]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Propagate erroneous types to declaration specifiers [PR107805]
authorFlorian Weimer <fweimer@redhat.com>
Thu, 24 Nov 2022 10:00:54 +0000 (11:00 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 24 Nov 2022 10:02:11 +0000 (11:02 +0100)
Without this change, finish_declspecs cannot tell that whether there
was an erroneous type specified, or no type at all.  This may result
in additional diagnostics for implicit ints, or missing diagnostics
for multiple types.

PR c/107805

gcc/c/
* c-decl.cc (declspecs_add_type): Propagate error_mark_bode
from type to specs.

gcc/testsuite/
* gcc.dg/pr107805-1.c: New test.
* gcc.dg/pr107805-2.c: Likewise.

gcc/c/c-decl.cc
gcc/testsuite/gcc.dg/pr107805-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr107805-2.c [new file with mode: 0644]

index 098e475f65d593a4f56d687f272d6c7ea72146d4..4adb89e4aaf1b53448cc9c3ca05eb5d05f0d02bf 100644 (file)
@@ -12243,11 +12243,9 @@ declspecs_add_type (location_t loc, struct c_declspecs *specs,
     error_at (loc, "two or more data types in declaration specifiers");
   else if (TREE_CODE (type) == TYPE_DECL)
     {
-      if (TREE_TYPE (type) == error_mark_node)
-       ; /* Allow the type to default to int to avoid cascading errors.  */
-      else
+      specs->type = TREE_TYPE (type);
+      if (TREE_TYPE (type) != error_mark_node)
        {
-         specs->type = TREE_TYPE (type);
          specs->decl_attr = DECL_ATTRIBUTES (type);
          specs->typedef_p = true;
          specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type);
diff --git a/gcc/testsuite/gcc.dg/pr107805-1.c b/gcc/testsuite/gcc.dg/pr107805-1.c
new file mode 100644 (file)
index 0000000..559b6a5
--- /dev/null
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+typedef int t;
+typedef struct { double a; int b; } t; /* { dg-error "conflicting types" } */
+t x; /* No warning here.  */
+
diff --git a/gcc/testsuite/gcc.dg/pr107805-2.c b/gcc/testsuite/gcc.dg/pr107805-2.c
new file mode 100644 (file)
index 0000000..fa5fa4c
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+typedef int t;
+typedef struct { double a; int b; } t; /* { dg-error "conflicting types" } */
+t char x; /* { dg-error "two or more data types" } */