93 lines · c
1// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes -Wno-implicit-function-declaration -Wno-error=implicit-int -verify %s2// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes -Wno-implicit-function-declaration -Wno-error=implicit-int -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s3 4// function definition with 0 params, no prototype, no preceding declaration.5void foo0() {} // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}6 7// function declaration with unspecified params8void foo1(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}9 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:"void"10// function declaration with 0 params11void foo2(void);12 13// function definition with 0 params, no prototype.14void foo1() {} // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}15// function definition with 0 params, prototype.16void foo2(void) {}17 18// function type typedef unspecified params19typedef void foo3(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}20 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:19}:"void"21 22// global fp unspecified params23void (*foo4)(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}24 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"void"25 26// struct member fp unspecified params27struct { void (*foo5)(); } s; // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}28 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:23-[[@LINE-1]]:23}:"void"29 30// param fp unspecified params31void bar2(void (*foo6)()) { // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}32 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:24-[[@LINE-1]]:24}:"void"33 // local fp unspecified params34 void (*foo7)() = 0; // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}35 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"void"36 // array fp unspecified params37 void (*foo8[2])() = {0}; // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}38 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:19}:"void"39}40 41// function type cast using using an anonymous function declaration42void bar3(void) {43 // casting function w/out prototype to unspecified params function type44 (void)(void(*)()) foo1; // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}45 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:18-[[@LINE-1]]:18}:"void"46 // .. specified params47 (void)(void(*)(void)) foo1;48}49 50// K&R function definition not preceded by full prototype51int foo9(a, b) // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C23}}52 int a, b;53{54 return a + b;55}56 57// Function declaration with no types58void foo10(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}} \59 expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C23, conflicting with a subsequent definition}}60 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"void"61// K&R function definition with incomplete param list declared62void foo10(p, p2) void *p; {} // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C23}} \63 expected-warning {{parameter 'p2' was not declared, defaults to 'int'; ISO C99 and later do not support implicit int}}64 65void foo11(int p, int p2);66void foo11(p, p2) int p; int p2; {} // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C23}}67 68// PR3102069void __attribute__((cdecl)) foo12(d) // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C23}}70 short d;71{}72 73// No warnings for variadic functions. Overloadable attribute is required74// to avoid err_ellipsis_first_param error.75void foo13(...) __attribute__((overloadable));76void foo13(...) __attribute__((overloadable)) {}77 78// We should not generate a strict-prototype warning for an implicit79// declaration. Leave that up to the implicit-function-declaration warning.80void foo14(void) {81 foo14_call(); // no-warning82}83 84// Ensure that redeclarations involving a typedef type work properly, even if85// there are function attributes involved in the declaration.86typedef void foo_t(unsigned val);87__attribute__((noreturn)) foo_t foo15;88foo_t foo15; // OK89void foo15(unsigned val); // OK90 91foo_t foo16;92void foo16(unsigned val); // OK93