[cfe-commits] r130821 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/Sema/SemaDeclCXX.cpp test/SemaCXX/cxx0x-delegating-ctors.cpp
Sean Hunt
scshunt at csclub.uwaterloo.ca
Tue May 3 18:19:04 PDT 2011
Author: coppro
Date: Tue May 3 20:19:04 2011
New Revision: 130821
URL: http://llvm.org/viewvc/llvm-project?rev=130821&view=rev
Log:
Ensure that delegating constructor loop detection uses canonical
declarations.
Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/cxx0x-delegating-ctors.cpp
Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=130821&r1=130820&r2=130821&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Tue May 3 20:19:04 2011
@@ -1693,6 +1693,13 @@
/// \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()); }
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=130821&r1=130820&r2=130821&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue May 3 20:19:04 2011
@@ -2072,10 +2072,10 @@
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;
Modified: cfe/trunk/test/SemaCXX/cxx0x-delegating-ctors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-delegating-ctors.cpp?rev=130821&r1=130820&r2=130821&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-delegating-ctors.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-delegating-ctors.cpp Tue May 3 20:19:04 2011
@@ -29,8 +29,7 @@
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}}
More information about the cfe-commits
mailing list