diff options
author | Sean Hunt <scshunt@csclub.uwaterloo.ca> | 2011-05-04 01:19:04 +0000 |
---|---|---|
committer | Sean Hunt <scshunt@csclub.uwaterloo.ca> | 2011-05-04 01:19:04 +0000 |
commit | fa74c2344addf92826c938758fb4dc612a004eb9 (patch) | |
tree | 8acbaf0a2a9f3b5b20b8fce80e3c33260cb706dc | |
parent | 3afa9753fa1243bb652bc5387ecf71044c24fd90 (diff) |
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
-rw-r--r-- | include/clang/AST/DeclCXX.h | 7 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 4 | ||||
-rw-r--r-- | test/SemaCXX/cxx0x-delegating-ctors.cpp | 3 |
3 files changed, 10 insertions, 4 deletions
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<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()); } 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}} |