Clang warning: passing object of class type A through variadic ...... [-Wclass-varargs] (warn_pass_class_arg_to_vararg)
Jump to navigation
Jump to search
Text |
| ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Type | Warning | ||||||||||
Category | Semantic Issue | ||||||||||
Internal Id | warn_pass_class_arg_to_vararg | ||||||||||
Active by Default | No | ||||||||||
Flags | -Wclass-varargs (5 elements) | ||||||||||
Internal Message | passing object of class type %0 through variadic %select{function|block|method|constructor}1%select{|; did you mean to call '%3'?}2
| ||||||||||
Regular Expression | (?:warning|error|fatal error)\: passing object of class type (.*?) through variadic (?:function|block|method|constructor)(?:|; did you mean to call '(.*?)'\?) \[(?:\-Werror,)?\-Wclass\-varargs[^\]]*\]
| ||||||||||
First Commit | 2014-02-28 2868a736f88e Add a -Wclass-varargs to warn on objects of any class type being passed through an ellipsis. Since C... |
Description
Example
Flags | -xc++ -Wclass-varargs
|
|
---|---|---|
Source |
#include <stdio.h>
class C {
public:
C() {}
void print() const { printf("C instance\n"); }
};
void f(const char *s, ...) {}
int main() {
C v;
f("%s", v); // MyClass passed to variadic function
return 0;
}
| |
Compiler Output |
<source>:13:11: warning: passing object of class type 'C' through variadic function [-Wclass-varargs] |
Clang Internals (17.0.6)
Git Commit Message
Add a -Wclass-varargs to warn on objects of any class type being passed through an ellipsis. Since C++11 relaxed the rules on this, we allow a lot more bad code through silently, such as: const char *format = "%s"; std::experimental::string_view view = "foo"; printf(format, view); In this case, not only warn about a class type being used here, but also suggest that calling c_str() might be a good idea. llvm-svn: 202461
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaExpr.cpp (line 1004)
void Sema::checkVariadicArgument(const Expr *E, VariadicCallType CT) {
// ...
case VAK_Valid:
if (Ty->isRecordType()) {
// ...
DiagRuntimeBehavior(E->getBeginLoc(), nullptr, PDiag(diag::warn_pass_class_arg_to_vararg) << Ty << CT << hasCStrMethod(E) << ".c_str()");
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/SemaCXX/vararg-class.cpp
- clang/test/SemaCXX/vararg-class.cpp:15:5: warning: passing object of class type 'A' through variadic function [-Wclass-varargs]
- clang/test/SemaCXX/vararg-class.cpp:17:5: warning: passing object of class type 'C' through variadic function; did you mean to call '.c_str()'? [-Wclass-varargs]
- clang/test/SemaCXX/vararg-class.cpp:18:5: warning: passing object of class type 'D' through variadic function; did you mean to call '.c_str()'? [-Wclass-varargs]
- clang/test/SemaCXX/vararg-class.cpp:19:5: warning: passing object of class type 'E' through variadic function [-Wclass-varargs]
- clang/test/SemaCXX/vararg-class.cpp:20:5: warning: passing object of class type 'F' through variadic function; did you mean to call '.c_str()'? [-Wclass-varargs]