= ((pedantic && !flag_isoc23 && warn_c11_c23_compat != 0)
|| warn_c11_c23_compat > 0);
+ if (warn_deprecated_non_prototype == -1)
+ warn_deprecated_non_prototype = warn_c11_c23_compat > 0;
+
/* -Wshift-negative-value is enabled by -Wextra in C99 and C++11 to C++17
modes. */
if (warn_shift_negative_value == -1)
C++ ObjC++ Var(warn_deprecated_literal_operator) Warning
Warn about deprecated space between "" and suffix in a user-defined literal operator.
+Wdeprecated-non-prototype
+C ObjC Var(warn_deprecated_non_prototype) Init(-1) Warning
+Warn about calls with arguments to functions declared without parameters.
+
Wdesignated-init
C ObjC Var(warn_designated_init) Init(1) Warning
Warn about positional initialization of structs requiring designated initializers.
Wdeprecated-literal-operator
UrlSuffix(gcc/C_002b_002b-Dialect-Options.html#index-Wdeprecated-literal-operator)
+Wdeprecated-non-prototype
+UrlSuffix(gcc/Warning-Options.html#index-Wdeprecated-non-prototype)
+
Wdesignated-init
UrlSuffix(gcc/Warning-Options.html#index-Wdesignated-init)
}
}
+ /* Optionally warn about C23 compatibility. */
+ if (warn_deprecated_non_prototype
+ && old_decl != NULL_TREE
+ && TREE_CODE (oldtype) == FUNCTION_TYPE
+ && !TYPE_ARG_TYPES (oldtype)
+ && !TYPE_NO_NAMED_ARGS_STDARG_P (oldtype)
+ && (TYPE_ARG_TYPES (newtype)
+ && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != void_type_node))
+ {
+ bool warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
+ "ISO C23 does not allow defining"
+ " parameters for function %qE declared"
+ " without parameters",
+ decl1);
+ if (warned)
+ inform (DECL_SOURCE_LOCATION (old_decl), "declared here");
+ }
+
/* Optionally warn of old-fashioned def with no previous prototype. */
if (warn_strict_prototypes
&& old_decl != error_mark_node
/* Convert the parameters to the types declared in the
function prototype, or apply default promotions. */
- nargs = convert_arguments (loc, arg_loc, TYPE_ARG_TYPES (fntype), params,
+ nargs = convert_arguments (loc, arg_loc, fntype, params,
origtypes, function, fundecl);
if (nargs < 0)
return error_mark_node;
}
/* Convert the argument expressions in the vector VALUES
- to the types in the list TYPELIST.
+ to the types in the list TYPE_ARG_TYPES (FNTYPE).
- If TYPELIST is exhausted, or when an element has NULL as its type,
+ If the list is exhausted, or when an element has NULL as its type,
perform the default conversions.
ORIGTYPES is the original types of the expressions in VALUES. This
failure. */
static int
-convert_arguments (location_t loc, vec<location_t> arg_loc, tree typelist,
+convert_arguments (location_t loc, vec<location_t> arg_loc, tree fntype,
vec<tree, va_gc> *values, vec<tree, va_gc> *origtypes,
tree function, tree fundecl)
{
+ tree typelist = TYPE_ARG_TYPES (fntype);
unsigned int parmnum;
bool error_args = false;
const bool type_generic = fundecl
builtin_typetail = NULL_TREE;
}
+ if (!typetail && parmnum == 0 && !TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
+ {
+ bool warned;
+ if (selector)
+ warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
+ "ISO C23 does not allow arguments"
+ " for method %qE declared without parameters",
+ function);
+ else
+ warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
+ "ISO C23 does not allow arguments"
+ " for function %qE declared without parameters",
+ function);
+ if (warned)
+ inform_declaration (fundecl);
+ }
+
if (selector && argnum > 2)
{
rname = selector;
}
@item C and Objective-C-only Warning Options
-@gccoptlist{-Wbad-function-cast -Wmissing-declarations
+@gccoptlist{-Wbad-function-cast -Wdeprecated-non-prototype -Wmissing-declarations
-Wmissing-parameter-name -Wmissing-parameter-type
-Wdeclaration-missing-parameter-type -Wmissing-prototypes
-Wmissing-variable-declarations -Wnested-externs -Wold-style-declaration
equivalent to @samp{(void)} in that case, but is considered an
old-style definition for older standards.
+@opindex Wdeprecated-non-prototype
+@opindex Wno-deprecated-non-prototype
+@item -Wdeprecated-non-prototype @r{(C and Objective-C only)}
+Warn if a function declarated with an empty parameter list @samp{()} is
+called with one or more arguments, or if a function definition with one
+or more parameters is encountered after such a declaration. Both cases
+are errors in C23 and later dialects of C.
+
+This warning is also enabled by @option{-Wc11-c23-compat}.
+
@opindex Wmissing-parameter-name
@opindex Wno-missing-parameter-name
@item -Wmissing-parameter-name @r{(C and Objective-C only)}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-std=gnu17 -Wdeprecated-non-prototype" } */
+
+void f1 ();
+void f2 (); /* { dg-note "declared here" } */
+void f3 (...);
+
+void
+g ()
+{
+ f1 ();
+ f2 (1); /* { dg-warning "does not allow arguments for function" } */
+ f3 (1);
+}
+
+void
+f1 ()
+{
+}
+
+void
+f2 (int i) /* { dg-warning "does not allow defining parameters for function" } */
+{
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-std=gnu17 -Wc11-c23-compat" } */
+
+void f1 ();
+void f2 (); /* { dg-note "declared here" } */
+
+void
+g ()
+{
+ f1 ();
+ f2 (1); /* { dg-warning "does not allow arguments for function" } */
+}
+
+void
+f1 ()
+{
+}
+
+void
+f2 (int i) /* { dg-warning "does not allow defining parameters for function" } */
+{
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-std=gnu17 -Wdeprecated-non-prototype -Wno-declaration-missing-parameter-type" } */
+
+void f1 (not_a_type); /* { dg-note "declared here" } */
+void f2 (not_a_type); /* { dg-note "declared here" } */
+
+void
+g ()
+{
+ /* This is not ideal, but the GCC type system does not capture the number of
+ arguments in a non-prototype function declaration. */
+ f1 (1); /* { dg-warning "does not allow arguments for function" } */
+}
+
+void
+f2 (int not_a_type) /* { dg-warning "does not allow defining parameters" } */
+{
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-std=gnu17 -Wc11-c23-compat -Wno-deprecated-non-prototype" } */
+
+void f1 ();
+void f2 ();
+
+void
+g ()
+{
+ f1 ();
+ f2 (1);
+}
+
+void
+f1 ()
+{
+}
+
+void
+f2 (int i)
+{
+}