1 // RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
3 using size_t = __SIZE_TYPE__
;
5 // Test array initialization
7 const char a
[] = __FUNCTION__
; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
8 const char b
[] = __FUNCDNAME__
; // expected-warning{{initializing an array from a '__FUNCDNAME__' predefined identifier is a Microsoft extension}}
9 const char c
[] = __FUNCSIG__
; // expected-warning{{initializing an array from a '__FUNCSIG__' predefined identifier is a Microsoft extension}}
10 const char d
[] = __func__
; // expected-warning{{initializing an array from a '__func__' predefined identifier is a Microsoft extension}}
11 const char e
[] = __PRETTY_FUNCTION__
; // expected-warning{{initializing an array from a '__PRETTY_FUNCTION__' predefined identifier is a Microsoft extension}}
12 const wchar_t f
[] = L__FUNCTION__
; // expected-warning{{initializing an array from a 'L__FUNCTION__' predefined identifier is a Microsoft extension}}
13 const wchar_t g
[] = L__FUNCSIG__
; // expected-warning{{initializing an array from a 'L__FUNCSIG__' predefined identifier is a Microsoft extension}}
16 // Test function local identifiers outside of a function
17 const char* g_function
= __FUNCTION__
; // expected-warning{{predefined identifier is only valid inside function}}
18 const char* g_function_lconcat
= "" __FUNCTION__
; // expected-warning{{predefined identifier is only valid inside function}} \
19 // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
20 const char* g_function_rconcat
= __FUNCTION__
""; // expected-warning{{predefined identifier is only valid inside function}} \
21 // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
25 const char* function
= __FUNCTION__
; // expected-warning{{predefined identifier is only valid inside function}}
26 const char* function_lconcat
= "" __FUNCTION__
; // expected-warning{{predefined identifier is only valid inside function}} \
27 // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
28 const char* function_rconcat
= __FUNCTION__
""; // expected-warning{{predefined identifier is only valid inside function}} \
29 // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
33 static constexpr const char* function
= __FUNCTION__
; // expected-warning{{predefined identifier is only valid inside function}}
34 static constexpr const char* function_lconcat
= "" __FUNCTION__
; // expected-warning{{predefined identifier is only valid inside function}} \
35 // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
36 static constexpr const char* function_rconcat
= __FUNCTION__
""; // expected-warning{{predefined identifier is only valid inside function}} \
37 // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
41 template<class T
, class U
>
42 constexpr bool is_same
= false;
44 constexpr bool is_same
<T
, T
> = true;
46 template<typename T
, size_t N
>
47 constexpr bool equal(const T (&a
)[N
], const T (&b
)[N
]) {
48 for (size_t i
= 0; i
< N
; i
++)
54 #define ASSERT_EQ(X, Y) static_assert(equal(X, Y), "")
55 #define ASSERT_EQ_TY(X, Y) static_assert(is_same<decltype((X)[0]), decltype((Y)[0])>, "")
58 #define WIDE(s) _WIDE(s)
61 extern "C" void test_value() {
62 ASSERT_EQ(__FUNCTION__
, "test_value");
63 ASSERT_EQ(__FUNCSIG__
, "void __cdecl test_value(void)");
65 ASSERT_EQ(WIDE(__FUNCTION__
), L
"test_value");
66 ASSERT_EQ(WIDE(__FUNCSIG__
), L
"void __cdecl test_value(void)");
70 template<class T
> class A
{
73 ASSERT_EQ(L__FUNCTION__
, L
"method");
77 void test_template_value() {
84 extern "C" void test_concat() {
85 ASSERT_EQ("left_" __FUNCTION__
, "left_test_concat"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
86 ASSERT_EQ("left_" __FUNCDNAME__
, "left_test_concat"); // expected-warning{{expansion of predefined identifier '__FUNCDNAME__' to a string literal is a Microsoft extension}}
87 ASSERT_EQ("left " __FUNCSIG__
, "left void __cdecl test_concat(void)"); // expected-warning{{expansion of predefined identifier '__FUNCSIG__' to a string literal is a Microsoft extension}}
89 ASSERT_EQ(__FUNCTION__
"_right", "test_concat_right"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
90 ASSERT_EQ(__FUNCDNAME__
"_right", "test_concat_right"); // expected-warning{{expansion of predefined identifier '__FUNCDNAME__' to a string literal is a Microsoft extension}}
91 ASSERT_EQ(__FUNCSIG__
" right", "void __cdecl test_concat(void) right"); // expected-warning{{expansion of predefined identifier '__FUNCSIG__' to a string literal is a Microsoft extension}}
93 ASSERT_EQ("left_" __FUNCTION__
"_right", "left_test_concat_right"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
94 ASSERT_EQ("left_" __FUNCDNAME__
"_right", "left_test_concat_right"); // expected-warning{{expansion of predefined identifier '__FUNCDNAME__' to a string literal is a Microsoft extension}}
95 ASSERT_EQ("left " __FUNCSIG__
" right", "left void __cdecl test_concat(void) right"); // expected-warning{{expansion of predefined identifier '__FUNCSIG__' to a string literal is a Microsoft extension}}
97 ASSERT_EQ(__FUNCTION__
"/" __FUNCSIG__
, "test_concat/void __cdecl test_concat(void)"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}} \
98 // expected-warning{{expansion of predefined identifier '__FUNCSIG__' to a string literal is a Microsoft extension}}
101 extern "C" void test_wide_concat() {
103 ASSERT_EQ(L
"" __FUNCTION__
, L__FUNCTION__
); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
104 ASSERT_EQ(L
"" __FUNCSIG__
, L__FUNCSIG__
); // expected-warning{{expansion of predefined identifier '__FUNCSIG__' to a string literal is a Microsoft extension}}
107 ASSERT_EQ(L__FUNCTION__
, L__FUNCTION__
""); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}}
108 ASSERT_EQ(L__FUNCSIG__
, L__FUNCSIG__
""); // expected-warning{{expansion of predefined identifier 'L__FUNCSIG__' to a string literal is a Microsoft extension}}
110 ASSERT_EQ(L
"left_" L__FUNCTION__
, L
"left_test_wide_concat"); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}}
111 ASSERT_EQ(L
"left " L__FUNCSIG__
, L
"left void __cdecl test_wide_concat(void)"); // expected-warning{{expansion of predefined identifier 'L__FUNCSIG__' to a string literal is a Microsoft extension}}
113 ASSERT_EQ(L__FUNCTION__ L
"_right", L
"test_wide_concat_right"); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}}
114 ASSERT_EQ(L__FUNCSIG__ L
" right", L
"void __cdecl test_wide_concat(void) right"); // expected-warning{{expansion of predefined identifier 'L__FUNCSIG__' to a string literal is a Microsoft extension}}
116 ASSERT_EQ(L
"left_" L__FUNCTION__ L
"_right", L
"left_test_wide_concat_right"); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}}
117 ASSERT_EQ(L
"left " L__FUNCSIG__ L
" right", L
"left void __cdecl test_wide_concat(void) right"); // expected-warning{{expansion of predefined identifier 'L__FUNCSIG__' to a string literal is a Microsoft extension}}
119 ASSERT_EQ(L__FUNCTION__ L
"/" L__FUNCSIG__
, L
"test_wide_concat/void __cdecl test_wide_concat(void)"); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}} \
120 // expected-warning{{expansion of predefined identifier 'L__FUNCSIG__' to a string literal is a Microsoft extension}}
123 void test_encoding() {
124 ASSERT_EQ_TY("" __FUNCTION__
, ""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
125 ASSERT_EQ_TY(L
"" __FUNCTION__
, L
""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
126 ASSERT_EQ_TY(L
"" L__FUNCTION__
, L
""); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}}
127 ASSERT_EQ_TY("" L__FUNCTION__
, L
""); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}}
128 ASSERT_EQ_TY(u8
"" __FUNCTION__
, u8
""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
129 ASSERT_EQ_TY(u
"" __FUNCTION__
, u
""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
130 ASSERT_EQ_TY(U
"" __FUNCTION__
, U
""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
132 ASSERT_EQ_TY(__FUNCTION__ L
"", L
""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
133 ASSERT_EQ_TY(__FUNCTION__ u8
"", u8
""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
134 ASSERT_EQ_TY(__FUNCTION__ u
"", u
""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
135 ASSERT_EQ_TY(__FUNCTION__ U
"", U
""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
138 extern "C" void test_𐀀
() {
139 ASSERT_EQ(U
"" __FUNCTION__
, U
"test_𐀀"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
140 ASSERT_EQ(u
"" __FUNCTION__
, u
"test_𐀀"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
141 ASSERT_EQ(u8
"" __FUNCTION__
, u8
"test_𐀀"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
147 void test_invalid_encoding() {
148 unused(u8
"" L__FUNCTION__
); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}} \
149 // expected-error{{unsupported non-standard concatenation of string literals}}
150 unused(u
"" L__FUNCTION__
); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}} \
151 // expected-error{{unsupported non-standard concatenation of string literals}}
152 unused(U
"" L__FUNCTION__
); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}} \
153 // expected-error{{unsupported non-standard concatenation of string literals}}
156 constexpr size_t operator""_len(const char*, size_t len
) {
160 void test_udliteral() {
161 static_assert(__FUNCTION__
""_len
== 14, ""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
164 void test_static_assert() {
165 static_assert(true, __FUNCTION__
); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
168 void test_char_injection(decltype(sizeof('"')), decltype(sizeof("()"))) {
169 unused("" __FUNCSIG__
); // expected-warning{{expansion of predefined identifier '__FUNCSIG__' to a string literal is a Microsoft extension}}
172 void test_in_struct_init() {
174 char F
[sizeof(__FUNCTION__
)];
175 } s1
= { __FUNCTION__
}; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
178 char F
[sizeof("F:" __FUNCTION__
)]; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
179 } s2
= { "F:" __FUNCTION__
}; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
184 char F
[sizeof(__FUNCTION__
)];
186 } c1
= { { __FUNCTION__
} }; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
189 void test_in_constexpr_struct_init() {
191 char F
[sizeof(__FUNCTION__
)];
192 } constexpr s1
= { __FUNCTION__
}; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
193 ASSERT_EQ(__FUNCTION__
, s1
.F
);
196 char F
[sizeof("F:" __FUNCTION__
)]; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
197 } constexpr s2
= { "F:" __FUNCTION__
}; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
198 ASSERT_EQ("F:" __FUNCTION__
, s2
.F
); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
203 char F
[sizeof("F:" __FUNCTION__
)]; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
205 } constexpr c1
= { { "F:" __FUNCTION__
} }; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
206 ASSERT_EQ("F:" __FUNCTION__
, c1
.s
.F
); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}