From: Douglas Gregor Date: Fri, 5 Feb 2010 06:12:42 +0000 (+0000) Subject: A function declarator with a non-identifier name in an anonymous class X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f7a17b718385464966251ee421b314570d32731;p=clang A function declarator with a non-identifier name in an anonymous class 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 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index bef53df4f0..28f49d0798 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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(DC)->getIdentifier()){ + if (Name.getAsIdentifierInfo() && + Name.getAsIdentifierInfo() == cast(DC)->getIdentifier()){ Diag(D.getIdentifierLoc(), diag::err_constructor_return_type) << SourceRange(D.getDeclSpec().getTypeSpecTypeLoc()) << SourceRange(D.getIdentifierLoc()); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index e746a8e98c..7fbbed4089 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -433,7 +433,7 @@ bool Sema::isCurrentClassName(const IdentifierInfo &II, Scope *, } else CurDecl = dyn_cast_or_null(CurContext); - if (CurDecl) + if (CurDecl && CurDecl->getIdentifier()) return &II == CurDecl->getIdentifier(); else return false; diff --git a/test/SemaCXX/overloaded-operator-decl.cpp b/test/SemaCXX/overloaded-operator-decl.cpp index c43d7c217c..5f8655cee7 100644 --- a/test/SemaCXX/overloaded-operator-decl.cpp +++ b/test/SemaCXX/overloaded-operator-decl.cpp @@ -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; +}