I am analyzing a codebase with clang-tidy and see a warning I do not understand. The warning is invoked by the following lines of code:
void fun(const QString& bar) {
const char* c_format = bar.toStdString().c_str();
expand_some_macro(c_format);
}
c_format
is passed around in the expanded macro which reads as follows:
#define expand_some_macro(c_format)\
char buffer[MAX_SIZE];\
va_list args;\
va_start(args, c_format);\
vsnprintf(buffer, MAX_SIZE, _TRUNCATE, c_format, args);\
va_end(args);
which includes function calls from the shlobj
header that I do not understand at this point. The clang-tidy
generates the following warning:
warning: object backing the pointer will be destroyed at the end of the full-expression [clang-diagnostic-dangling-gsl]
I browsed the web, in particular the c++ core guidelines, in an attempt to educate myself about this warning but could not find a proper reference. This lead me to two sets of questions:
- What is a reference for this warning? Where can I learn about this an similar warnings?
- What might be wrong with the code above? Do I need to call
delete[] c_format
at the end of the scope?