From ad1bbb93d154db125a916f178f4f54f3de842032 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 15 Mar 2013 00:41:52 +0000 Subject: [PATCH] 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! llvm-svn: 177134 --- clang/lib/Parse/ParseDecl.cpp | 10 ++++++---- .../test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 5202e69..4d1147b 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4833,12 +4833,14 @@ void Parser::ParseFunctionDeclarator(Declarator &D, // "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(Actions.CurContext), DS.getTypeQualifiers() | diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp index b84cec6..2e7b58d 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp @@ -61,9 +61,26 @@ namespace PR10036 { } } +namespace PR15290 { + template + class A { + T v_; + friend int add_to_v(A &t) noexcept(noexcept(v_ + 42)) + { + return t.v_ + 42; + } + }; + void f() + { + A 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}} -- 2.7.4