If we find an error in the range expression in a range-based for loop, and the
loop variable has a type containing 'auto', set the declaration to be invalid
(because we couldn't deduce its type) to prevent follow-on errors.
llvm-svn: 188853
diff --git a/clang/test/SemaCXX/for-range-examples.cpp b/clang/test/SemaCXX/for-range-examples.cpp
index ca505e0..08c6936 100644
--- a/clang/test/SemaCXX/for-range-examples.cpp
+++ b/clang/test/SemaCXX/for-range-examples.cpp
@@ -180,3 +180,14 @@
for (y : {1, 2, 3}) {} // expected-error {{must declare a variable}} expected-warning {{result unused}}
}
}
+
+namespace test5 {
+ // Test error-recovery.
+ void f() {
+ for (auto x : undeclared_identifier) // expected-error {{undeclared identifier}}
+ for (auto y : x->foo)
+ y->bar();
+ for (auto x : 123) // expected-error {{no viable 'begin'}}
+ x->foo();
+ }
+}