r241424 - When we see something that looks like a constructor with a return type, only issue one error, not two.
Richard Smith
richard-llvm at metafoo.co.uk
Sun Jul 5 18:04:40 PDT 2015
Author: rsmith
Date: Sun Jul 5 20:04:39 2015
New Revision: 241424
URL: http://llvm.org/viewvc/llvm-project?rev=241424&view=rev
Log:
When we see something that looks like a constructor with a return type, only issue one error, not two.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CXX/class/class.mem/p2.cpp
cfe/trunk/test/CXX/drs/dr1xx.cpp
cfe/trunk/test/Parser/cxx-default-delete.cpp
cfe/trunk/test/SemaCXX/constructor.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=241424&r1=241423&r2=241424&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Jul 5 20:04:39 2015
@@ -4742,15 +4742,16 @@ NamedDecl *Sema::HandleDeclarator(Scope
}
}
- if (DiagnoseClassNameShadow(DC, NameInfo))
+ TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);
+ QualType R = TInfo->getType();
+
+ if (!R->isFunctionType() && DiagnoseClassNameShadow(DC, NameInfo))
// If this is a typedef, we'll end up spewing multiple diagnostics.
- // Just return early; it's safer.
+ // Just return early; it's safer. If this is a function, let the
+ // "constructor cannot have a return type" diagnostic handle it.
if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
return nullptr;
- TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);
- QualType R = TInfo->getType();
-
if (DiagnoseUnexpandedParameterPack(D.getIdentifierLoc(), TInfo,
UPPC_DeclarationType))
D.setInvalidType();
Modified: cfe/trunk/test/CXX/class/class.mem/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.mem/p2.cpp?rev=241424&r1=241423&r2=241424&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class/class.mem/p2.cpp (original)
+++ cfe/trunk/test/CXX/class/class.mem/p2.cpp Sun Jul 5 20:04:39 2015
@@ -76,13 +76,10 @@ namespace PR12629 {
namespace PR12688 {
struct S {
- // FIXME: Producing one error saying this can't have the same name
- // as the class because it's not a constructor, then producing
- // another error saying this can't have a return type because
- // it is a constructor, is redundant and inconsistent.
+ // FIXME: Maybe suppress the "constructor cannot have a return type" error
+ // if the return type is invalid.
nonsense S() throw (more_nonsense); // \
// expected-error {{'nonsense'}} \
- // expected-error {{has the same name as its class}} \
// expected-error {{constructor cannot have a return type}}
};
}
Modified: cfe/trunk/test/CXX/drs/dr1xx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr1xx.cpp?rev=241424&r1=241423&r2=241424&view=diff
==============================================================================
--- cfe/trunk/test/CXX/drs/dr1xx.cpp (original)
+++ cfe/trunk/test/CXX/drs/dr1xx.cpp Sun Jul 5 20:04:39 2015
@@ -943,10 +943,10 @@ namespace dr188 { // dr188: yes
namespace dr194 { // dr194: yes
struct A {
A();
- void A(); // expected-error {{has the same name as its class}} expected-error {{constructor cannot have a return type}}
+ void A(); // expected-error {{constructor cannot have a return type}}
};
struct B {
- void B(); // expected-error {{has the same name as its class}} expected-error {{constructor cannot have a return type}}
+ void B(); // expected-error {{constructor cannot have a return type}}
B();
};
struct C {
Modified: cfe/trunk/test/Parser/cxx-default-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-default-delete.cpp?rev=241424&r1=241423&r2=241424&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-default-delete.cpp (original)
+++ cfe/trunk/test/Parser/cxx-default-delete.cpp Sun Jul 5 20:04:39 2015
@@ -19,5 +19,5 @@ struct foo {
void baz() = delete;
struct quux {
- int quux() = default; // expected-error{{constructor cannot have a return type}} expected-error {{member 'quux' has the same name as its class}}
+ int quux() = default; // expected-error{{constructor cannot have a return type}}
};
Modified: cfe/trunk/test/SemaCXX/constructor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor.cpp?rev=241424&r1=241423&r2=241424&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constructor.cpp (original)
+++ cfe/trunk/test/SemaCXX/constructor.cpp Sun Jul 5 20:04:39 2015
@@ -15,8 +15,7 @@ class Foo {
virtual Foo(double); // expected-error{{constructor cannot be declared 'virtual'}}
Foo(long) const; // expected-error{{'const' qualifier is not allowed on a constructor}}
- int Foo(int, int); // expected-error{{constructor cannot have a return type}} \
- // expected-error{{member 'Foo' has the same name as its class}}
+ int Foo(int, int); // expected-error{{constructor cannot have a return type}}
volatile Foo(float); // expected-error{{constructor cannot have a return type}}
};
More information about the cfe-commits
mailing list