diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-10-18 18:33:57 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-10-18 18:33:57 +0000 |
commit | f106f0ee3ba0c81d4c56f7935f518da53d78c08e (patch) | |
tree | 7ab929caab3201e8d2a0f5c1e9a14b1752185d3a | |
parent | c19981c2711c9b0564bc1a9cbad4b2d0cca608d5 (diff) |
In C++11, a class's members are allowed to be nominated as friends.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142393 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 2 | ||||
-rw-r--r-- | test/CXX/class/class.friend/p1-cxx11.cpp | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index a39584a107..38bce96360 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -10045,7 +10045,7 @@ Decl *Sema::ActOnFriendFunctionDecl(Scope *S, Declarator &D, // C++ [class.friend]p1: A friend of a class is a function or // class that is not a member of the class . . . - if (DC->Equals(CurContext)) + if (DC->Equals(CurContext) && !getLangOptions().CPlusPlus0x) Diag(DS.getFriendSpecLoc(), diag::err_friend_is_member); if (D.isFunctionDefinition()) { diff --git a/test/CXX/class/class.friend/p1-cxx11.cpp b/test/CXX/class/class.friend/p1-cxx11.cpp new file mode 100644 index 0000000000..235f295d12 --- /dev/null +++ b/test/CXX/class/class.friend/p1-cxx11.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +class A { + class AInner { + }; + + void a_member(); + friend void A::a_member(); // ok in c++11, ill-formed in c++98 + friend void a_member(); // ok in both, refers to non-member + friend class A::AInner; // ok in c++11, extension in c++98 + friend class AInner; // ok in both, refers to non-member +}; |