[cfe-commits] r70516 - in /cfe/trunk: lib/Parse/ParseDecl.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp test/SemaCXX/constructor.cpp
Anders Carlsson
andersca at mac.com
Thu Apr 30 15:41:11 PDT 2009
Author: andersca
Date: Thu Apr 30 17:41:11 2009
New Revision: 70516
URL: http://llvm.org/viewvc/llvm-project?rev=70516&view=rev
Log:
Rework the way we handle constructor decls to be less hacky and fix PR3948 completely.
Modified:
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/constructor.cpp
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=70516&r1=70515&r2=70516&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Apr 30 17:41:11 2009
@@ -1982,7 +1982,17 @@
if (Tok.is(tok::identifier)) {
assert(Tok.getIdentifierInfo() && "Not an identifier?");
- D.SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
+
+ // If this identifier is the name of the current class, it's a
+ // constructor name.
+ if (!D.getDeclSpec().hasTypeSpecifier() &&
+ Actions.isCurrentClassName(*Tok.getIdentifierInfo(),CurScope)) {
+ D.setConstructor(Actions.getTypeName(*Tok.getIdentifierInfo(),
+ Tok.getLocation(), CurScope),
+ Tok.getLocation());
+ // This is a normal identifier.
+ } else
+ D.SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
ConsumeToken();
goto PastIdentifier;
} else if (Tok.is(tok::annot_template_id)) {
@@ -2092,15 +2102,6 @@
break;
}
ParseFunctionDeclarator(ConsumeParen(), D);
-
- // If this identifier is the name of the current class, it's a
- // constructor name.
- if (IdentifierInfo *II = D.getIdentifier()) {
- if (Actions.isCurrentClassName(*II, CurScope))
- D.setConstructor(Actions.getTypeName(*II, D.getIdentifierLoc(),
- CurScope),
- D.getIdentifierLoc());
- }
} else if (Tok.is(tok::l_square)) {
ParseBracketDeclarator(D);
} else {
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=70516&r1=70515&r2=70516&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Apr 30 17:41:11 2009
@@ -2035,6 +2035,18 @@
isVirtualOkay = true;
} else if (DC->isRecord()) {
+ // If the of the function is the same as the name of the record, then this
+ // must be an invalid constructor that has a return type.
+ // (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()){
+ Diag(D.getIdentifierLoc(), diag::err_constructor_return_type)
+ << SourceRange(D.getDeclSpec().getTypeSpecTypeLoc())
+ << SourceRange(D.getIdentifierLoc());
+ return 0;
+ }
+
// This is a C++ method declaration.
NewFD = CXXMethodDecl::Create(Context, cast<CXXRecordDecl>(DC),
D.getIdentifierLoc(), Name, R,
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=70516&r1=70515&r2=70516&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Apr 30 17:41:11 2009
@@ -1294,19 +1294,6 @@
D.setInvalidType();
SC = FunctionDecl::None;
}
- if (D.getDeclSpec().hasTypeSpecifier() && !D.isInvalidType()) {
- // Constructors don't have return types, but the parser will
- // happily parse something like:
- //
- // class X {
- // float X(float);
- // };
- //
- // The return type will be eliminated later.
- Diag(D.getIdentifierLoc(), diag::err_constructor_return_type)
- << SourceRange(D.getDeclSpec().getTypeSpecTypeLoc())
- << SourceRange(D.getIdentifierLoc());
- }
DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(0).Fun;
if (FTI.TypeQuals != 0) {
Modified: cfe/trunk/test/SemaCXX/constructor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor.cpp?rev=70516&r1=70515&r2=70516&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constructor.cpp (original)
+++ cfe/trunk/test/SemaCXX/constructor.cpp Thu Apr 30 17:41:11 2009
@@ -45,3 +45,16 @@
struct mmst_reg{
char mmst_reg[10];
};
+
+// PR3948
+namespace PR3948 {
+// PR3948
+class a {
+ public:
+ int b(int a());
+};
+int x();
+void y() {
+ a z; z.b(x);
+}
+}
More information about the cfe-commits
mailing list