1 // RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -verify -fsyntax-only %s
2 // RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -verify -std=c++11 -fsyntax-only -x c++ %s
3 // RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -verify -fsyntax-only %s
4 // RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -verify -std=c++11 -fsyntax-only -x c++ %s
5 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -verify -fsyntax-only %s
6 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -verify -std=c++11 -fsyntax-only -x c++ %s
7
8 // The x86_64-w64-windows-gnu version tests mingw target, which relies on
9 // __declspec(...) being defined as __attribute__((...)) by compiler built-in.
10
11 #if defined(_WIN32)
12
13 // Function definition.
testGuardNoCF(void)14 __declspec(guard(nocf)) void testGuardNoCF(void) { // no warning
15 }
16
17 // Function definition using GNU-style attribute without relying on the
18 // __declspec define for mingw.
testGNUStyleGuardNoCF(void)19 __attribute__((guard(nocf))) void testGNUStyleGuardNoCF(void) { // no warning
20 }
21
22 // Can not be used on variable, parameter, or function pointer declarations.
23 int __declspec(guard(nocf)) i; // expected-warning {{'guard' attribute only applies to functions}}
testGuardNoCFFuncParam(double i)24 void testGuardNoCFFuncParam(double __declspec(guard(nocf)) i) {} // expected-warning {{'guard' attribute only applies to functions}}
25 __declspec(guard(nocf)) typedef void (*FuncPtrWithGuardNoCF)(void); // expected-warning {{'guard' attribute only applies to functions}}
26
27 // 'guard' Attribute requries an argument.
testGuardNoCFParams(void)28 __declspec(guard) void testGuardNoCFParams(void) { // expected-error {{'guard' attribute takes one argument}}
29 }
30
31 // 'guard' Attribute requries an identifier as argument.
testGuardNoCFParamType(void)32 __declspec(guard(1)) void testGuardNoCFParamType(void) { // expected-error {{'guard' attribute requires an identifier}}
33 }
34
35 // 'guard' Attribute only takes a single argument.
testGuardNoCFTooManyParams(void)36 __declspec(guard(nocf, nocf)) void testGuardNoCFTooManyParams(void) { // expected-error {{use of undeclared identifier 'nocf'}}
37 }
38
39 // 'guard' Attribute argument must be a supported identifier.
testGuardNoCFInvalidParam(void)40 __declspec(guard(cf)) void testGuardNoCFInvalidParam(void) { // expected-warning {{'guard' attribute argument not supported: 'cf'}}
41 }
42
43 #else
44
guard(nocf)45 __attribute((guard(nocf))) void testGNUStyleGuardNoCF(void) {} // expected-warning {{unknown attribute 'guard' ignored}}
46
47 #endif
48