diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-01-12 01:05:20 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-01-12 01:05:20 +0000 |
commit | a7edaad3b66ceb038b6240e32a96e14803e7802c (patch) | |
tree | 16c0f5400a8b92017907699f78518bf31d68475d | |
parent | 873c724b4a1662ec5468a055758c11b19ad19ee8 (diff) | |
download | llvm-a7edaad3b66ceb038b6240e32a96e14803e7802c.zip llvm-a7edaad3b66ceb038b6240e32a96e14803e7802c.tar.gz llvm-a7edaad3b66ceb038b6240e32a96e14803e7802c.tar.bz2 |
Only produce one -Wc++98-compat warning when initializing a reference from an init list with multiple elements.
llvm-svn: 172285
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 1 | ||||
-rw-r--r-- | clang/test/SemaCXX/cxx98-compat.cpp | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 111f81e..94dd2aa 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -4877,6 +4877,7 @@ InitializationSequence::Perform(Sema &S, if (S.getLangOpts().CPlusPlus11 && Entity.getType()->isReferenceType() && Args.size() == 1 && isa<InitListExpr>(Args[0]) && + cast<InitListExpr>(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/clang/test/SemaCXX/cxx98-compat.cpp b/clang/test/SemaCXX/cxx98-compat.cpp index 830ab9b..ca32c19 100644 --- a/clang/test/SemaCXX/cxx98-compat.cpp +++ b/clang/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 { |