public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/67033] New: [c++11] template argument invalid for integral constant expression beginning with address-of expression
@ 2015-07-27 20:36 ed at catmur dot co.uk
2015-07-27 20:55 ` [Bug c++/67033] " ed at catmur dot co.uk
2021-07-29 21:06 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: ed at catmur dot co.uk @ 2015-07-27 20:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67033
Bug ID: 67033
Summary: [c++11] template argument invalid for integral
constant expression beginning with address-of
expression
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ed at catmur dot co.uk
Target Milestone: ---
template<bool B> struct S { };
int x;
S<&x == &x> s;
// error: template argument 1 is invalid
// ^
&x == &x is a valid converted constant expression of type bool.
The problem is that cp_parser_template_argument sees the initial '&' and
decides that the non-type template argument must be the address-of operator
applied to an id-expression; when it fails to reach the end of the template
argument it aborts.
This behavior is valid for <= C++03, where '&' cannot appear in a constant
expression, but C++11 is more relaxed.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/67033] [c++11] template argument invalid for integral constant expression beginning with address-of expression
2015-07-27 20:36 [Bug c++/67033] New: [c++11] template argument invalid for integral constant expression beginning with address-of expression ed at catmur dot co.uk
@ 2015-07-27 20:55 ` ed at catmur dot co.uk
2021-07-29 21:06 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: ed at catmur dot co.uk @ 2015-07-27 20:55 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/67033] [c++11] template argument invalid for integral constant expression beginning with address-of expression
2015-07-27 20:36 [Bug c++/67033] New: [c++11] template argument invalid for integral constant expression beginning with address-of expression ed at catmur dot co.uk
2015-07-27 20:55 ` [Bug c++/67033] " ed at catmur dot co.uk
@ 2021-07-29 21:06 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-29 21:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67033
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Target Milestone|--- |6.0
Resolution|--- |FIXED
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(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<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
GCC 6+ does the correct thing for the testcase in comment #1 so closing.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-29 21:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-27 20:36 [Bug c++/67033] New: [c++11] template argument invalid for integral constant expression beginning with address-of expression ed at catmur dot co.uk
2015-07-27 20:55 ` [Bug c++/67033] " ed at catmur dot co.uk
2021-07-29 21:06 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).