Ensure that delegating constructor loop detection uses canonical

declarations.

llvm-svn: 130821
This commit is contained in:
Alexis Hunt 2011-05-04 01:19:04 +00:00
parent 737aac5107
commit 159bdaa50e
3 changed files with 10 additions and 4 deletions

View File

@ -1693,6 +1693,13 @@ public:
/// \brief Set the constructor that this inheriting constructor is based on.
void setInheritedConstructor(const CXXConstructorDecl *BaseCtor);
const CXXConstructorDecl *getCanonicalDecl() const {
return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
}
CXXConstructorDecl *getCanonicalDecl() {
return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
}
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }

View File

@ -2072,10 +2072,10 @@ static bool CollectFieldInitializer(BaseAndFieldInfo &Info,
bool
Sema::SetDelegatingInitializer(CXXConstructorDecl *Constructor,
CXXCtorInitializer *Initializer) {
// FIXME: This doesn't catch indirect loops yet
CXXConstructorDecl *Target = Initializer->getTargetConstructor();
CXXConstructorDecl *Canonical = Constructor->getCanonicalDecl();
while (Target) {
if (Target == Constructor) {
if (Target->getCanonicalDecl() == Canonical) {
Diag(Initializer->getSourceLocation(), diag::err_delegating_ctor_loop)
<< Constructor;
return true;

View File

@ -29,8 +29,7 @@ foo::foo (bool) : foo(true) { // expected-error{{delegates to itself}}
foo::foo (const float* f) : foo(*f) {
}
// FIXME: This should error
foo::foo (const float &f) : foo(&f) {
foo::foo (const float &f) : foo(&f) { //expected-error{{delegates to itself}}
}
foo::foo (char) : i(3), foo(3) { // expected-error{{must appear alone}}