]> granicus.if.org Git - clang/commitdiff
Sema: RecordDecl shouldn't have a FunctionDecl as a Decl
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 9 Jan 2015 07:36:13 +0000 (07:36 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 9 Jan 2015 07:36:13 +0000 (07:36 +0000)
RecordDecls should have things like CXXMethodDecls or FriendDecls as a
decl but not things like FunctionDecls.

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

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

index 1e20121b375c6fc6a2c6898f9cc81df5e85a98ae..970b2ecd72c2360224d39369c0d3051f9447fe5c 100644 (file)
@@ -6712,6 +6712,11 @@ static FunctionDecl* CreateNewFunctionDecl(Sema &SemaRef, Declarator &D,
     IsVirtualOkay = !Ret->isStatic();
     return Ret;
   } else {
+    bool isFriend =
+        SemaRef.getLangOpts().CPlusPlus && D.getDeclSpec().isFriendSpecified();
+    if (!isFriend && SemaRef.CurContext->isRecord())
+      return nullptr;
+
     // Determine whether the function was written with a
     // prototype. This true when:
     //   - we're in C++ (where every function has a prototype),
@@ -7482,7 +7487,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
     } else if (isFunctionTemplateSpecialization) {
       if (CurContext->isDependentContext() && CurContext->isRecord() 
           && !isFriend) {
-        isDependentClassScopeExplicitSpecialization = isa<CXXMethodDecl>(NewFD);
+        isDependentClassScopeExplicitSpecialization = true;
         Diag(NewFD->getLocation(), getLangOpts().MicrosoftExt ? 
           diag::ext_function_specialization_in_class :
           diag::err_function_specialization_in_class)
index c2d4704bc029f3d930bd1eb195d882e7c93f7a72..961884417b5428d07dae1fcc8bfeafbf4c2ccb09 100644 (file)
@@ -199,5 +199,11 @@ namespace PR22040 {
 template <typename>
 struct SpecializationOfGlobalFnInClassScope {
   template <>
-  void ::Fn(); // expected-error{{cannot have a qualified name}} expected-error{{cannot specialize a function}}
+  void ::Fn(); // expected-error{{cannot have a qualified name}}
+};
+
+class AbstractClassWithGlobalFn {
+  template <typename>
+  void ::f(); // expected-error{{cannot have a qualified name}}
+  virtual void f1() = 0;
 };