[PATCH] C++11: if decl-specifier has 'friend', do not allow access to 'this' pointer when parsing function declarator.

Richard Smith richard at metafoo.co.uk
Mon Mar 11 11:15:14 PDT 2013



================
Comment at: lib/Parse/ParseDecl.cpp:4839-4843
@@ -4837,6 +4838,7 @@
         getLangOpts().CPlusPlus11 &&
-        (D.getContext() == Declarator::MemberContext ||
+        (IsMemberContext ||
          (D.getContext() == Declarator::FileContext &&
           D.getCXXScopeSpec().isValid() &&
-          Actions.CurContext->isRecord()));
+          Actions.CurContext->isRecord())) &&
+        !(IsMemberContext && D.getDeclSpec().isFriendSpecified());
       Sema::CXXThisScopeRAII ThisScope(Actions,
----------------
How about:

        (D.getContext() == Declarator::MemberContext
         ? !D.getDeclSpec().isFriendSpecified()
         : D.getContext() == Declarator::FileContext &&
           D.getCXXScopeSpec().isValid() &&
           Actions.CurContext->isRecord());

Please also add a FIXME for the 'static' case.

================
Comment at: test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp:83
@@ -66,3 +82,3 @@
     int m;
     static auto f() -> decltype(m); // expected-error{{'this' cannot be implicitly used in a static member function declaration}}
     static auto g() -> decltype(this->m); // expected-error{{'this' cannot be used in a static member function declaration}}
----------------
Please add a FIXME here too.


http://llvm-reviews.chandlerc.com/D468



More information about the cfe-commits mailing list