diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 51a62c800f7..3b45cfda0ff 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -1692,7 +1692,7 @@ function_types_compatible_p (const_tree f1, const_tree f2, if (args1 == NULL_TREE) { - if (!self_promoting_args_p (args2)) + if (flag_isoc2x ? stdarg_p (f2) : !self_promoting_args_p (args2)) return 0; /* If one of these types comes from a non-prototype fn definition, compare that with the other type's arglist. @@ -1705,7 +1705,7 @@ function_types_compatible_p (const_tree f1, const_tree f2, } if (args2 == NULL_TREE) { - if (!self_promoting_args_p (args1)) + if (flag_isoc2x ? stdarg_p (f1) : !self_promoting_args_p (args1)) return 0; if (TYPE_ACTUAL_ARG_TYPES (f2) && type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), diff --git a/gcc/testsuite/gcc.dg/c11-unproto-1.c b/gcc/testsuite/gcc.dg/c11-unproto-1.c new file mode 100644 index 00000000000..ea9e807a68e --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-unproto-1.c @@ -0,0 +1,24 @@ +/* Test compatibility of unprototyped and prototyped function types (C2x makes + the case of types affected by default argument promotions compatible). Test + valid-in-C2x usages are not accepted for C11. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -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" } */ diff --git a/gcc/testsuite/gcc.dg/c11-unproto-2.c b/gcc/testsuite/gcc.dg/c11-unproto-2.c new file mode 100644 index 00000000000..0557ae3f5cb --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-unproto-2.c @@ -0,0 +1,21 @@ +/* Test compatibility of unprototyped and prototyped function types (C2x makes + the case of types affected by default argument promotions compatible). Test + invalid-in-C2x usages, in C11 mode. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -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 } */ diff --git a/gcc/testsuite/gcc.dg/c2x-unproto-1.c b/gcc/testsuite/gcc.dg/c2x-unproto-1.c new file mode 100644 index 00000000000..45d68f2c292 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-unproto-1.c @@ -0,0 +1,20 @@ +/* Test compatibility of unprototyped and prototyped function types (C2x makes + the case of types affected by default argument promotions compatible). Test + valid-in-C2x usages. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +void f1 (); +void f1 (float); + +void f2 (float); +void f2 (); + +void f3 (); +void f3 (char); + +void f4 (char); +void f4 (); + +/* Built-in function case. */ +float sqrtf (); diff --git a/gcc/testsuite/gcc.dg/c2x-unproto-2.c b/gcc/testsuite/gcc.dg/c2x-unproto-2.c new file mode 100644 index 00000000000..f826b7c3ac8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-unproto-2.c @@ -0,0 +1,21 @@ +/* Test compatibility of unprototyped and prototyped function types (C2x makes + the case of types affected by default argument promotions compatible). Test + invalid-in-C2x usages. */ +/* { 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 } */