]> granicus.if.org Git - clang/commitdiff
In C++11, a class's members are allowed to be nominated as friends.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 18 Oct 2011 18:33:57 +0000 (18:33 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 18 Oct 2011 18:33:57 +0000 (18:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142393 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/CXX/class/class.friend/p1-cxx11.cpp [new file with mode: 0644]

index a39584a107a8a54daf6cd79c4f943776bf2abb30..38bce96360c27e42949a29c95139c9649e21259a 100644 (file)
@@ -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 (file)
index 0000000..235f295
--- /dev/null
@@ -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
+};