[clang] [Sema] Fix parameter index checks on explicit object member functions (PR #165586)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 29 21:59:20 PDT 2025
================
@@ -11,13 +11,16 @@ struct S {
// the format argument is argument 2 here.
void g(const char*, ...) __attribute__((format(printf, 2, 3)));
const char* g2(const char*) __attribute__((format_arg(2)));
+ void g3(this S&, const char *, ...) __attribute__((format(printf, 2, 3)));
void h(const char*, ...) __attribute__((format(printf, 1, 4))); // \
expected-error{{implicit this argument as the format string}}
void h2(const char*, ...) __attribute__((format(printf, 2, 1))); // \
expected-error{{out of bounds}}
const char* h3(const char*) __attribute__((format_arg(1))); // \
expected-error{{invalid for the implicit this argument}}
+ void h4(this S&, const char *, ...) __attribute__((format(printf, 1, 3))); // \
+ expected-error {{format argument not a string type}}
----------------
Sirraide wrote:
Can you add this as a test to make sure we actually emit the diagnostics correctly?
```c++
struct S {
__attribute__((format(printf, 1, 2))) void f(this const char* s, ...);
consteval operator const char*() const { return "%f"; }
};
void f() {
S().f(4); // Should warn about us passing an 'int' instead of a 'double'.
}
```
https://github.com/llvm/llvm-project/pull/165586
More information about the cfe-commits
mailing list