Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home for chromium.org
« Groups Home
FYI: Move-only class + windows C++ compiler + ternary operator
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
vabr  
View profile  
 More options Aug 3 2012, 4:13 am
From: vabr <v...@chromium.org>
Date: Fri, 3 Aug 2012 01:13:18 -0700 (PDT)
Local: Fri, Aug 3 2012 4:13 am
Subject: FYI: Move-only class + windows C++ compiler + ternary operator

Hi all,

The following describes a strange issue of the compiler on win_rel try bot.
Albert Wong was very kind and took a look at this, and said he was not sure
whether this is a compiler bug or something which can be fixed in our code (base/move.h
or scoped_ptr). Therefore I have not filed a bug and I'm only posting a
work-around here just in case anybody hits the same problem later. If you
think this is something we can and should fix, feel free to let me know and
I'll file the bug.

The following code seems OK to me and (with details in) compiles all right
on linux and mac try-bots:

scoped_ptr<const DictionaryValue> GetDictionaryFromJson(/*...*/) {
  bool success;
  // ...
  scoped_ptr<const DictionaryValue> dictionary(/*...*/);
  return success ? dictionary.Pass() : scoped_ptr<const DictionaryValue>();

}

However, the win_rel bot complained<http://build.chromium.org/p/tryserver.chromium/builders/win_rel/build...> (search
for "C2248" on that page) about the return statement, pointing to the line
where scoped_ptr employs MOVE_ONLY_TYPE_FOR_CPP_03, and saying that
"'scoped_ptr<C>::scoped_ptr' : cannot access private member declared in
class 'scoped_ptr<C>'". Interestingly after I expanded<http://codereview.chromium.org/10694055/diff2/77002:75041/chrome/brow...>
 the ternary operator to a full if-else statement, the compiler accepted it.

Vaclav


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mattias Nissler  
View profile  
 More options Aug 3 2012, 4:46 am
From: Mattias Nissler <mniss...@chromium.org>
Date: Fri, 3 Aug 2012 10:46:13 +0200
Local: Fri, Aug 3 2012 4:46 am
Subject: Re: [chromium-dev] FYI: Move-only class + windows C++ compiler + ternary operator

For posterity, here is the full error message (the log will become
unavailable at some point):

E:\b\build\slave\win\build\src\chrome\browser\extensions\api\web_request\we b_request_api_unittest.cc(96)
:error C2248: 'scoped_ptr<C>::scoped_ptr' : cannot access private member
declared in class 'scoped_ptr<C>'

        with
        [
            C=const base::DictionaryValue
        ]
        ..\base/memory/scoped_ptr.h(134) : see declaration of
'scoped_ptr<C>::scoped_ptr'
        with
        [
            C=const base::DictionaryValue
        ]


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jochen Eisinger  
View profile  
 More options Aug 3 2012, 5:42 am
From: Jochen Eisinger <joc...@chromium.org>
Date: Fri, 3 Aug 2012 11:42:43 +0200
Local: Fri, Aug 3 2012 5:42 am
Subject: Re: [chromium-dev] FYI: Move-only class + windows C++ compiler + ternary operator

The return value of a ternary operator is the type of the second
expressions, which is the (private) class
scoped_ptr<const::DictionaryValue>::RValue. The third expression is of type
scoped_ptr<const::DictionaryValue> which you cannot cast to ...::RValue

I guess that's what the error message is trying to tell you

-jochen

On Fri, Aug 3, 2012 at 10:46 AM, Mattias Nissler <mniss...@chromium.org>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
vabr  
View profile  
 More options Aug 3 2012, 5:50 am
From: vabr <v...@chromium.org>
Date: Fri, 3 Aug 2012 02:50:06 -0700 (PDT)
Local: Fri, Aug 3 2012 5:50 am
Subject: Re: [chromium-dev] FYI: Move-only class + windows C++ compiler + ternary operator

Thanks, Jochen,

On Friday, August 3, 2012 11:42:43 AM UTC+2, Jochen Eisinger wrote:

> The return value of a ternary operator is the type of the second
> expressions, which is the (private) class
> scoped_ptr<const::DictionaryValue>::RValue. The third expression is of type
> scoped_ptr<const::DictionaryValue> which you cannot cast to ...::RValue

> I guess that's what the error message is trying to tell you

Your explanation makes sense (unlike the error message from the compiler).

But I cannot help wondering why did it work on the other compilers...

Vaclav


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Victor Khimenko  
View profile  
 More options Aug 3 2012, 6:09 am
From: Victor Khimenko <k...@chromium.org>
Date: Fri, 3 Aug 2012 14:09:39 +0400
Local: Fri, Aug 3 2012 6:09 am
Subject: Re: [chromium-dev] FYI: Move-only class + windows C++ compiler + ternary operator

Type of the ternary operator is NOT the type of the second expression.
Instead if types are different then compiler is supposed to try to convert
T1 to T2 and T2 to T1. If one is Ok and another is not then this conversion
is chosen, if both are valid then program is
malformed. Here scoped_ptr<const::DictionaryValue> will be converted
to scoped_ptr<const::DictionaryValue>
because scoped_ptr<const::DictionaryValue>::RValue can not be converted
to scoped_ptr<const::DictionaryValue> as was pointed above. Was defined
this way from the day one (C++98).

If Jochen's explanation is correct then it should be easy to check: swap
arguments of ternary operand around and see if it'll compile or not.

Vaclav


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
vabr  
View profile  
 More options Aug 3 2012, 6:30 am
From: vabr <v...@chromium.org>
Date: Fri, 3 Aug 2012 03:30:24 -0700 (PDT)
Local: Fri, Aug 3 2012 6:30 am
Subject: Re: [chromium-dev] FYI: Move-only class + windows C++ compiler + ternary operator

Thanks, that's interesting.

But might there be also a problem with the type of return value
being scoped_ptr<const::DictionaryValue>? If the ternary expression ends up
being of type RValue, then it should not be possible to convert it
to scoped_ptr<const::DictionaryValue>, right? Or does the RValue propagate
further, until the point where the result of GetDictionaryFromJson is used
as as a right-hand value?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Victor Khimenko  
View profile  
 More options Aug 3 2012, 8:39 am
From: Victor Khimenko <k...@chromium.org>
Date: Fri, 3 Aug 2012 16:39:38 +0400
Local: Fri, Aug 3 2012 8:39 am
Subject: Re: [chromium-dev] FYI: Move-only class + windows C++ compiler + ternary operator

Right. If you can convert both ways then program is malformed and compiler
should not accept it.

> Or does the RValue propagate further, until the point where the result
> of GetDictionaryFromJson is used as as a right-hand value?

No. The only place where C++ does such an awful thing and determines type
of something using the destination type if when you take an address of the
overloaded function. In all other places arguments should determine the
type of outcome. In particular ternary operator picks either T1 or T2, if
it can not determine which one is "correct" it should detect some kind of
error.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »