[cfe-commits] [PATCH] Improved error recovery in for-statement
Richard Smith
richard at metafoo.co.uk
Tue Jan 25 10:18:16 PST 2011
Hi,
The attached patch improves diagnostics error recovery in for-statements.
Examples:
Before:
for.cpp:8:11: error: expected ';' in 'for' statement specifier
for (n 0; n < 10; n++); // expected-error {{expected '=' in 'for'}}
^
for.cpp:8:8: warning: expression result unused
for (n 0; n < 10; n++); // expected-error {{expected '=' in 'for'}}
^
After:
for.cpp:8:11: error: expected '=' in 'for' init statement
for (n 0; n < 10; n++); // expected-error {{expected '=' in 'for'}}
^
=
Before (note that this error currently causes clang to get confused about
the following statement):
for.cpp:9:14: error: expected ';' in 'for' statement specifier
for (n = 0 n < 10; n++); // expected-error {{expected ';' in 'for'}}
^
for.cpp:9:25: error: expected ';' in 'for' statement specifier
for (n = 0 n < 10; n++); // expected-error {{expected ';' in 'for'}}
^
for.cpp:10:3: error: expected expression
for (n = 0; n < 10 n++); // expected-error {{expected ';' in 'for'}}
^
for.cpp:10:3: error: expected ')'
for.cpp:9:7: note: to match this '('
for (n = 0 n < 10; n++); // expected-error {{expected ';' in 'for'}}
^
After:
for.cpp:9:14: error: expected ';' in 'for' statement specifier
for (n = 0 n < 10; n++); // expected-error {{expected ';' in 'for'}}
^
;
Before (an extreme case):
for.cpp:20:10: error: expected ';' in 'for' statement specifier
for (n 0 n < 10 n++); // expected-error {{expected '=' in 'for'}}
expected-error 2{{expected ';' in 'for'}}
^
for.cpp:20:22: error: expected expression
for (n 0 n < 10 n++); // expected-error {{expected '=' in 'for'}}
expected-error 2{{expected ';' in 'for'}}
^
for.cpp:22:3: error: expected expression
for (intt n = 0; n < 10; ++n); // expected-error {{undeclared identifier
'intt'}}
^
for.cpp:22:3: error: expected ')'
for.cpp:20:7: note: to match this '('
for (n 0 n < 10 n++); // expected-error {{expected '=' in 'for'}}
expected-error 2{{expected ';' in 'for'}}
^
for.cpp:20:8: warning: expression result unused
for (n 0 n < 10 n++); // expected-error {{expected '=' in 'for'}}
expected-error 2{{expected ';' in 'for'}}
^
After:
../src/tools/clang/test/Parser/for.cpp:20:10: error: expected '=' in 'for'
init statement
for (n 0 n < 10 n++); // expected-error {{expected '=' in 'for'}}
expected-error 2{{expected ';' in 'for'}}
^
=
../src/tools/clang/test/Parser/for.cpp:20:12: error: expected ';' in 'for'
statement specifier
for (n 0 n < 10 n++); // expected-error {{expected '=' in 'for'}}
expected-error 2{{expected ';' in 'for'}}
^
;
../src/tools/clang/test/Parser/for.cpp:20:19: error: expected ';' in 'for'
statement specifier
for (n 0 n < 10 n++); // expected-error {{expected '=' in 'for'}}
expected-error 2{{expected ';' in 'for'}}
^
;
The patch can be viewed online here: http://codereview.appspot.com/3992046/
Please let me know what I need to fix in order to get this committed.
Thanks!
Richard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-for-error.patch
Type: text/x-patch
Size: 5491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110125/4a3cc2f2/attachment.bin>
More information about the cfe-commits
mailing list