r225511 - Sema: RecordDecl shouldn't have a FunctionDecl as a Decl

David Majnemer david.majnemer at gmail.com
Thu Jan 8 23:36:13 PST 2015


Author: majnemer
Date: Fri Jan  9 01:36:13 2015
New Revision: 225511

URL: http://llvm.org/viewvc/llvm-project?rev=225511&view=rev
Log:
Sema: RecordDecl shouldn't have a FunctionDecl as a Decl

RecordDecls should have things like CXXMethodDecls or FriendDecls as a
decl but not things like FunctionDecls.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaTemplate/instantiate-method.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=225511&r1=225510&r2=225511&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jan  9 01:36:13 2015
@@ -6712,6 +6712,11 @@ static FunctionDecl* CreateNewFunctionDe
     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,
     } 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)

Modified: cfe/trunk/test/SemaTemplate/instantiate-method.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-method.cpp?rev=225511&r1=225510&r2=225511&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-method.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-method.cpp Fri Jan  9 01:36:13 2015
@@ -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;
 };





More information about the cfe-commits mailing list