[Bug c++/67033] [c++11] template argument invalid for integral constant expression beginning with address-of expression
ed at catmur dot co.uk
gcc-bugzilla@gcc.gnu.org
Mon Jul 27 20:55:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67033
--- Comment #1 from Ed Catmur <ed at catmur dot co.uk> ---
Created attachment 36075
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36075&action=edit
pr67033.patch
This is kinda ugly.
The problem is that before C++1z, a non-type template argument that evaluates
to the address of or a reference to an object [...] must be expressed as "&
id-expression" [...]; this means that the parser isn't really the place for
this, as the validity of the expression depends on its value:
template<int* p> class X {};
int i;
X<&i> x1; // OK
X<(&(i))> x2; // OK since C++11
template<bool b> class Y : X<b ? &i : nullptr> {}; // OK since C++11 if !b
X<true ? &i : nullptr> x3; // OK since C++1z
The attached patch lets through quite a lot of constructs that are actually
invalid pre-C++1z. A rigorous check would be to annotate the constant
expression to say whether it matches the form allowed in [temp.arg.nontype] and
then on evaluation check whether it is a null pointer constant.
More information about the Gcc-bugs
mailing list