94 lines · c
1// RUN: %clang_cc1 %s -verify=expected,both -fsyntax-only -Werror=implicit-function-declaration -std=c992// RUN: %clang_cc1 %s -verify=expected,both -fsyntax-only -std=c113// RUN: %clang_cc1 %s -verify=c2x,both -fsyntax-only -std=c2x4 5/// -Werror-implicit-function-declaration is a deprecated alias used by many projects.6// RUN: %clang_cc1 %s -verify=expected,both -fsyntax-only -Werror-implicit-function-declaration7 8// c2x-note@*:* {{'__builtin_va_list' declared here}}9 10typedef int int32_t;11typedef unsigned char Boolean;12 13extern int printf(__const char *__restrict __format, ...); // both-note{{'printf' declared here}}14void func(void) {15 int32_t *vector[16];16 const char compDesc[16 + 1] = { 0 };17 int32_t compCount = 0;18 if (_CFCalendarDecomposeAbsoluteTimeV(compDesc, vector, compCount)) { // expected-error {{call to undeclared function '_CFCalendarDecomposeAbsoluteTimeV'; ISO C99 and later do not support implicit function declarations}} \19 expected-note {{previous implicit declaration}} \20 c2x-error {{use of undeclared identifier '_CFCalendarDecomposeAbsoluteTimeV'}}21 }22 23 printg("Hello, World!\n"); // expected-error{{call to undeclared function 'printg'; ISO C99 and later do not support implicit function declarations}} \24 expected-note{{did you mean 'printf'?}} \25 c2x-error {{use of undeclared identifier 'printg'; did you mean 'printf'?}}26 27 __builtin_is_les(1, 3); // expected-error{{use of unknown builtin '__builtin_is_les'}} \28 c2x-error {{unknown type name '__builtin_is_les'; did you mean '__builtin_va_list'?}} \29 c2x-error {{expected identifier or '('}} \30 c2x-error {{expected ')'}} \31 c2x-note {{to match this '('}}32}33Boolean _CFCalendarDecomposeAbsoluteTimeV(const char *componentDesc, int32_t **vector, int32_t count) { // expected-error {{conflicting types}}34 return 0;35}36 37 38// Test the typo-correction callback in Sema::ImplicitlyDefineFunction39extern int sformatf(char *str, __const char *__restrict __format, ...); // expected-note{{'sformatf' declared here}}40void test_implicit(void) {41 int formats = 0; // c2x-note {{'formats' declared here}}42 formatd("Hello, World!\n"); // expected-error{{call to undeclared function 'formatd'; ISO C99 and later do not support implicit function declarations}} \43 expected-note{{did you mean 'sformatf'?}} \44 c2x-error {{use of undeclared identifier 'formatd'; did you mean 'formats'?}} \45 c2x-error {{called object type 'int' is not a function or function pointer}}46}47 48void test_suggestion(void) {49 bark(); // expected-error {{call to undeclared function 'bark'; ISO C99 and later do not support implicit function declarations}} \50 c2x-error {{use of undeclared identifier 'bark'}}51 bork(); // expected-error {{call to undeclared function 'bork'; ISO C99 and later do not support implicit function declarations}} \52 c2x-error {{use of undeclared identifier 'bork'}}53}54 55// The following used to cause an assertion from trying to define the implicit56// function within a structure scope as opposed to within function or global57// scoped.58int GH48579_1(void) {59 struct {60 int x __attribute__((aligned(({ a(); })))); // expected-error {{call to undeclared function 'a'; ISO C99 and later do not support implicit function declarations}} \61 c2x-error {{use of undeclared identifier 'a'}} \62 both-error {{'aligned' attribute requires integer constant}}63 } x;64}65 66void GH48579_2(void) {67 struct S {68 int array[({ a(); })]; // expected-error {{call to undeclared function 'a'; ISO C99 and later do not support implicit function declarations}} \69 c2x-error {{use of undeclared identifier 'a'}} \70 expected-error {{fields must have a constant size: 'variable length array in structure' extension will never be supported}} \71 c2x-error {{size of array has non-integer type 'void'}}72 };73}74 75int GH48579_3 = ({a();}); // both-error {{statement expression not allowed at file scope}}76void GH48579_4(int array[({ a(); })]); // both-error {{statement expression not allowed at file scope}}77 78void pragma_warning(void) {79#pragma clang diagnostic warning "-Wimplicit-function-declaration"80 bark(); // expected-warning {{call to undeclared function 'bark'; ISO C99 and later do not support implicit function declarations}} \81 c2x-error {{use of undeclared identifier 'bark'}}82}83 84void pragma_error(void) {85#pragma clang diagnostic error "-Wimplicit-function-declaration"86 bark(); // expected-error {{call to undeclared function 'bark'; ISO C99 and later do not support implicit function declarations}} \87 c2x-error {{use of undeclared identifier 'bark'}}88}89 90void pragma_ignored(void) {91#pragma clang diagnostic ignored "-Wimplicit-function-declaration"92 bark(); // c2x-error {{use of undeclared identifier 'bark'}}93}94