diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-21 20:01:35 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-21 20:01:35 +0000 |
| commit | 9a2b7e820c79055ee83652ffc0321566f4bddf1f (patch) | |
| tree | 113ab523b3a05bfc43434a3d2164eaa5c7b07707 | |
| parent | 58dab6829a970b798e04daed5ce750b8023483f2 (diff) | |
| download | bcm5719-llvm-9a2b7e820c79055ee83652ffc0321566f4bddf1f.tar.gz bcm5719-llvm-9a2b7e820c79055ee83652ffc0321566f4bddf1f.zip | |
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.
llvm-svn: 151081
| -rw-r--r-- | clang/lib/Parse/ParseStmt.cpp | 3 | ||||
| -rw-r--r-- | clang/test/SemaCXX/for-range-examples.cpp | 11 |
2 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index c256f7842de..54f1b51f7e9 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -1396,8 +1396,7 @@ StmtResult Parser::ParseForStatement(ParsedAttributes &attrs, 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) diff --git a/clang/test/SemaCXX/for-range-examples.cpp b/clang/test/SemaCXX/for-range-examples.cpp index 868de9d4f0e..8bda51062a4 100644 --- a/clang/test/SemaCXX/for-range-examples.cpp +++ b/clang/test/SemaCXX/for-range-examples.cpp @@ -169,3 +169,14 @@ namespace test3 { 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}} + } +} |

