|
| 1 | +// #scratch_space |
1 | 2 | // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -Wformat-pedantic -fblocks %s |
2 | 3 | // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -fblocks -std=c++98 %s |
3 | 4 | // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -Wformat-pedantic -fblocks -std=c++11 %s |
4 | 5 | // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -Wformat-pedantic -fblocks -std=c++20 %s |
5 | | - |
6 | | -#if __cplusplus >= 202000l |
7 | | -// expected-note@-6{{format string computed from non-literal expression}} |
8 | | -// ^^^ there will be a <scratch space> SourceLocation caused by the |
9 | | -// test_constexpr_string test, that -verify treats as if it showed up at |
10 | | -// line 1 of this file. |
11 | | -#endif |
| 6 | +// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -Wformat-pedantic -fblocks -std=c++23 %s |
12 | 7 |
|
13 | 8 | #include <stdarg.h> |
14 | 9 |
|
@@ -310,5 +305,26 @@ constexpr my_string const_string() { |
310 | 305 | void test_constexpr_string() { |
311 | 306 | printf(const_string().c_str(), "hello", 123); // no-warning |
312 | 307 | printf(const_string().c_str(), 123, 456); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}} |
| 308 | + // expected-note@#scratch_space {{format string computed from non-literal expression}} |
| 309 | +} |
| 310 | +#endif |
| 311 | + |
| 312 | +#if __cplusplus >= 202300L |
| 313 | +constexpr const char *consteval_str() { |
| 314 | + if consteval { |
| 315 | + return "%s"; |
| 316 | + } else { |
| 317 | + return "%d"; // expected-note 2{{format string is defined here}} |
| 318 | + } |
| 319 | +} |
| 320 | + |
| 321 | +constexpr const char *consteval_str_global = consteval_str(); |
| 322 | + |
| 323 | +void test_consteval_str() { |
| 324 | + printf(consteval_str(), 789); // no-warning |
| 325 | + printf(consteval_str(), "hello"); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}} |
| 326 | + |
| 327 | + printf(consteval_str_global, 1234); // no-warning |
| 328 | + printf(consteval_str_global, "hello"); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}} |
313 | 329 | } |
314 | 330 | #endif |
0 commit comments