aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-01-12 01:05:20 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-01-12 01:05:20 +0000
commit193649c2a3ff0616777de934a2bf47eaeb4f1076 (patch)
tree2cc0066df2ba385d84949f4f8b0186fd5b561d0f
parent013539cddae154cd1782984a7dc3bb471cac397e (diff)
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
-rw-r--r--lib/Sema/SemaInit.cpp1
-rw-r--r--test/SemaCXX/cxx98-compat.cpp7
2 files changed, 8 insertions, 0 deletions
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<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/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 {