]> granicus.if.org Git - clang/commitdiff
Issue a diagnostic if we see a templated friend declaration that we do not
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 8 Nov 2013 18:59:56 +0000 (18:59 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 8 Nov 2013 18:59:56 +0000 (18:59 +0000)
support.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194273 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaTemplate.cpp
test/CXX/class.access/class.friend/p3-cxx0x.cpp
test/CXX/temp/temp.decls/temp.friend/p5.cpp
test/SemaTemplate/friend-template.cpp

index 67097a5774ea8cbc3898b4c17d6b18c5bfb01cd6..be9ea674d0da4957ec6ab15c5f3fd3e02130cea5 100644 (file)
@@ -333,6 +333,7 @@ def UnknownAttributes : DiagGroup<"attributes">;
 def IgnoredAttributes : DiagGroup<"ignored-attributes">;
 def UnnamedTypeTemplateArgs : DiagGroup<"unnamed-type-template-args",
                                         [CXX98CompatUnnamedTypeTemplateArgs]>;
+def UnsupportedFriend : DiagGroup<"unsupported-friend">;
 def UnusedArgument : DiagGroup<"unused-argument">;
 def UnusedSanitizeArgument : DiagGroup<"unused-sanitize-argument">;
 def UnusedCommandLineArgument : DiagGroup<"unused-command-line-argument",
index 5f26a0013d64cb9131d13bf7db03bf73ec2e3156..dba3ca16527457728a9335d70c9152fd05357058 100644 (file)
@@ -914,6 +914,14 @@ def err_friend_not_first_in_declaration : Error<
   "'friend' must appear first in a non-function declaration">;
 def err_using_decl_friend : Error<
   "cannot befriend target of using declaration">;
+def warn_template_qualified_friend_unsupported : Warning<
+  "dependent nested name specifier '%0' for friend class declaration is "
+  "not supported; turning off access control for %1">,
+  InGroup<UnsupportedFriend>;
+def warn_template_qualified_friend_ignored : Warning<
+  "dependent nested name specifier '%0' for friend template declaration is "
+  "not supported; ignoring this friend declaration">,
+  InGroup<UnsupportedFriend>;
   
 def err_invalid_member_in_interface : Error<
   "%select{data member |non-public member function |static member function |"
index 8b04f8dfcf52147de5b5046fdae4b6c31e4936eb..660641eec6cadb5e205cda1498586b09049a0c1c 100644 (file)
@@ -11410,6 +11410,8 @@ Decl *Sema::ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
   // Handle the case of a templated-scope friend class.  e.g.
   //   template <class T> class A<T>::B;
   // FIXME: we don't support these right now.
+  Diag(NameLoc, diag::warn_template_qualified_friend_unsupported)
+    << SS.getScopeRep() << SS.getRange() << cast<CXXRecordDecl>(CurContext);
   ElaboratedTypeKeyword ETK = TypeWithKeyword::getKeywordForTagTypeKind(Kind);
   QualType T = Context.getDependentNameType(ETK, SS.getScopeRep(), Name);
   TypeSourceInfo *TSI = Context.CreateTypeSourceInfo(T);
index 795774657c7005c796b4cfe929d22cf9df2d3e60..6d40e00b21a7d1df04685735a10a059077a9ace0 100644 (file)
@@ -877,10 +877,11 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
       // FIXME: Horrible, horrible hack! We can't currently represent this
       // in the AST, and historically we have just ignored such friend
       // class templates, so don't complain here.
-      if (TUK != TUK_Friend)
-        Diag(NameLoc, diag::err_template_qualified_declarator_no_match)
+      Diag(NameLoc, TUK == TUK_Friend
+                        ? diag::warn_template_qualified_friend_ignored
+                        : diag::err_template_qualified_declarator_no_match)
           << SS.getScopeRep() << SS.getRange();
-      return true;
+      return TUK != TUK_Friend;
     }
 
     if (RequireCompleteDeclContext(SS, SemanticContext))
index ea9d2ce697c55a4ecbc9d38872b86317d210950a..5a1ab49321d099a65a9b04617d522e131fd9f785 100644 (file)
@@ -36,10 +36,17 @@ class A {
 public:
   class foo {};
   static int y;
-  template <typename S> friend class B<S>::ty;
+  template <typename S> friend class B<S>::ty; // expected-warning {{dependent nested name specifier 'B<S>::' for friend class declaration is not supported}}
 };
 
-template <typename T> class B { typedef int ty; };
+template<typename T> class B { typedef int ty; };
+
+template<> class B<int> {
+  class ty {
+    static int f(A<int> &a) { return a.y; } // ok, befriended
+  };
+};
+int f(A<char> &a) { return a.y; } // FIXME: should be an error
 
 struct {
   // Ill-formed
@@ -56,7 +63,7 @@ struct {
       friend
 
   float;
-  template<typename T> friend class A<T>::foo;
+  template<typename T> friend class A<T>::foo; // expected-warning {{not supported}}
 } a;
 
 void testA() { (void)sizeof(A<int>); }
index 77f071d52e67a0907a38954103587df6d0d23021..b26abb64f83836ed573cec5214d03adcdc8a551f 100644 (file)
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 namespace test0 {
   template <class T> class A {
@@ -7,7 +6,8 @@ namespace test0 {
   };
 
   class B {
-    template <class T> friend class A<T>::Member;
+    template <class T> friend class A<T>::Member; // expected-warning {{not supported}}
+    int n;
   };
 
   A<int> a;
@@ -68,7 +68,7 @@ namespace test3 {
 
   template <class U> class C {
     int i;
-    template <class T> friend struct A<T>::Inner;
+    template <class T> friend struct A<T>::Inner; // expected-warning {{not supported}}
   };
 
   template <class T> int A<T>::Inner::foo() {
index 8a478777eb7e9a0047ff8ebe9254350dd119deec..e9b2b9b8e64e53dd4f71e81799e817929618d80c 100644 (file)
@@ -232,16 +232,23 @@ namespace PR10660 {
 }
 
 namespace rdar11147355 {
-  template <class T> 
+  template <class T>
   struct A {
     template <class U> class B;
-    template <class S> template <class U> friend class A<S>::B; 
+    template <class S> template <class U> friend class A<S>::B; // expected-warning {{dependent nested name specifier 'A<S>::' for friend template declaration is not supported; ignoring this friend declaration}}
+  private:
+    int n; // expected-note {{here}}
   };
-  
+
   template <class S> template <class U> class A<S>::B {
-  }; 
-  
+  public:
+    // FIXME: This should be permitted.
+    int f(A<S*> a) { return a.n; } // expected-error {{private}}
+  };
+
   A<double>::B<double>  ab;
+  A<double*> a;
+  int k = ab.f(a); // expected-note {{instantiation of}}
 }
 
 namespace RedeclUnrelated {