162 lines · cpp
1// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++03 -E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM --implicit-check-not=:2// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++11 -E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM --implicit-check-not=:3// RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++03 -E -P %s -o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:4// RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E -P %s -o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:5 6#define CXX11(x) x: __has_cpp_attribute(x)7 8// CHECK: clang::fallthrough: 19CXX11(clang::fallthrough)10 11// CHECK: selectany: 012CXX11(selectany)13 14// The attribute name can be bracketed with double underscores.15// CHECK: clang::__fallthrough__: 116CXX11(clang::__fallthrough__)17 18// The scope cannot be bracketed with double underscores unless it is19// for gnu or clang.20// CHECK: __gsl__::suppress: 021CXX11(__gsl__::suppress)22 23// CHECK: _Clang::fallthrough: 124CXX11(_Clang::fallthrough)25 26// CHECK: __nodiscard__: 201907L27CXX11(__nodiscard__)28 29// CHECK: warn_unused_result: 030CXX11(warn_unused_result)31 32// CHECK: gnu::warn_unused_result: 133CXX11(gnu::warn_unused_result)34 35// CHECK: clang::warn_unused_result: 136CXX11(clang::warn_unused_result)37 38// CHECK: __gnu__::__const__: 139CXX11(__gnu__::__const__)40 41// Test that C++11, target-specific attributes behave properly.42 43// CHECK: gnu::mips16: 044CXX11(gnu::mips16)45 46// Test for standard attributes as listed in C++2a [cpp.cond] paragraph 6.47 48CXX11(assert)49CXX11(carries_dependency)50CXX11(deprecated)51CXX11(ensures)52CXX11(expects)53CXX11(fallthrough)54CXX11(likely)55CXX11(maybe_unused)56CXX11(no_unique_address)57CXX11(msvc::no_unique_address)58CXX11(nodiscard)59CXX11(noreturn)60CXX11(unlikely)61// FIXME(201806L) CHECK: assert: 062// CHECK: carries_dependency: 200809L63// CHECK: deprecated: 201309L64// FIXME(201806L) CHECK: ensures: 065// FIXME(201806L) CHECK: expects: 066// CHECK: fallthrough: 201603L67// CHECK: likely: 201803L68// CHECK: maybe_unused: 201603L69// ITANIUM: no_unique_address: 201803L70// WINDOWS: no_unique_address: 071// ITANIUM: msvc::no_unique_address: 072// WINDOWS: msvc::no_unique_address: 201803L73// CHECK: nodiscard: 201907L74// CHECK: noreturn: 200809L75// CHECK: unlikely: 201803L76 77namespace PR48462 {78// Test that macro expansion of the builtin argument works.79#define C clang80#define F fallthrough81#define CF clang::fallthrough82 83#if __has_cpp_attribute(F)84int has_fallthrough;85#endif86// CHECK: int has_fallthrough;87 88#if __has_cpp_attribute(C::F)89int has_clang_falthrough_1;90#endif91// CHECK: int has_clang_falthrough_1;92 93#if __has_cpp_attribute(clang::F)94int has_clang_falthrough_2;95#endif96// CHECK: int has_clang_falthrough_2;97 98#if __has_cpp_attribute(C::fallthrough)99int has_clang_falthrough_3;100#endif101// CHECK: int has_clang_falthrough_3;102 103#if __has_cpp_attribute(CF)104int has_clang_falthrough_4;105#endif106// CHECK: int has_clang_falthrough_4;107 108#define FUNCLIKE1(x) clang::x109#if __has_cpp_attribute(FUNCLIKE1(fallthrough))110int funclike_1;111#endif112// CHECK: int funclike_1;113 114#define FUNCLIKE2(x) _Clang::x115#if __has_cpp_attribute(FUNCLIKE2(fallthrough))116int funclike_2;117#endif118// CHECK: int funclike_2;119 120#if __has_cpp_attribute(CF\121)122int has_clang_falthrough_5;123#endif124// CHECK: int has_clang_falthrough_5;125 126#define CF_2 clang::\127fallthrough128 129#if __has_cpp_attribute(CF_2)130int has_clang_falthrough_6;131#endif132// CHECK: int has_clang_falthrough_6;133 134#if __has_cpp_attribute(CF_2\135)136int has_clang_falthrough_7;137#endif138// CHECK: int has_clang_falthrough_7;139}140 141// Test for Microsoft __declspec attributes142 143#define DECLSPEC(x) x: __has_declspec_attribute(x)144 145// CHECK: uuid: 1146// CHECK: __uuid__: 1147DECLSPEC(uuid)148DECLSPEC(__uuid__)149 150// CHECK: fallthrough: 0151DECLSPEC(fallthrough)152 153namespace PR48462 {154// Test that macro expansion of the builtin argument works.155#define U uuid156 157#if __has_declspec_attribute(U)158int has_uuid;159#endif160// CHECK: int has_uuid;161}162