diff mbox

[C++,/,RFC] PR 54864

Message ID 52029D61.2050107@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Aug. 7, 2013, 7:17 p.m. UTC
Hi,

the issue here is that... I'm not sure the bug report is valid ;) 
Seriously, *if* we think it is, must be fixable with a moderate effort. 
Here Jason fixed the closely related c++/53721:

     http://gcc.gnu.org/ml/gcc-patches/2013-04/msg01445.html

and tweaking a bit more the check would allow this variant too, with 
outer pointing to the enclosing S:

struct S
{
     int foo();

     struct nested
     {
         S* outer;

         auto bar() -> decltype(outer->foo());
     };
};


but I'm not sure it's valid code: for example clang accepts it, icc 
doesn't. If it is, something along the lines of the attached (with at 
least an improved comment: we want to say something like pointer to this 
*or* to enclosing class) works for the testcase (and a few positive and 
negative variants) and lightly tested on x86_64-linux.

Thanks!
Paolo.

/////////////////////////

Comments

Jason Merrill Aug. 7, 2013, 7:52 p.m. UTC | #1
On 08/07/2013 03:17 PM, Paolo Carlini wrote:
> the issue here is that... I'm not sure the bug report is valid ;)
> Seriously, *if* we think it is, must be fixable with a moderate effort.
> Here Jason fixed the closely related c++/53721:
>
>      http://gcc.gnu.org/ml/gcc-patches/2013-04/msg01445.html
>
> and tweaking a bit more the check would allow this variant too, with
> outer pointing to the enclosing S:
>
> struct S
> {
>      int foo();
>
>      struct nested
>      {
>          S* outer;
>
>          auto bar() -> decltype(outer->foo());
>      };
> };
>
>
> but I'm not sure it's valid code: for example clang accepts it, icc
> doesn't.

The rule that allows use of *this is pretty specific:

Unlike the object expression in other contexts, *this is not required to 
be of complete type for purposes of class member access (5.2.5) outside 
the member function body.

That doesn't seem to allow the use of *outer.

Jason
Paolo Carlini Aug. 7, 2013, 8:26 p.m. UTC | #2
Hi,

On 08/07/2013 09:52 PM, Jason Merrill wrote:
> The rule that allows use of *this is pretty specific:
>
> Unlike the object expression in other contexts, *this is not required 
> to be of complete type for purposes of class member access (5.2.5) 
> outside the member function body.
>
> That doesn't seem to allow the use of *outer.
Ok. I'm closing the report as invalid.

Thanks!
Paolo.
diff mbox

Patch

Index: parser.c
===================================================================
--- parser.c	(revision 201558)
+++ parser.c	(working copy)
@@ -6294,8 +6294,10 @@  cp_parser_postfix_dot_deref_expression (cp_parser
       /* Unlike the object expression in other contexts, *this is not
 	 required to be of complete type for purposes of class member
 	 access (5.2.5) outside the member function body.  */
-      else if (postfix_expression != current_class_ref
-	       && !(processing_template_decl && scope == current_class_type))
+      else if (!(processing_template_decl && scope == current_class_type)
+	       && (!current_class_type || !CLASS_TYPE_P (scope)
+		   || (common_enclosing_class (scope, current_class_type)
+		       != scope)))
 	scope = complete_type_or_else (scope, NULL_TREE);
       /* Let the name lookup machinery know that we are processing a
 	 class member access expression.  */