According to current C++0x draft 14.3.2 [temp.arg.nontype], template non-type arguments can be a constant expression that evaluates to a null pointer value or null member pointer value. This change was made in n1905. So the following code is well-formed. template < void * = nullptr > void f() { } int main() { f() ; f<nullptr>() ; f<0>() ; constexpr void * ptr = nullptr ; f<ptr>() ; } But current gcc does not accept it. Or is this just unimplemented feature?
Current C++0x draft 14.3.2/5 says 0 is not a valid template-argument for a non-type template-parameter of pointer type. So, `f<0>();' is ill-formed, as current gcc rejects it. But 14.3.2/5 says both `(void*)0' and `nullptr' are valid, so the other codes should be accepted.
Author: jason Date: Sun Aug 28 15:38:29 2011 New Revision: 178144 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178144 Log: Core DR 342 PR c++/48582 * pt.c (check_valid_ptrmem_cst_expr): A null member pointer value is valid in C++11. (convert_nontype_argument): Likewise. Implicitly convert nullptr and do constant folding. * mangle.c (write_template_arg_literal): Mangle null member pointer values as 0. * call.c (null_member_pointer_value_p): New. * cp-tree.h: Declare it. Added: trunk/gcc/testsuite/g++.dg/abi/mangle50.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/call.c trunk/gcc/cp/cp-tree.h trunk/gcc/cp/mangle.c trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog
Implemented for 4.7.