Can not-const nullptr_t variable be a template non-type argument?
17:10 30 Jan 2026

Can one use a not const variable with nullptr value as a non-type argument of some template?

For example:

template
int v = 0;

int main() {
    auto nil = nullptr;
    return v;
} 

I see that the program is accepted by both GCC and Clang. But other compilers do not agree.

MSVC:

error C2971: 'v': template parameter 'P': 'nil': a variable with non-static storage duration cannot be used as a non-type argument

EDG:

error: argument of type "std::nullptr_t" is incompatible with template parameter of type "int *"

Even if I write template int v = 0; EDG still dislikes it:

error: expression must have a constant value

Online demo

Which implementation is correct?

c++ templates language-lawyer nullptr non-type-template-parameter