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
This commit is contained in:
Richard Smith 2012-09-14 18:21:10 +00:00
Родитель 15dfcbf9da
Коммит a6ddea6adb
2 изменённых файлов: 6 добавлений и 5 удалений

Просмотреть файл

@ -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]);

Просмотреть файл

@ -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