diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-03-15 00:41:52 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-03-15 00:41:52 +0000 |
commit | d92277928eefcf958080707ed6e154f406a5d054 (patch) | |
tree | d7970a34cd7ac9cf506e446614d221342fcce452 | |
parent | e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3 (diff) |
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!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177134 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 10 | ||||
-rw-r--r-- | test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp | 17 |
2 files changed, 23 insertions, 4 deletions
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 5202e694d8..4d1147b5df 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/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<CXXRecordDecl>(Actions.CurContext), DS.getTypeQualifiers() | diff --git a/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp b/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp index b84cec61c3..2e7b58d97a 100644 --- a/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp +++ b/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp @@ -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}} |