https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108694

            Bug ID: 108694
           Summary: need a new warning option for preparing migration to
                    ISO C 23
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bruno at clisp dot org
  Target Milestone: ---

The use of () to denote an unknown or varargs parameter list in function
declarations and function types, a language feature from K&R C, is finally
disallowed in ISO C 23. Instead, () as a parameter list denotes a list of zero
arguments, the same as (void), in ISO C 23.

The set of warnings that were added to GCC over the years, regarding function
prototypes, were designed at a time when the migration target was still
unknown. Now that the migration target, ISO C 23, is known, some projects want
to have the following programming style, for code that compiles OK both in C99
and C23:
- (1) In function definitions, use () to denote argument lists with zero
arguments.
- (2) In function declarations and function types, use (void) to denote
argument lists with zero arguments.
See https://lists.gnu.org/archive/html/bug-gnulib/2023-02/msg00055.html and
https://lists.gnu.org/archive/html/bug-gnulib/2023-02/msg00062.html for details
of the rationale.

As a programmer, I would like to have an easy way to get warnings when this
programming style is not followed.

There are two ways such a warning could be added to GCC:

(A) A warning that applies when compiling for a language standard older than
C23 (e.g. -std=gnu99).

In which situations would this warning be emitted?
=========================================================================
/* Function definitions: */
void func1 () {} /* No warning */
void func2 (void) {} /* No warning */
/* Function declarations: */
void func3 (); /* warning: an empty parameter list in function declarators will
have a different meaning in ISO C23 */
void func4 (void); /* No warning */
=========================================================================

Looking through the existing warning options of GCC and clang:

Warning options from https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
Option                      Not adequate because ...
-----------------------     ------------------------
-Wall                       Does not warn for func3.
-Wstrict-prototypes         Warns for func1 as well.
-Wold-style-declaration     Does not warn for func3.
-Wold-style-definition      Does not warn for func3. Warns for func1.
-Wmissing-prototypes        Does not warn for func3. Warns for func1 and func2.
-Wmissing-declarations      Does not warn for func3. Warns for func1 and func2.
-Wpedantic                  Does not warn for func3.

Warning options from https://clang.llvm.org/docs/DiagnosticsReference.html
Option                      Not adequate because ...
-----------------------     ------------------------
-Wall                       Does not warn for func3.
-Wdeprecated-declarations   Does not warn for func3.
-Wdeprecated-non-prototype  Does not warn for func3.
-Wmissing-prototypes        Does not warn for func3. Warns for func1 and func2.
-Wpedantic                  Warns for func1 as well.

So, none of these existing warning options fits the need. A new warning option
is needed.

(B) A warning that applies when compiling for C23 (e.g. -std=gnu23).

The situations would be the same as above. Only the diagnostic's message would
refer to *older* standard versions, such as:
=========================================================================
/* Function definitions: */
void func1 () {} /* No warning */
void func2 (void) {} /* No warning */
/* Function declarations: */
void func3 (); /* warning: an empty parameter list in function declarators
denotes a varargs parameter list in ISO C17 and older; use (void) to
disambiguate */
void func4 (void); /* No warning */
=========================================================================

Reply via email to