}
}
- 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();
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}}
};
}
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 {
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}}
};
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}}
};