This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-12-20
[Voted into WP at October 2005 meeting.]
The standard does not permit a null value to be used as a nontype templateargument for a nontype template parameter that is a pointer.
This code is accepted by EDG, Microsoft, Borland and Cfront, but rejectedby g++ and Sun:
template <int *p> struct A {}; A<(int*)0> ai;I'm not sure this was ever explicitly considered by the committee.Is there any reason to permit this kind of usage?
Jason Merrill:I suppose it might be useful for a program to be able to express adegenerate case using a null template argument. I think allowing it wouldbe harmless.
Notes from October 2004 meeting:
CWG decided that it would be desirable to allow null pointersas nontype template arguments, even though they are notrepresentable in some current ABIs. There was some discussionover whether to allow a bare0 to be used with a pointernontype template parameter. The following case was decisive:
template<int i> void foo(); template<int* i> void foo(); ... foo<0>();
The current wording of 13.4 [temp.arg] paragraph 7disambiguates the function call in favor of theintversion. If the null pointer conversion were allowed for pointernontype template parameters, this case would become ambiguous, soit was decided to require a cast.
Proposed resolution (April, 2005):
In 13.4.3 [temp.arg.nontype] paragraph 1, insert thefollowing after the third bullet:
Add the indicated text to the note in the second bullet of13.4.3 [temp.arg.nontype] paragraph 5:
[Note: In particular, neither the null pointer conversion(7.3.12 [conv.ptr]) nor the derived-to-base conversion(7.3.12 [conv.ptr]) are applied. Although0 is a validtemplate-argument for a non-typetemplate-parameter of integraltype, it is not a validtemplate-argument for a non-typetemplate-parameter of pointer type.However,(int*)0 is a validtemplate-argument for a non-typetemplate-parameter of type“pointer to int.” —end note]
Replace the normative wording of 13.6 [temp.type] paragraph 1 with the following:
Twotemplate-ids refer to the same class or functionif
- theirtemplate-names refer to the same template, and
- their corresponding typetemplate-arguments are thesame type, and
- their corresponding non-typetemplate-arguments ofintegral or enumeration type have identical values, and
- their corresponding non-typetemplate-arguments ofpointer type refer to the same external object or function or areboth the null pointer value, and
- their corresponding non-typetemplate-arguments ofpointer-to-member type refer to the same class member or are boththe null member pointer value, and
- their corresponding non-typetemplate-argumentss fortemplate parameters of reference type refer to the same externalobject or function, and
- their corresponding templatetemplate-arguments referto the same template.