[cfe-commits] r151081 - in /cfe/trunk: lib/Parse/ParseStmt.cpp test/SemaCXX/for-range-examples.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Tue Feb 21 12:01:35 PST 2012
Author: rsmith
Date: Tue Feb 21 14:01:35 2012
New Revision: 151081
URL: http://llvm.org/viewvc/llvm-project?rev=151081&view=rev
Log:
Don't assume that a valid expression for the first part of a for-statement
is non-null when diagnosing a broken attempt to write a for-range-statement.
Modified:
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/test/SemaCXX/for-range-examples.cpp
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=151081&r1=151080&r2=151081&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Tue Feb 21 14:01:35 2012
@@ -1396,8 +1396,7 @@
return StmtError();
}
Collection = ParseExpression();
- } else if (getLang().CPlusPlus0x && Tok.is(tok::colon) &&
- !FirstPart.isInvalid()) {
+ } else if (getLang().CPlusPlus0x && Tok.is(tok::colon) && FirstPart.get()) {
// User tried to write the reasonable, but ill-formed, for-range-statement
// for (expr : expr) { ... }
Diag(Tok, diag::err_for_range_expected_decl)
Modified: cfe/trunk/test/SemaCXX/for-range-examples.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/for-range-examples.cpp?rev=151081&r1=151080&r2=151081&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/for-range-examples.cpp (original)
+++ cfe/trunk/test/SemaCXX/for-range-examples.cpp Tue Feb 21 14:01:35 2012
@@ -169,3 +169,14 @@
template<typename T> void f() { for (auto a : A()) {} }
void g() { f<int>(); }
}
+
+namespace test4 {
+ void f() {
+ int y;
+
+ // Make sure these don't crash. Better diagnostics would be nice.
+ for (: {1, 2, 3}) {} // expected-error {{expected expression}} expected-error {{expected ';'}}
+ for (x : {1, 2, 3}) {} // expected-error {{undeclared identifier}} expected-error {{expected ';'}}
+ for (y : {1, 2, 3}) {} // expected-error {{must declare a variable}} expected-warning {{result unused}}
+ }
+}
More information about the cfe-commits
mailing list