Warning for ODR violation #23533
Labels
bugzilla
Issues migrated from bugzilla
c++
clang:diagnostics
New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Extended Description
Richard provided to me this example showing ODR violation:
#include
// implicitly internal linkage due to 'const'
const int n = 5;
// odr violation, captures n by reference
inline auto f() { return std::make_pair(n, 3); }
// much more obvious odr violation, takes address of n
inline auto g() {
static const int *p = &n;
return p;
}
Clang compiles this, however, without issuing any warnings. Taking the address of a variable with internal linkage in an inline function is probably not a good idea.
The text was updated successfully, but these errors were encountered: