[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Sema / attr-nocf_check.cpp
blobe306c8ef79cd545625eae4a25a7baa6608e2b291
1 // RUN: %clang_cc1 -triple=i386-unknown-unknown -verify -fcf-protection=branch -std=c++11 -fsyntax-only %s
3 // Function pointer definition.
4 [[gnu::nocf_check]] typedef void (*FuncPointerWithNoCfCheck)(void); // no-warning
5 typedef void (*FuncPointer)(void);
7 // Dont allow function declaration and definition mismatch.
8 [[gnu::nocf_check]] void testNoCfCheck(); // expected-note {{previous declaration is here}}
9 void testNoCfCheck(){}; // expected-error {{conflicting types for 'testNoCfCheck'}}
11 // No variable or parameter declaration
12 int [[gnu::nocf_check]] i; // expected-error {{'nocf_check' attribute cannot be applied to types}}
13 void testNoCfCheckImpl(double i [[gnu::nocf_check]]) {} // expected-warning {{'nocf_check' attribute only applies to functions and function pointers}}
15 // Allow attributed function pointers as well as casting between attributed
16 // and non-attributed function pointers.
17 void testNoCfCheckMismatch(FuncPointer f) {
18 FuncPointerWithNoCfCheck fNoCfCheck = f; // expected-error {{cannot initialize a variable of type}}
19 (*fNoCfCheck)(); // no-warning
22 // 'nocf_check' Attribute has no parameters.
23 [[gnu::nocf_check(1)]] int testNoCfCheckParams(); // expected-error {{'nocf_check' attribute takes no arguments}}