[Bug c++/67033] [c++11] template argument invalid for integral constant expression beginning with address-of expression
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67033 Andrew Pinski changed: What|Removed |Added Status|NEW |RESOLVED Target Milestone|--- |6.0 Resolution|--- |FIXED --- Comment #3 from Andrew Pinski --- (In reply to Marek Polacek from comment #2) > Confirmed. > > Testcase from PR56428: This is a different issue overall related to PMF rather than to addresses, I filed PR 101681 for that. (In reply to Ed Catmur from comment #1) > template class X {}; > int i; > X<&i> x1; // OK > X<(&(i))> x2; // OK since C++11 > template class Y : X {}; // OK since C++11 if !b > X x3; // OK since C++1z GCC 6+ does the correct thing for the testcase in comment #1 so closing.
[Bug c++/67033] [c++11] template argument invalid for integral constant expression beginning with address-of expression
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67033 Marek Polacek changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2019-08-02 CC||mpolacek at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #2 from Marek Polacek --- Confirmed. Testcase from PR56428: template struct Z { }; struct C { void f(); Z<&C::f == nullptr> z; };
[Bug c++/67033] [c++11] template argument invalid for integral constant expression beginning with address-of expression
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67033 --- Comment #1 from Ed Catmur --- 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 class X {}; int i; X<&i> x1; // OK X<(&(i))> x2; // OK since C++11 template class Y : X {}; // OK since C++11 if !b X 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.