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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68911 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Parser/declarators.c b/test/Parser/declarators.c
index 8a533ee..09b43e5 100644
--- a/test/Parser/declarators.c
+++ b/test/Parser/declarators.c
@@ -12,7 +12,7 @@
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 @@
// 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; }