Sema: Don't crash when specializing a global scope function in a class
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 9 Jan 2015 06:10:21 +0000 (06:10 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 9 Jan 2015 06:10:21 +0000 (06:10 +0000)
We assumed that class-scope specializations would result in a
CXXMethodDecl for that class.  However, globally qualified functions
will result in normal FunctionDecls.

llvm-svn: 225508

clang/lib/Sema/SemaDecl.cpp
clang/test/SemaTemplate/instantiate-method.cpp

index 8a50475..1e20121 100644 (file)
@@ -7482,7 +7482,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
     } else if (isFunctionTemplateSpecialization) {
       if (CurContext->isDependentContext() && CurContext->isRecord() 
           && !isFriend) {
-        isDependentClassScopeExplicitSpecialization = true;
+        isDependentClassScopeExplicitSpecialization = isa<CXXMethodDecl>(NewFD);
         Diag(NewFD->getLocation(), getLangOpts().MicrosoftExt ? 
           diag::ext_function_specialization_in_class :
           diag::err_function_specialization_in_class)
index 4cc40af..c2d4704 100644 (file)
@@ -195,3 +195,9 @@ namespace PR22040 {
     Foobar<int>::bazqux(3);  // expected-error{{no member named 'bazqux' in }}
   }
 }
+
+template <typename>
+struct SpecializationOfGlobalFnInClassScope {
+  template <>
+  void ::Fn(); // expected-error{{cannot have a qualified name}} expected-error{{cannot specialize a function}}
+};