From: Sean Hunt Date: Wed, 4 May 2011 01:19:04 +0000 (+0000) Subject: Ensure that delegating constructor loop detection uses canonical X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fa74c2344addf92826c938758fb4dc612a004eb9;p=clang Ensure that delegating constructor loop detection uses canonical declarations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130821 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 8c819e3878..0cb24767e6 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -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(FunctionDecl::getCanonicalDecl()); + } + CXXConstructorDecl *getCanonicalDecl() { + return cast(FunctionDecl::getCanonicalDecl()); + } // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 6cd5e43241..641bcd831b 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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; diff --git a/test/SemaCXX/cxx0x-delegating-ctors.cpp b/test/SemaCXX/cxx0x-delegating-ctors.cpp index 6d0695dfa1..df88b6bc31 100644 --- a/test/SemaCXX/cxx0x-delegating-ctors.cpp +++ b/test/SemaCXX/cxx0x-delegating-ctors.cpp @@ -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}}