1 // RUN: %clang_cc1 %s -verify -fsyntax-only -Werror=implicit-function-declaration -std=c99
2 // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11
3 // RUN: %clang_cc1 %s -verify=c2x -fsyntax-only -std=c2x
4 
5 /// -Werror-implicit-function-declaration is a deprecated alias used by many projects.
6 // RUN: %clang_cc1 %s -verify -fsyntax-only -Werror-implicit-function-declaration
7 
8 // c2x-note@*:* {{'__builtin_va_list' declared here}}
9 
10 typedef int int32_t;
11 typedef unsigned char Boolean;
12 
13 extern int printf(__const char *__restrict __format, ...); // expected-note{{'printf' declared here}} \
14                                                               c2x-note {{'printf' declared here}}
15 
16 void func(void) {
17    int32_t *vector[16];
18    const char compDesc[16 + 1];
19    int32_t compCount = 0;
20    if (_CFCalendarDecomposeAbsoluteTimeV(compDesc, vector, compCount)) { // expected-error {{call to undeclared function '_CFCalendarDecomposeAbsoluteTimeV'; ISO C99 and later do not support implicit function declarations}} \
21                                                                             expected-note {{previous implicit declaration}} \
22                                                                             c2x-error {{use of undeclared identifier '_CFCalendarDecomposeAbsoluteTimeV'}}
23    }
24 
25    printg("Hello, World!\n"); // expected-error{{call to undeclared function 'printg'; ISO C99 and later do not support implicit function declarations}} \
26                                  expected-note{{did you mean 'printf'?}} \
27                                  c2x-error {{use of undeclared identifier 'printg'; did you mean 'printf'?}}
28 
29   __builtin_is_les(1, 3); // expected-error{{use of unknown builtin '__builtin_is_les'}} \
30                              c2x-error {{unknown type name '__builtin_is_les'; did you mean '__builtin_va_list'?}} \
31                              c2x-error {{expected identifier or '('}} \
32                              c2x-error {{expected ')'}} \
33                              c2x-note {{to match this '('}}
34 }
35 Boolean _CFCalendarDecomposeAbsoluteTimeV(const char *componentDesc, int32_t **vector, int32_t count) { // expected-error {{conflicting types}}
36  return 0;
37 }
38 
39 
40 // Test the typo-correction callback in Sema::ImplicitlyDefineFunction
41 extern int sformatf(char *str, __const char *__restrict __format, ...); // expected-note{{'sformatf' declared here}}
42 void test_implicit(void) {
43   int formats = 0; // c2x-note {{'formats' declared here}}
44   formatd("Hello, World!\n"); // expected-error{{call to undeclared function 'formatd'; ISO C99 and later do not support implicit function declarations}} \
45                                  expected-note{{did you mean 'sformatf'?}} \
46                                  c2x-error {{use of undeclared identifier 'formatd'; did you mean 'formats'?}} \
47                                  c2x-error {{called object type 'int' is not a function or function pointer}}
48 }
49 
50 void test_suggestion(void) {
51   bark(); // expected-error {{call to undeclared function 'bark'; ISO C99 and later do not support implicit function declarations}} \
52              c2x-error {{use of undeclared identifier 'bark'}}
53   bork(); // expected-error {{call to undeclared function 'bork'; ISO C99 and later do not support implicit function declarations}} \
54              c2x-error {{use of undeclared identifier 'bork'}}
55 }
56