error ("%<[*]%> not allowed in other than function prototype scope");
}
- if (arg_types == NULL_TREE && !funcdef_flag
+ if (arg_types == NULL_TREE && !funcdef_flag && !flag_isoc2x
&& !in_system_header_at (input_location))
warning (OPT_Wstrict_prototypes,
"function declaration isn%'t a prototype");
tree parm, type, typelt;
unsigned int parmno;
- /* In C2X, convert () in a function definition to (void). */
+ /* In C2X, convert () to (void). */
if (flag_isoc2x
- && funcdef_flag
&& !arg_types
&& !arg_info->parms)
arg_types = arg_info->types = void_list_node;
--- /dev/null
+/* Test function declarations without prototypes for C11. */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+void f1 ();
+void
+f1a (void)
+{
+ f1 (1, 2);
+}
+
+void f2 ();
+void f2 (int);
+
+void f3 ();
+
+_Static_assert (_Generic (f3,
+ void (*) (int) : 1,
+ default : 3) == 1, "unprototyped test");
-/* Test old-style function definitions not in C2x: () does not give
- type with a prototype except for function definitions. */
+/* Test old-style function definitions not in C2x: () gives a type with
+ a prototype for all declarations. */
/* { dg-do compile } */
/* { dg-options "-std=c2x" } */
-void f1 ();
+void f1 (); /* { dg-message "declared here" } */
-/* Prototyped function returning a pointer to unprototyped function. */
+/* Prototyped function returning a pointer to a function with no arguments. */
void (*f2 (void))() { return f1; }
void
g (void)
{
- f1 (1);
- f2 () (1);
+ f1 (1); /* { dg-error "too many arguments" } */
+ f2 () (1); /* { dg-error "too many arguments" } */
}
-/* Test compatibility of unprototyped and prototyped function types (C2x made
- the case of types affected by default argument promotions compatible, before
- removing unprototyped functions completely). Test affected usages are not
- accepted for C2x. */
+/* Test compatibility of prototyped function types with and without arguments
+ (C2x made the case of types affected by default argument promotions
+ compatible, before removing unprototyped functions completely). Test
+ affected usages are not accepted for C2x. */
/* { dg-do compile } */
/* { dg-options "-std=c2x -pedantic-errors" } */
void f1 (); /* { dg-message "previous declaration" } */
void f1 (float); /* { dg-error "conflicting types" } */
-/* { dg-message "default promotion" "" { target *-*-* } .-1 } */
void f2 (float); /* { dg-message "previous declaration" } */
void f2 (); /* { dg-error "conflicting types" } */
-/* { dg-message "default promotion" "" { target *-*-* } .-1 } */
void f3 (); /* { dg-message "previous declaration" } */
void f3 (char); /* { dg-error "conflicting types" } */
-/* { dg-message "default promotion" "" { target *-*-* } .-1 } */
void f4 (char); /* { dg-message "previous declaration" } */
void f4 (); /* { dg-error "conflicting types" } */
-/* { dg-message "default promotion" "" { target *-*-* } .-1 } */
/* Built-in function case. */
float sqrtf (); /* { dg-warning "conflicting types for built-in function" } */
-/* Test compatibility of unprototyped and prototyped function types (C2x made
- the case of types affected by default argument promotions compatible, before
- removing unprototyped functions completely). Test always-invalid-in-C2x
- usages, in C2X mode. */
+/* Test compatibility of prototyped function types without arguments and with
+ variable arguments (C2x made the case of types affected by default argument
+ promotions compatible, before removing unprototyped functions completely).
+ Test always-invalid-in-C2x usages, in C2X mode. */
/* { dg-do compile } */
/* { dg-options "-std=c2x -pedantic-errors" } */
void f1 (); /* { dg-message "previous declaration" } */
void f1 (int, ...); /* { dg-error "conflicting types" } */
-/* { dg-message "ellipsis" "" { target *-*-* } .-1 } */
void f2 (int, ...); /* { dg-message "previous declaration" } */
void f2 (); /* { dg-error "conflicting types" } */
-/* { dg-message "ellipsis" "" { target *-*-* } .-1 } */
void f3 (); /* { dg-message "previous declaration" } */
void f3 (char, ...); /* { dg-error "conflicting types" } */
-/* { dg-message "ellipsis" "" { target *-*-* } .-1 } */
void f4 (char, ...); /* { dg-message "previous declaration" } */
void f4 (); /* { dg-error "conflicting types" } */
-/* { dg-message "ellipsis" "" { target *-*-* } .-1 } */
--- /dev/null
+/* Test that declaring a function with () is the same as (void) in C2X. Valid
+ use cases. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors -Wstrict-prototypes" } */
+
+void f1 ();
+void f1 (void);
+
+void f2 (void);
+void f2 ();
+
+typedef void T1 ();
+typedef void T1 (void);
+
+void f3 ();
+
+_Static_assert (_Generic (f3,
+ void (*) (int) : 1,
+ void (*) (void) : 2,
+ default : 3) == 2);
--- /dev/null
+/* Test that declaring a function with () is the same as (void) in C2X.
+ Invalid use cases. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+
+void f1 (); /* { dg-message "previous declaration" } */
+void f1 (int); /* { dg-error "conflicting types" } */
+
+void f2 (); /* { dg-message "declared here" } */
+
+void
+f3 (void)
+{
+ f2 (1); /* { dg-error "too many arguments" } */
+}