r177134 - PR15290: 'this' is not permitted in the declaration of a friend function,

Richard Smith richard-llvm at metafoo.co.uk
Thu Mar 14 17:41:52 PDT 2013


Author: rsmith
Date: Thu Mar 14 19:41:52 2013
New Revision: 177134

URL: http://llvm.org/viewvc/llvm-project?rev=177134&view=rev
Log:
PR15290: 'this' is not permitted in the declaration of a friend function,
therefore references to members should not be transformed into implicit uses of
'this'. Patch by Ismail Pazarbasi!

Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=177134&r1=177133&r2=177134&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Mar 14 19:41:52 2013
@@ -4833,12 +4833,14 @@ void Parser::ParseFunctionDeclarator(Dec
       //   "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
       //   and the end of the function-definition, member-declarator, or
       //   declarator.
+      // FIXME: currently, "static" case isn't handled correctly.
       bool IsCXX11MemberFunction =
         getLangOpts().CPlusPlus11 &&
-        (D.getContext() == Declarator::MemberContext ||
-         (D.getContext() == Declarator::FileContext &&
-          D.getCXXScopeSpec().isValid() &&
-          Actions.CurContext->isRecord()));
+        (D.getContext() == Declarator::MemberContext
+         ? !D.getDeclSpec().isFriendSpecified()
+         : D.getContext() == Declarator::FileContext &&
+           D.getCXXScopeSpec().isValid() &&
+           Actions.CurContext->isRecord());
       Sema::CXXThisScopeRAII ThisScope(Actions,
                                dyn_cast<CXXRecordDecl>(Actions.CurContext),
                                DS.getTypeQualifiers() |

Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp?rev=177134&r1=177133&r2=177134&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp Thu Mar 14 19:41:52 2013
@@ -61,9 +61,26 @@ namespace PR10036 {
   }
 }
 
+namespace PR15290 {
+  template<typename T>
+  class A {
+    T v_;
+    friend int add_to_v(A &t) noexcept(noexcept(v_ + 42))
+    {
+      return t.v_ + 42;
+    }
+  };
+  void f()
+  {
+    A<int> t;
+    add_to_v(t);
+  }
+}
+
 namespace Static {
   struct X1 {
     int m;
+    // FIXME: This should be accepted.
     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}}
 





More information about the cfe-commits mailing list