1- // RUN: %clang_cc1 -fsyntax-only -Wformat-nonliteral -verify %s
1+ // RUN: %clang_cc1 -fsyntax-only -std=c++23 - Wformat-nonliteral -verify %s
22#include < stdarg.h>
33
44int printf (const char *fmt, ...) __attribute__((format(printf, 1 , 2 )));
@@ -11,17 +11,28 @@ struct S {
1111 // the format argument is argument 2 here.
1212 void g (const char *, ...) __attribute__((format(printf, 2 , 3 )));
1313 const char * g2 (const char *) __attribute__((format_arg(2 )));
14+ // From C++23 'this' can also be specified explicitly.
15+ void g3 (this S&, const char *, ...) __attribute__((format(printf, 2 , 3 )));
16+ void g4 (this const char * s, ...) __attribute__((format(printf, 1 , 2 )));
17+ consteval operator const char *() const { return " %f" ; } // #g4_fmt_string
1418
1519 void h (const char *, ...) __attribute__((format(printf, 1 , 4 ))); // \
1620 expected-error{{implicit this argument as the format string}}
1721 void h2 (const char *, ...) __attribute__((format(printf, 2 , 1 ))); // \
1822 expected-error{{out of bounds}}
1923 const char * h3 (const char *) __attribute__((format_arg(1 ))); // \
2024 expected-error{{invalid for the implicit this argument}}
25+ void h4 (this S&, const char *, ...) __attribute__((format(printf, 1 , 3 ))); // \
26+ expected-error {{format argument not a string type}}
2127
2228 void operator () (const char *, ...) __attribute__((format(printf, 2 , 3 )));
2329};
2430
31+ void s () {
32+ S ().g4 (4 ); // expected-warning {{format specifies type 'double' but the argument has type 'int'}}
33+ // expected-note@#g4_fmt_string {{format string is defined here}}
34+ }
35+
2536// PR5521
2637struct A { void a (const char *,...) __attribute((format(printf,2 ,3 ))); };
2738void b (A x) {
0 commit comments