r234565 - [Sema] Don't assume that an initializer list has an initializer
David Majnemer
david.majnemer at gmail.com
Thu Apr 9 21:52:06 PDT 2015
Author: majnemer
Date: Thu Apr 9 23:52:06 2015
New Revision: 234565
URL: http://llvm.org/viewvc/llvm-project?rev=234565&view=rev
Log:
[Sema] Don't assume that an initializer list has an initializer
Given something like 'int({}, 1)', we would try to emit a diagnostic
regarding the excess element in the scalar initializer. However, we
assumed that the initializer list had an element in it.
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaCXX/functional-cast.cpp
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=234565&r1=234564&r2=234565&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Thu Apr 9 23:52:06 2015
@@ -6753,9 +6753,9 @@ bool InitializationSequence::Diagnose(Se
case FK_TooManyInitsForScalar: {
SourceRange R;
- if (InitListExpr *InitList = dyn_cast<InitListExpr>(Args[0]))
- R = SourceRange(InitList->getInit(0)->getLocEnd(),
- InitList->getLocEnd());
+ auto *InitList = dyn_cast<InitListExpr>(Args[0]);
+ if (InitList && InitList->getNumInits() == 1)
+ R = SourceRange(InitList->getInit(0)->getLocEnd(), InitList->getLocEnd());
else
R = SourceRange(Args.front()->getLocEnd(), Args.back()->getLocEnd());
Modified: cfe/trunk/test/SemaCXX/functional-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/functional-cast.cpp?rev=234565&r1=234564&r2=234565&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/functional-cast.cpp (original)
+++ cfe/trunk/test/SemaCXX/functional-cast.cpp Thu Apr 9 23:52:06 2015
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
// REQUIRES: LP64
// ------------ not interpreted as C-style cast ------------
@@ -11,7 +11,7 @@ struct InitViaConstructor {
InitViaConstructor(int i = 7);
};
-struct NoValueInit { // expected-note 2 {{candidate constructor (the implicit copy constructor)}}
+struct NoValueInit { // expected-note 2 {{candidate constructor (the implicit copy constructor)}} expected-note 2 {{candidate constructor (the implicit move constructor)}}
NoValueInit(int i, int j); // expected-note 2 {{candidate constructor}}
};
@@ -25,6 +25,7 @@ void test_cxx_function_cast_multi() {
(void)NoValueInit(0, 0);
(void)NoValueInit(0, 0, 0); // expected-error{{no matching constructor for initialization}}
(void)int(1, 2); // expected-error{{excess elements in scalar initializer}}
+ (void)int({}, 2); // expected-error{{excess elements in scalar initializer}}
}
More information about the cfe-commits
mailing list