[cfe-commits] r76704 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaCXXScopeSpec.cpp test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp

Douglas Gregor dgregor at apple.com
Tue Jul 21 17:28:09 PDT 2009


Author: dgregor
Date: Tue Jul 21 19:28:09 2009
New Revision: 76704

URL: http://llvm.org/viewvc/llvm-project?rev=76704&view=rev
Log:
Complain if we're entering the context of a dependent nested-name-specifier but
cannot match that nested-name-specifier to a class template or class template
partial specialization.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
    cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=76704&r1=76703&r2=76704&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jul 21 19:28:09 2009
@@ -793,7 +793,7 @@
 def err_template_arg_extra_parens : Error<
   "non-type template argument cannot be surrounded by parentheses">;
 
-// C++ class template specialization
+// C++ class template specializations and out-of-line definitions
 def err_template_spec_needs_header : Error<
   "template specialization requires 'template<>'">;
 def err_template_spec_needs_template_parameters : Error<
@@ -802,6 +802,9 @@
 def err_template_spec_extra_headers : Error<
   "extraneous template parameter list in template specialization or "
   "out-of-line template definition">;
+def err_template_qualified_declarator_no_match : Error<
+  "nested name specifier '%0' for declaration does not refer to a class "
+  "template or class template partial specialization">;
 def err_template_spec_decl_out_of_scope_global : Error<
   "class template %select{|partial }0specialization of %1 must occur in the "
   "global scope">;

Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=76704&r1=76703&r2=76704&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Tue Jul 21 19:28:09 2009
@@ -17,6 +17,7 @@
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/Parse/DeclSpec.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/raw_ostream.h"
 using namespace clang;
 
 /// \brief Compute the DeclContext that is associated with the given
@@ -48,7 +49,7 @@
     if (EnteringContext) {
       // We are entering the context of the nested name specifier, so try to
       // match the nested name specifier to either a primary class template
-      // or a class template partial specialization
+      // or a class template partial specialization.
       if (const TemplateSpecializationType *SpecType
             = dyn_cast_or_null<TemplateSpecializationType>(NNS->getAsType())) {
         if (ClassTemplateDecl *ClassTemplate 
@@ -64,6 +65,17 @@
           // FIXME: Class template partial specializations
         }
       }
+      
+      std::string NNSString;
+      {
+        llvm::raw_string_ostream OS(NNSString);
+        NNS->print(OS, Context.PrintingPolicy);
+      }
+      
+      // FIXME: Allow us to pass a nested-name-specifier to Diag?
+      Diag(SS.getRange().getBegin(), 
+           diag::err_template_qualified_declarator_no_match)
+        << NNSString << SS.getRange();
     }
     
     return 0;

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp?rev=76704&r1=76703&r2=76704&view=diff

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp Tue Jul 21 19:28:09 2009
@@ -12,6 +12,7 @@
   void f1(size_type) const;
   void f2(size_type) const;
   void f3(size_type) const;
+  void f4() ;
   
   T value;
 };
@@ -36,6 +37,9 @@
 void X0<X, Y>::f3(size_type) const {
 }
 
+template<class X, class Y> 
+void X0<Y, X>::f4() { } // expected-error{{does not refer to}}
+
 // FIXME: error message should probably say, "redefinition of 'X0<T, U>::f0'"
 // rather than just "redefinition of 'f0'"
 template<typename T, typename U>





More information about the cfe-commits mailing list