1 // RUN: %clang_cc1 %s -verify=werror,both -fsyntax-only -Werror=implicit-function-declaration -std=c99
2 // RUN: %clang_cc1 %s -verify=expected,both -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=werror,both -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, ...); // werror-note{{'printf' declared here}} \
14                                                               c2x-note {{'printf' declared here}}
15 
func(void)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)) { // werror-error {{call to undeclared function '_CFCalendarDecomposeAbsoluteTimeV'; ISO C99 and later do not support implicit function declarations}} \
21                                                                             both-note {{previous implicit declaration}} \
22                                                                             expected-warning {{call to undeclared function '_CFCalendarDecomposeAbsoluteTimeV'; ISO C99 and later do not support implicit function declarations}} \
23                                                                             c2x-error {{use of undeclared identifier '_CFCalendarDecomposeAbsoluteTimeV'}}
24    }
25 
26    printg("Hello, World!\n"); // werror-error{{call to undeclared function 'printg'; ISO C99 and later do not support implicit function declarations}} \
27                                  werror-note{{did you mean 'printf'?}} \
28                                  expected-warning{{call to undeclared function 'printg'; ISO C99 and later do not support implicit function declarations}} \
29                                  c2x-error {{use of undeclared identifier 'printg'; did you mean 'printf'?}}
30 
31   __builtin_is_les(1, 3); // both-error{{use of unknown builtin '__builtin_is_les'}} \
32                              c2x-error {{unknown type name '__builtin_is_les'; did you mean '__builtin_va_list'?}} \
33                              c2x-error {{expected identifier or '('}} \
34                              c2x-error {{expected ')'}} \
35                              c2x-note {{to match this '('}}
36 }
_CFCalendarDecomposeAbsoluteTimeV(const char * componentDesc,int32_t ** vector,int32_t count)37 Boolean _CFCalendarDecomposeAbsoluteTimeV(const char *componentDesc, int32_t **vector, int32_t count) { // both-error {{conflicting types}}
38  return 0;
39 }
40 
41 
42 // Test the typo-correction callback in Sema::ImplicitlyDefineFunction
43 extern int sformatf(char *str, __const char *__restrict __format, ...); // werror-note{{'sformatf' declared here}}
test_implicit(void)44 void test_implicit(void) {
45   int formats = 0; // c2x-note {{'formats' declared here}}
46   formatd("Hello, World!\n"); // werror-error{{call to undeclared function 'formatd'; ISO C99 and later do not support implicit function declarations}} \
47                                  werror-note{{did you mean 'sformatf'?}} \
48                                  expected-warning{{call to undeclared function 'formatd'; ISO C99 and later do not support implicit function declarations}} \
49                                  c2x-error {{use of undeclared identifier 'formatd'; did you mean 'formats'?}} \
50                                  c2x-error {{called object type 'int' is not a function or function pointer}}
51 }
52 
test_suggestion(void)53 void test_suggestion(void) {
54   bark(); // werror-error {{call to undeclared function 'bark'; ISO C99 and later do not support implicit function declarations}} \
55              expected-warning {{call to undeclared function 'bark'; ISO C99 and later do not support implicit function declarations}} \
56              c2x-error {{use of undeclared identifier 'bark'}}
57   bork(); // werror-error {{call to undeclared function 'bork'; ISO C99 and later do not support implicit function declarations}} \
58              expected-warning {{call to undeclared function 'bork'; ISO C99 and later do not support implicit function declarations}} \
59              c2x-error {{use of undeclared identifier 'bork'}}
60 }
61