[cfe-commits] r153752 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp test/SemaTemplate/friend-template.cpp

Douglas Gregor dgregor at apple.com
Fri Mar 30 09:20:47 PDT 2012


Author: dgregor
Date: Fri Mar 30 11:20:47 2012
New Revision: 153752

URL: http://llvm.org/viewvc/llvm-project?rev=153752&view=rev
Log:
If we encounter a friend class template for which we cannot resolve
the nested-name-specifier (e.g., because it is dependent), do not
error even though we can't represent it in the AST at this point.

This is a horrible, horrible hack. The actual feature we still need to
implement (for C++98!) is covered by PR12292. However, we used to
silently accept this code, so when we recently started rejecting it we
caused some regressions (e.g., <rdar://problem/11147355>). This hack
brings us back to the passable-but-not-good state we had previously.

Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/SemaTemplate/friend-template.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=153752&r1=153751&r2=153752&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Mar 30 11:20:47 2012
@@ -872,8 +872,12 @@
   if (SS.isNotEmpty() && !SS.isInvalid()) {
     SemanticContext = computeDeclContext(SS, true);
     if (!SemanticContext) {
-      Diag(NameLoc, diag::err_template_qualified_declarator_no_match)
-        << SS.getScopeRep() << SS.getRange();
+      // 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)
+          << SS.getScopeRep() << SS.getRange();
       return true;
     }
 

Modified: cfe/trunk/test/SemaTemplate/friend-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/friend-template.cpp?rev=153752&r1=153751&r2=153752&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/friend-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/friend-template.cpp Fri Mar 30 11:20:47 2012
@@ -230,3 +230,16 @@
     template <> friend class B; // expected-error{{extraneous 'template<>' in declaration of class 'B'}}
   };
 }
+
+namespace rdar11147355 {
+  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> class A<S>::B {
+  }; 
+  
+  A<double>::B<double>  ab;
+}





More information about the cfe-commits mailing list