]> granicus.if.org Git - clang/commitdiff
A function declarator with a non-identifier name in an anonymous class
authorDouglas Gregor <dgregor@apple.com>
Fri, 5 Feb 2010 06:12:42 +0000 (06:12 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 5 Feb 2010 06:12:42 +0000 (06:12 +0000)
is a constructor for that class, right? Fixes PR6238.

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

lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/overloaded-operator-decl.cpp

index bef53df4f0be8749f7367658aa14abc33f326640..28f49d07986f77950826657e1c55a5253dd45d3c 100644 (file)
@@ -2737,7 +2737,8 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
     // (The parser checks for a return type and makes the declarator a
     // constructor if it has no return type).
     // must have an invalid constructor that has a return type
-    if (Name.getAsIdentifierInfo() == cast<CXXRecordDecl>(DC)->getIdentifier()){
+    if (Name.getAsIdentifierInfo() &&
+        Name.getAsIdentifierInfo() == cast<CXXRecordDecl>(DC)->getIdentifier()){
       Diag(D.getIdentifierLoc(), diag::err_constructor_return_type)
         << SourceRange(D.getDeclSpec().getTypeSpecTypeLoc())
         << SourceRange(D.getIdentifierLoc());
index e746a8e98c304db022f05f8bc780fcd0dd224e62..7fbbed40890ac075700794dea48c56f0444a5634 100644 (file)
@@ -433,7 +433,7 @@ bool Sema::isCurrentClassName(const IdentifierInfo &II, Scope *,
   } else
     CurDecl = dyn_cast_or_null<CXXRecordDecl>(CurContext);
 
-  if (CurDecl)
+  if (CurDecl && CurDecl->getIdentifier())
     return &II == CurDecl->getIdentifier();
   else
     return false;
index c43d7c217cca5b6be9621b4e49826ea397b63309..5f8655cee70cb61c2c5344ab61b5e520163928e7 100644 (file)
@@ -37,3 +37,9 @@ Y operator++(Y&, INT);
 X operator++(X&, FLOAT); // expected-error{{parameter of overloaded post-increment operator must have type 'int' (not 'FLOAT' (aka 'float'))}}
 
 int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}}
+
+namespace PR6238 {
+  static struct {
+    void operator()();
+  } plus;
+}