https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105885
Bug ID: 105885
Summary: [Regression]: Spurious warning: "the address of [...]
will never be NULL [-Waddress]" with const char*
template argument
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
The following with -std=c++20 -Waddress:
#include <iostream>
template<const char* ARG = nullptr>
void test() {
if constexpr(ARG == nullptr) {
std::cout << "Nullptr!!" << std::endl;
} else {
std::cout << ARG << "heh" << std::endl;
}
}
const char CONSTSTR[] = {'\n', '\t', ' ', '\0'};
int main() {
test();
test<CONSTSTR>();
}
gives a spurious/pointless warning:
<source>: In instantiation of 'void test() [with const char* ARG = (&
CONSTSTR)]':
<source>:16:19: required from here
<source>:5:22: warning: the address of 'CONSTSTR' will never be NULL
[-Waddress]
5 | if constexpr(ARG == nullptr) {
| ~~~~^~~~~~~~~~
<source>:12:12: note: 'CONSTSTR' declared here
12 | const char CONSTSTR[] = {'\n', '\t', ' ', '\0'};
| ^~~~~~~~
ASM generation compiler returned: 0
<source>: In instantiation of 'void test() [with const char* ARG = (&
CONSTSTR)]':
<source>:16:19: required from here
<source>:5:22: warning: the address of 'CONSTSTR' will never be NULL
[-Waddress]
5 | if constexpr(ARG == nullptr) {
| ~~~~^~~~~~~~~~
<source>:12:12: note: 'CONSTSTR' declared here
12 | const char CONSTSTR[] = {'\n', '\t', ' ', '\0'};
Clang doesn't produce a warning for this case.
Potentially very similar to: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94554