[cfe-commits] r67059 - in /cfe/trunk: include/clang/AST/ include/clang/Basic/ lib/AST/ lib/CodeGen/ lib/Sema/ test/Parser/ test/SemaCXX/

Douglas Gregor dgregor at apple.com
Mon Mar 23 10:18:13 PDT 2009


On Mar 23, 2009, at 10:12 AM, Howard Hinnant wrote:

>
> On Mar 23, 2009, at 1:01 PM, Howard Hinnant wrote:
>
>> On Mar 23, 2009, at 12:35 PM, Douglas Gregor wrote:
>>
>>> On Mar 21, 2009, at 8:11 AM, Howard Hinnant wrote:
>>>
>>>> On Mar 20, 2009, at 4:17 PM, Douglas Gregor wrote:
>>>>
>>>>> Howard, there's a question for you below. Just search for your  
>>>>> name.
>>>>
>>>> I didn't see a question.
>>>
>>> Errr, sorry. The question was: do you agree that the following code
>>> should be ill-
>>> formed?
>>>
>>> struct A { };
>>>
>>> struct B {
>>>  operator A&&();
>>> }
>>>
>>> void test(B b) {
>>>  const A &ar = b; // error: operator A&&() returns an rvalue, so
>>> it should not be considered when trying to bind ar to b
>>> }
>>
>> I'm not positive.  However assuming that this is ill-formed:
>>
>> struct A { };
>>
>> struct B {
>>   operator A&();
>> }
>>
>> void test(B b) {
>>   const A &ar = b; // error: operator A&() returns an lvalue, so it
>> should not be considered when trying to bind ar to b
>> }
>>
>> (by some rule buried in [over]), then I see no reason to have  
>> operator
>> A&&() behave differently (it should also be ill-formed).  If however
>> my assumption is incorrect, then I would like to investigate this
>> further.
>
> I think I'm officially confused.  It appears to me that the use of  
> both:
>
>   operator A&();
>
> and
>
>   operator A();
>
> would be well formed.  What is the motivation (or reference to rule)  
> to disallow operator A&&() in this context?


Yes, both are well-formed and both mean different things. The first  
one causes a direct binding (that's [dcl.init.ref]p5b1sb2), while the  
second one binds to a temporary.

You know, I completely screwed up the example. I meant test() to be:

   void test(B b) {
     A &ar = b; // ill-formed
   }

*sigh*, and I think I've answer my own question. Sorry for the noise.

	- Doug



More information about the cfe-commits mailing list