Bug 48582 - [C++0x] [DR 342] Template non-type arguments doesn't accept null pointer constant value
Summary: [C++0x] [DR 342] Template non-type arguments doesn't accept null pointer cons...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.7.0
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-04-12 20:33 UTC by Ryou Ezoe
Modified: 2011-08-28 15:39 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-08-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryou Ezoe 2011-04-12 20:33:25 UTC
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?
Comment 1 Takaya Saito 2011-08-25 20:09:49 UTC
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.
Comment 2 Jason Merrill 2011-08-28 15:38:33 UTC
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
Comment 3 Jason Merrill 2011-08-28 15:39:14 UTC
Implemented for 4.7.