https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96543
Bug ID: 96543
Summary: null check on template pointer parameter fails
Product: gcc
Version: 10.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: vlad at petric dot cc
Target Milestone: ---
static unsigned c = 0;
template <unsigned* c>
struct A {
static void test() {
if constexpr (c) ++ *c;
}
};
int main() {
A<&c>::test();
A<nullptr>::test();
}
The error is:
bug.cc: In instantiation of ‘static void A<c>::test() [with unsigned int* c =
(& c)]’:
bug.cc:11:10: required from here
bug.cc:11:5: error: the address of ‘c’ will never be NULL [-Werror=address]
11 | A<&c>::test();
The only fix is to remove the if constexpr (nothing else helps).