diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-09-14 18:21:10 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-09-14 18:21:10 +0000 |
commit | a6ddea6adbef22d4e2673dbb7236186ac5b14e09 (patch) | |
tree | fa16921ef560080c825bf8eb0829933a0f82bb40 | |
parent | 15dfcbf9da7acba1d1881961048f6982430fe22e (diff) |
When diagnosing multiple mem-initializers in a delegating ctor, point to the delegating initializer, not to the first initializer. For good measure, also highlight the other initializer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163919 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 7 | ||||
-rw-r--r-- | test/SemaCXX/cxx0x-delegating-ctors.cpp | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 7c97453d6f..6fe3b6869a 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -3346,11 +3346,10 @@ void Sema::ActOnMemInitializers(Decl *ConstructorDecl, } else { assert(Init->isDelegatingInitializer()); // This must be the only initializer - if (i != 0 || NumMemInits > 1) { - Diag(MemInits[0]->getSourceLocation(), + if (NumMemInits != 1) { + Diag(Init->getSourceLocation(), diag::err_delegating_initializer_alone) - << MemInits[0]->getSourceRange(); - HadError = true; + << Init->getSourceRange() << MemInits[i ? 0 : 1]->getSourceRange(); // We will treat this as being the only initializer. } SetDelegatingInitializer(Constructor, MemInits[i]); diff --git a/test/SemaCXX/cxx0x-delegating-ctors.cpp b/test/SemaCXX/cxx0x-delegating-ctors.cpp index 2d49f0fc59..a34ee4fcb0 100644 --- a/test/SemaCXX/cxx0x-delegating-ctors.cpp +++ b/test/SemaCXX/cxx0x-delegating-ctors.cpp @@ -33,7 +33,9 @@ foo::foo (const float &f) : foo(&f) { //expected-error{{creates a delegation cyc //expected-note{{which delegates to}} } -foo::foo (char) : i(3), foo(3) { // expected-error{{must appear alone}} +foo::foo (char) : + i(3), + foo(3) { // expected-error{{must appear alone}} } // This should not cause an infinite loop |