]> granicus.if.org Git - clang/commitdiff
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.

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

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

index 8a5047592aa16babb449fedd01eef7d80e13f227..1e20121b375c6fc6a2c6898f9cc81df5e85a98ae 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 4cc40af7e123d5f3f924bf12dbbf1b0f41badf89..c2d4704bc029f3d930bd1eb195d882e7c93f7a72 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}}
+};