]> granicus.if.org Git - clang/commitdiff
Only produce one -Wc++98-compat warning when initializing a reference from an init...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 12 Jan 2013 01:05:20 +0000 (01:05 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 12 Jan 2013 01:05:20 +0000 (01:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172285 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/SemaCXX/cxx98-compat.cpp

index 111f81e44995df5f2fb03ed5ed7e5136ec232e6b..94dd2aa45c7f953bbda66f6fa51bf9af61d2d20e 100644 (file)
@@ -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
index 830ab9b6fe40f29d2ad3c43f79151e5fcf572e9f..ca32c197de7918a3ff9e1aad100da9bd89caf0ee 100644 (file)
@@ -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 {