c: Restore warning for incomplete structures declared in parameter list [PR117866]

Message ID f485b7950ce98171e6e2630b2ead90e6ea9a1ceb.camel@tugraz.at
State New
Headers
Series c: Restore warning for incomplete structures declared in parameter list [PR117866] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed

Commit Message

Martin Uecker Jan. 6, 2025, 2:51 p.m. UTC
  Happy new year! Please consider the following patch.

Bootstrapped and regression tested on x86_64.


    c: Restore warning for incomplete structures declared in parameter list [PR117866]
    
    In C23 mode the warning about declaring structures and union in
    parameter lists was removed, because it is possible to redeclare
    a compatible type elsewhere.  This is not the case for incomplete types,
    so restore the warning for those types.
    
            PR c/117886
    
    gcc/c/ChangeLog:
            * c-decl.cc (get_parm_info): Change condition for warning.
    
    gcc/testsuite/ChangeLog:
            * gcc.dg/pr117866.c: New test.
            * gcc.dg/struct-pr118007.c: Adapt.
  

Comments

Joseph Myers Jan. 6, 2025, 6:59 p.m. UTC | #1
On Mon, 6 Jan 2025, Martin Uecker wrote:

> 
> Happy new year! Please consider the following patch.
> 
> Bootstrapped and regression tested on x86_64.
> 
> 
>     c: Restore warning for incomplete structures declared in parameter list [PR117866]
>     
>     In C23 mode the warning about declaring structures and union in
>     parameter lists was removed, because it is possible to redeclare
>     a compatible type elsewhere.  This is not the case for incomplete types,
>     so restore the warning for those types.
>     
>             PR c/117886
>     
>     gcc/c/ChangeLog:
>             * c-decl.cc (get_parm_info): Change condition for warning.
>     
>     gcc/testsuite/ChangeLog:
>             * gcc.dg/pr117866.c: New test.
>             * gcc.dg/struct-pr118007.c: Adapt.

OK.
  

Patch

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index f60b2a54a17..56d13884182 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -8677,7 +8677,7 @@  get_parm_info (bool ellipsis, tree expr)
 	      if (b->id)
 		{
 		  /* The %s will be one of 'struct', 'union', or 'enum'.  */
-		  if (!flag_isoc23)
+		  if (!flag_isoc23 || !COMPLETE_TYPE_P (decl))
 		    warning_at (b->locus, 0,
 				"%<%s %E%> declared inside parameter list"
 				" will not be visible outside of this definition or"
diff --git a/gcc/testsuite/gcc.dg/pr117866.c b/gcc/testsuite/gcc.dg/pr117866.c
new file mode 100644
index 00000000000..3caf707791d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr117866.c
@@ -0,0 +1,5 @@ 
+/* { dg-do compile } */
+/* { dg-options "-std=c23" } */
+
+void convert(struct fractpoint *pt);	/* { dg-warning "declared inside parameter list" } */
+
diff --git a/gcc/testsuite/gcc.dg/strub-pr118007.c b/gcc/testsuite/gcc.dg/strub-pr118007.c
index 6c24cad6529..51f48245b3f 100644
--- a/gcc/testsuite/gcc.dg/strub-pr118007.c
+++ b/gcc/testsuite/gcc.dg/strub-pr118007.c
@@ -2,4 +2,4 @@ 
 /* { dg-do compile } */
 /* { dg-options "-fstrub=all -O2" } */
 
-void rb_ec_error_print(struct rb_execution_context_struct *volatile) {}
+void rb_ec_error_print(struct rb_execution_context_struct *volatile) {}	/* { dg-warning "declared inside parameter list" } */