diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-12 20:42:31 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-12 20:42:31 +0000 |
commit | 6cc055af1df10c5255273c8308a381540e3af443 (patch) | |
tree | 24ba04bc673ecdb1c83529ad194a632eb0097abe /clang/test | |
parent | 4ac15cee54479089604216c823eaeb6852d56816 (diff) | |
download | bcm5719-llvm-6cc055af1df10c5255273c8308a381540e3af443.tar.gz bcm5719-llvm-6cc055af1df10c5255273c8308a381540e3af443.zip |
Implement the first set of changes for PR3963 and rdar://6759604,
which tries to do better error recovery when it is "obvious" that an
identifier is a mis-typed typename. In this case, we try to parse
it as a typename instead of as the identifier in a declarator, which
gives us several options for better error recovery and immediately
makes diagnostics more useful. For example, we now produce:
t.c:4:8: error: unknown type name 'foo_t'
static foo_t a = 4;
^
instead of:
t.c:4:14: error: invalid token after top level declarator
static foo_t a = 4;
^
Also, since we now parse "a" correctly, we make a decl for it,
preventing later uses of 'a' from emitting things like:
t.c:12:20: error: use of undeclared identifier 'a'
int bar() { return a + b; }
^
I'd really appreciate any scrutiny possible on this, it
is a tricky area.
llvm-svn: 68911
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Lexer/block_cmt_end.c | 2 | ||||
-rw-r--r-- | clang/test/Parser/declarators.c | 19 | ||||
-rw-r--r-- | clang/test/Parser/objc-foreach-syntax.m | 10 | ||||
-rw-r--r-- | clang/test/SemaObjC/exception-go-boom.m | 2 |
4 files changed, 24 insertions, 9 deletions
diff --git a/clang/test/Lexer/block_cmt_end.c b/clang/test/Lexer/block_cmt_end.c index 65d948f7fd8..d85cf81f214 100644 --- a/clang/test/Lexer/block_cmt_end.c +++ b/clang/test/Lexer/block_cmt_end.c @@ -17,7 +17,7 @@ next comment ends with normal escaped newline: /* expected-warning {{escaped newline}} expected-warning {{backslash and newline}} *\ / -bar +int bar /* xyz diff --git a/clang/test/Parser/declarators.c b/clang/test/Parser/declarators.c index 8a533ee53d8..09b43e50571 100644 --- a/clang/test/Parser/declarators.c +++ b/clang/test/Parser/declarators.c @@ -12,7 +12,7 @@ char ((((*X)))); void (*signal(int, void (*)(int)))(int); -int a, ***C, * const D, b(int); +int a, ***C, * const D, B(int); int *A; @@ -36,3 +36,20 @@ int test4(x, x) int x; {} /* expected-error {{redefinition of parameter 'x'}} */ // PR3031 int (test5), ; // expected-error {{expected identifier or '('}} + + +// PR3963 & rdar://6759604 - test error recovery for mistyped "typenames". + +struct xyz { int y; }; + +foo_t a = 4; // expected-error {{unknown type name 'foo_t'}} +xyz b; // expected-error {{unknown type name 'xyz'}} + +foo_t *d; // expected-error {{unknown type name 'foo_t'}} + +static f; // expected-warning {{type specifier missing, defaults to 'int'}} +static g = 4; // expected-warning {{type specifier missing, defaults to 'int'}} +static h // expected-warning {{type specifier missing, defaults to 'int'}} + __asm__("foo"); // expected-warning {{extension used}} + +int bar() { return a; } diff --git a/clang/test/Parser/objc-foreach-syntax.m b/clang/test/Parser/objc-foreach-syntax.m index e6e3ccf12d1..977dccc88b1 100644 --- a/clang/test/Parser/objc-foreach-syntax.m +++ b/clang/test/Parser/objc-foreach-syntax.m @@ -1,10 +1,8 @@ // RUN: clang-cc -fsyntax-only -verify %s -ce MyList // expected-error {{invalid token after top level declarator}} -@end -@implementation MyList +@implementation MyList // expected-warning {{cannot find interface declaration for 'MyList'}} - (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount { return 0; @@ -14,10 +12,10 @@ ce MyList // expected-error {{invalid token after top level declarator}} int LOOP(); -@implementation MyList (BasicTest) // expected-error {{cannot find interface declaration for 'MyList'}} +@implementation MyList (BasicTest) - (void)compilerTestAgainst { -MyList * el; // expected-error {{use of undeclared identifier 'MyList'}} - for (el in @"foo") // expected-error {{use of undeclared identifier 'el'}} +MyList * el; + for (el in @"foo") { LOOP(); } } @end diff --git a/clang/test/SemaObjC/exception-go-boom.m b/clang/test/SemaObjC/exception-go-boom.m index 1d792c4c131..774ae7cd639 100644 --- a/clang/test/SemaObjC/exception-go-boom.m +++ b/clang/test/SemaObjC/exception-go-boom.m @@ -4,7 +4,7 @@ void f0(id x) { @try { } @catch (NSException *x) { // \ - expected-warning{{type specifier missing, defaults to 'int'}} \ + expected-error{{unknown type name 'NSException'}} \ expected-error{{@catch parameter is not a pointer to an interface type}} } } |