Centralize error reporting of improper uses of incomplete types in the
new DiagnoseIncompleteType. It provides additional information about
struct/class/union/enum types when possible, either by pointing to the
forward declaration of that type or by pointing to the definition (if
we're in the process of defining that type).
Fixes <rdar://problem/6500531>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62521 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Sema/array-constraint.c b/test/Sema/array-constraint.c
index 596d19f..69475b7 100644
--- a/test/Sema/array-constraint.c
+++ b/test/Sema/array-constraint.c
@@ -1,6 +1,6 @@
// RUN: clang -fsyntax-only -verify -pedantic %s
-struct s;
+struct s; // expected-note {{forward declaration of 'struct s'}}
struct s* t (struct s z[]) { // expected-error {{array has incomplete element type}}
return z;
}
diff --git a/test/Sema/compound-literal.c b/test/Sema/compound-literal.c
index c053a59..e457c72 100644
--- a/test/Sema/compound-literal.c
+++ b/test/Sema/compound-literal.c
@@ -24,7 +24,7 @@
fooFunc(&(struct foo){ 1, 2 });
}
-struct Incomplete;
+struct Incomplete; // expected-note{{forward declaration of 'struct Incomplete'}}
struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}}
void IncompleteFunc(unsigned x) {
struct Incomplete* I2 = (struct foo[x]){1, 2, 3}; // -expected-error {{variable-sized object may not be initialized}}
diff --git a/test/Sema/enum.c b/test/Sema/enum.c
index ea66c27..55ddb0d 100644
--- a/test/Sema/enum.c
+++ b/test/Sema/enum.c
@@ -21,7 +21,9 @@
return sizeof(enum e) ;
}
-enum gccForwardEnumExtension ve; // expected-error {{variable has incomplete type 'enum gccForwardEnumExtension'}} expected-warning{{ISO C forbids forward references to 'enum' types}}
+enum gccForwardEnumExtension ve; // expected-error {{variable has incomplete type 'enum gccForwardEnumExtension'}} \
+ // expected-warning{{ISO C forbids forward references to 'enum' types}} \
+ // expected-note{{forward declaration of 'enum gccForwardEnumExtension'}}
int test2(int i)
{
@@ -52,7 +54,7 @@
// <rdar://problem/6093889>
enum e0 { // expected-note {{previous definition is here}}
- E0 = sizeof(enum e0 { E1 }) // expected-error {{nested redefinition}}
+ E0 = sizeof(enum e0 { E1 }), // expected-error {{nested redefinition}}
};
// PR3173
@@ -66,3 +68,8 @@
// <rdar://problem/6503878>
typedef enum { X = 0 }; // expected-warning{{typedef requires a name}}
+
+
+enum NotYetComplete { // expected-note{{definition of 'enum NotYetComplete' is not complete until the closing '}'}}
+ NYC1 = sizeof(enum NotYetComplete) // expected-error{{invalid application of 'sizeof' to an incomplete type 'enum NotYetComplete'}}
+};
diff --git a/test/Sema/incomplete-decl.c b/test/Sema/incomplete-decl.c
index fedf2c6..bd60368 100644
--- a/test/Sema/incomplete-decl.c
+++ b/test/Sema/incomplete-decl.c
@@ -1,5 +1,7 @@
// RUN: clang -fsyntax-only -verify %s
+struct foo; // expected-note {{forward declaration of 'struct foo'}}
+
void b; // expected-error {{variable has incomplete type 'void'}}
struct foo f; // expected-error {{variable has incomplete type 'struct foo'}}
diff --git a/test/Sema/init.c b/test/Sema/init.c
index 72586b1..abfab37 100644
--- a/test/Sema/init.c
+++ b/test/Sema/init.c
@@ -71,7 +71,8 @@
// PR3001
struct s1 s2 = {
- .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}}
+ .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \
+ // expected-note{{forward declaration of 'struct s3'}}
.b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
}
diff --git a/test/Sema/pointer-addition.c b/test/Sema/pointer-addition.c
index f2fb973..95f364f 100644
--- a/test/Sema/pointer-addition.c
+++ b/test/Sema/pointer-addition.c
@@ -1,6 +1,6 @@
// RUN: clang %s -fsyntax-only -verify -pedantic
-typedef struct S S;
+typedef struct S S; // expected-note{{forward declaration of 'struct S'}}
void a(S* b, void* c) {
b++; // expected-error {{arithmetic on pointer to incomplete type}}
b += 1; // expected-error {{arithmetic on pointer to incomplete type}}
@@ -9,6 +9,6 @@
b = 1+b; // expected-error {{arithmetic on pointer to incomplete type}}
/* The next couple tests are only pedantic warnings in gcc */
void (*d)(S*,void*) = a;
- d += 1; // expected-error {{pointer to incomplete type}}
- d++; // expected-error {{pointer to incomplete type}}
+ d += 1; // expected-error {{arithmetic on pointer to function type}}}
+ d++; // expected-error {{arithmetic on pointer to function type}}}
}