1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
// RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
// RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions -fexperimental-new-constant-interpreter
using size_t = __SIZE_TYPE__;
// Test array initialization
void array_init() {
const char a[] = __FUNCTION__; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
const char b[] = __FUNCDNAME__; // expected-warning{{initializing an array from a '__FUNCDNAME__' predefined identifier is a Microsoft extension}}
const char c[] = __FUNCSIG__; // expected-warning{{initializing an array from a '__FUNCSIG__' predefined identifier is a Microsoft extension}}
const char d[] = __func__; // expected-warning{{initializing an array from a '__func__' predefined identifier is a Microsoft extension}}
const char e[] = __PRETTY_FUNCTION__; // expected-warning{{initializing an array from a '__PRETTY_FUNCTION__' predefined identifier is a Microsoft extension}}
const wchar_t f[] = L__FUNCTION__; // expected-warning{{initializing an array from a 'L__FUNCTION__' predefined identifier is a Microsoft extension}}
const wchar_t g[] = L__FUNCSIG__; // expected-warning{{initializing an array from a 'L__FUNCSIG__' predefined identifier is a Microsoft extension}}
}
// Test function local identifiers outside of a function
const char* g_function = __FUNCTION__; // expected-warning{{predefined identifier is only valid inside function}}
const char* g_function_lconcat = "" __FUNCTION__; // expected-warning{{predefined identifier is only valid inside function}} \
// expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
const char* g_function_rconcat = __FUNCTION__ ""; // expected-warning{{predefined identifier is only valid inside function}} \
// expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
namespace NS
{
const char* function = __FUNCTION__; // expected-warning{{predefined identifier is only valid inside function}}
const char* function_lconcat = "" __FUNCTION__; // expected-warning{{predefined identifier is only valid inside function}} \
// expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
const char* function_rconcat = __FUNCTION__ ""; // expected-warning{{predefined identifier is only valid inside function}} \
// expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
struct S
{
static constexpr const char* function = __FUNCTION__; // expected-warning{{predefined identifier is only valid inside function}}
static constexpr const char* function_lconcat = "" __FUNCTION__; // expected-warning{{predefined identifier is only valid inside function}} \
// expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
static constexpr const char* function_rconcat = __FUNCTION__ ""; // expected-warning{{predefined identifier is only valid inside function}} \
// expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
};
}
template<class T, class U>
constexpr bool is_same = false;
template<class T>
constexpr bool is_same<T, T> = true;
template<typename T, size_t N>
constexpr bool equal(const T (&a)[N], const T (&b)[N]) {
for (size_t i = 0; i < N; i++)
if (a[i] != b[i])
return false;
return true;
}
#define ASSERT_EQ(X, Y) static_assert(equal(X, Y), "")
#define ASSERT_EQ_TY(X, Y) static_assert(is_same<decltype((X)[0]), decltype((Y)[0])>, "")
#define _WIDE(s) L##s
#define WIDE(s) _WIDE(s)
// Test value
extern "C" void test_value() {
ASSERT_EQ(__FUNCTION__, "test_value");
ASSERT_EQ(__FUNCSIG__, "void __cdecl test_value(void)");
ASSERT_EQ(WIDE(__FUNCTION__), L"test_value");
ASSERT_EQ(WIDE(__FUNCSIG__), L"void __cdecl test_value(void)");
}
namespace PR13206 {
template<class T> class A {
public:
void method() {
ASSERT_EQ(L__FUNCTION__, L"method");
}
};
void test_template_value() {
A<int> x;
x.method();
}
}
// Test concatenation
extern "C" void test_concat() {
ASSERT_EQ("left_" __FUNCTION__, "left_test_concat"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ("left_" __FUNCDNAME__, "left_test_concat"); // expected-warning{{expansion of predefined identifier '__FUNCDNAME__' to a string literal is a Microsoft extension}}
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}}
ASSERT_EQ(__FUNCTION__ "_right", "test_concat_right"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ(__FUNCDNAME__ "_right", "test_concat_right"); // expected-warning{{expansion of predefined identifier '__FUNCDNAME__' to a string literal is a Microsoft extension}}
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}}
ASSERT_EQ("left_" __FUNCTION__ "_right", "left_test_concat_right"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ("left_" __FUNCDNAME__ "_right", "left_test_concat_right"); // expected-warning{{expansion of predefined identifier '__FUNCDNAME__' to a string literal is a Microsoft extension}}
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}}
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}} \
// expected-warning{{expansion of predefined identifier '__FUNCSIG__' to a string literal is a Microsoft extension}}
}
extern "C" void test_wide_concat() {
// test L"" + ""
ASSERT_EQ(L"" __FUNCTION__, L__FUNCTION__); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ(L"" __FUNCSIG__, L__FUNCSIG__); // expected-warning{{expansion of predefined identifier '__FUNCSIG__' to a string literal is a Microsoft extension}}
// test Lx + ""
ASSERT_EQ(L__FUNCTION__, L__FUNCTION__ ""); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ(L__FUNCSIG__, L__FUNCSIG__ ""); // expected-warning{{expansion of predefined identifier 'L__FUNCSIG__' to a string literal is a Microsoft extension}}
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}}
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}}
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}}
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}}
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}}
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}}
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}} \
// expected-warning{{expansion of predefined identifier 'L__FUNCSIG__' to a string literal is a Microsoft extension}}
}
void test_encoding() {
ASSERT_EQ_TY("" __FUNCTION__, ""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ_TY(L"" __FUNCTION__, L""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ_TY(L"" L__FUNCTION__, L""); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ_TY("" L__FUNCTION__, L""); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ_TY(u8"" __FUNCTION__, u8""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ_TY(u"" __FUNCTION__, u""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ_TY(U"" __FUNCTION__, U""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
//
ASSERT_EQ_TY(__FUNCTION__ L"", L""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ_TY(__FUNCTION__ u8"", u8""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ_TY(__FUNCTION__ u"", u""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ_TY(__FUNCTION__ U"", U""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
}
extern "C" void test_𐀀() {
ASSERT_EQ(U"" __FUNCTION__, U"test_𐀀"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ(u"" __FUNCTION__, u"test_𐀀"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ(u8"" __FUNCTION__, u8"test_𐀀"); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
}
template<typename T>
void unused(T);
void test_invalid_encoding() {
unused(u8"" L__FUNCTION__); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}} \
// expected-error{{unsupported non-standard concatenation of string literals}}
unused(u"" L__FUNCTION__); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}} \
// expected-error{{unsupported non-standard concatenation of string literals}}
unused(U"" L__FUNCTION__); // expected-warning{{expansion of predefined identifier 'L__FUNCTION__' to a string literal is a Microsoft extension}} \
// expected-error{{unsupported non-standard concatenation of string literals}}
}
constexpr size_t operator""_len(const char*, size_t len) {
return len;
}
void test_udliteral() {
static_assert(__FUNCTION__ ""_len == 14, ""); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
}
void test_static_assert() {
static_assert(true, __FUNCTION__); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
}
void test_char_injection(decltype(sizeof('"')), decltype(sizeof("()"))) {
unused("" __FUNCSIG__); // expected-warning{{expansion of predefined identifier '__FUNCSIG__' to a string literal is a Microsoft extension}}
}
void test_in_struct_init() {
struct {
char F[sizeof(__FUNCTION__)];
} s1 = { __FUNCTION__ }; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
struct {
char F[sizeof("F:" __FUNCTION__)]; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
} s2 = { "F:" __FUNCTION__ }; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
class C {
public:
struct {
char F[sizeof(__FUNCTION__)];
} s;
} c1 = { { __FUNCTION__ } }; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
}
void test_in_constexpr_struct_init() {
struct {
char F[sizeof(__FUNCTION__)];
} constexpr s1 = { __FUNCTION__ }; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
ASSERT_EQ(__FUNCTION__, s1.F);
struct {
char F[sizeof("F:" __FUNCTION__)]; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
} constexpr s2 = { "F:" __FUNCTION__ }; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ("F:" __FUNCTION__, s2.F); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
class C {
public:
struct {
char F[sizeof("F:" __FUNCTION__)]; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
} s;
} constexpr c1 = { { "F:" __FUNCTION__ } }; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
ASSERT_EQ("F:" __FUNCTION__, c1.s.F); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
}
|