From: Richard Smith Date: Sat, 12 Jan 2013 01:05:20 +0000 (+0000) Subject: Only produce one -Wc++98-compat warning when initializing a reference from an init... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=193649c2a3ff0616777de934a2bf47eaeb4f1076;p=clang Only produce one -Wc++98-compat warning when initializing a reference from an init list with multiple elements. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172285 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 111f81e449..94dd2aa45c 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -4877,6 +4877,7 @@ InitializationSequence::Perform(Sema &S, if (S.getLangOpts().CPlusPlus11 && Entity.getType()->isReferenceType() && Args.size() == 1 && isa(Args[0]) && + cast(Args[0])->getNumInits() == 1 && Entity.getKind() != InitializedEntity::EK_Parameter) { // Produce a C++98 compatibility warning if we are initializing a reference // from an initializer list. For parameters, we produce a better warning diff --git a/test/SemaCXX/cxx98-compat.cpp b/test/SemaCXX/cxx98-compat.cpp index 830ab9b6fe..ca32c197de 100644 --- a/test/SemaCXX/cxx98-compat.cpp +++ b/test/SemaCXX/cxx98-compat.cpp @@ -8,6 +8,8 @@ namespace std { initializer_list(T*, size_t); T *p; size_t n; + T *begin(); + T *end(); }; } @@ -103,6 +105,11 @@ void RangeFor() { int xs[] = {1, 2, 3}; for (int &a : xs) { // expected-warning {{range-based for loop is incompatible with C++98}} } + for (auto &b : {1, 2, 3}) { + // expected-warning@-1 {{range-based for loop is incompatible with C++98}} + // expected-warning@-2 {{'auto' type specifier is incompatible with C++98}} + // expected-warning@-3 {{initialization of initializer_list object is incompatible with C++98}} + } } struct InClassInit {