forked from OSchip/llvm-project
When we see something that looks like a constructor with a return type, only issue one error, not two.
llvm-svn: 241424
This commit is contained in:
parent
ff35c338dc
commit
a60a6db73f
|
@ -4742,15 +4742,16 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DiagnoseClassNameShadow(DC, NameInfo))
|
|
||||||
// If this is a typedef, we'll end up spewing multiple diagnostics.
|
|
||||||
// Just return early; it's safer.
|
|
||||||
if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);
|
TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);
|
||||||
QualType R = TInfo->getType();
|
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. 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;
|
||||||
|
|
||||||
if (DiagnoseUnexpandedParameterPack(D.getIdentifierLoc(), TInfo,
|
if (DiagnoseUnexpandedParameterPack(D.getIdentifierLoc(), TInfo,
|
||||||
UPPC_DeclarationType))
|
UPPC_DeclarationType))
|
||||||
D.setInvalidType();
|
D.setInvalidType();
|
||||||
|
|
|
@ -76,13 +76,10 @@ namespace PR12629 {
|
||||||
|
|
||||||
namespace PR12688 {
|
namespace PR12688 {
|
||||||
struct S {
|
struct S {
|
||||||
// FIXME: Producing one error saying this can't have the same name
|
// FIXME: Maybe suppress the "constructor cannot have a return type" error
|
||||||
// as the class because it's not a constructor, then producing
|
// if the return type is invalid.
|
||||||
// another error saying this can't have a return type because
|
|
||||||
// it is a constructor, is redundant and inconsistent.
|
|
||||||
nonsense S() throw (more_nonsense); // \
|
nonsense S() throw (more_nonsense); // \
|
||||||
// expected-error {{'nonsense'}} \
|
// expected-error {{'nonsense'}} \
|
||||||
// expected-error {{has the same name as its class}} \
|
|
||||||
// expected-error {{constructor cannot have a return type}}
|
// expected-error {{constructor cannot have a return type}}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -943,10 +943,10 @@ namespace dr188 { // dr188: yes
|
||||||
namespace dr194 { // dr194: yes
|
namespace dr194 { // dr194: yes
|
||||||
struct A {
|
struct A {
|
||||||
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 {
|
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();
|
B();
|
||||||
};
|
};
|
||||||
struct C {
|
struct C {
|
||||||
|
|
|
@ -19,5 +19,5 @@ struct foo {
|
||||||
void baz() = delete;
|
void baz() = delete;
|
||||||
|
|
||||||
struct quux {
|
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}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,8 +15,7 @@ class Foo {
|
||||||
virtual Foo(double); // expected-error{{constructor cannot be declared 'virtual'}}
|
virtual Foo(double); // expected-error{{constructor cannot be declared 'virtual'}}
|
||||||
Foo(long) const; // expected-error{{'const' qualifier is not allowed on a constructor}}
|
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}} \
|
int Foo(int, int); // expected-error{{constructor cannot have a return type}}
|
||||||
// expected-error{{member 'Foo' has the same name as its class}}
|
|
||||||
|
|
||||||
volatile Foo(float); // expected-error{{constructor cannot have a return type}}
|
volatile Foo(float); // expected-error{{constructor cannot have a return type}}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue