From 21f06f0fcb3e616c912b6f2e053f397f7eef8a4b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 14 Sep 2012 18:21:10 +0000 Subject: [PATCH] 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. llvm-svn: 163919 --- clang/lib/Sema/SemaDeclCXX.cpp | 7 +++---- clang/test/SemaCXX/cxx0x-delegating-ctors.cpp | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 7c97453d6fc1..6fe3b6869a48 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/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/clang/test/SemaCXX/cxx0x-delegating-ctors.cpp b/clang/test/SemaCXX/cxx0x-delegating-ctors.cpp index 2d49f0fc599d..a34ee4fcb024 100644 --- a/clang/test/SemaCXX/cxx0x-delegating-ctors.cpp +++ b/clang/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