public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98804] New: GCC misparses template in pack expansion as comparison
@ 2021-01-23 16:01 foom at fuhm dot net
2021-01-24 20:33 ` [Bug c++/98804] " richard-gccbugzilla at metafoo dot co.uk
2021-02-12 4:38 ` mpolacek at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: foom at fuhm dot net @ 2021-01-23 16:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98804
Bug ID: 98804
Summary: GCC misparses template in pack expansion as comparison
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: foom at fuhm dot net
CC: richard-gccbugzilla at metafoo dot co.uk
Target Milestone: ---
GCC parses the following program (by Richard Smith) as `g` less-than `a`
greater-than `(a)` instead of a call to the function `g` with template-args
`a`, and argument-list `(a)`. And thus, it fails to compile.
(Compile with -std=c++20)
----
struct X { constexpr X(int&) {} };
template<class F> void g(F);
template<X> void g(int);
void g(...);
template<class ...A> auto h(A ...a)->decltype (g (0, g < a > (a) ...)) {
}
void test () {
h(0);
}
-----
I originally noticed this bug with the following test from Clang's test-suite,
while working on a mangling bug in Clang. In this original test-case, GCC does
successfully compile, but the mangling is weird, exposing that the same
misparse occurred.
----
namespace pr30440 {
template<class F> void g(F);
template<class ...A> auto h(A ...a)->decltype (g (0, g < a > (a) ...)) {
}
void pr30440_test () {
h();
}
}
----
GCC mangles as:
_ZN7pr304401hIJEEEDTcl1gLi0Espgtlt1gfp_fp_EEDpT_
^^^^
with greater/less operators in the mangling.
But it should've been:
_ZN7pr304401hIJEEEDTcl1gLi0Espcl1gIXfp_EEfp_EEEDpT_
^^^^^^^
with a template-arg.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/98804] GCC misparses template in pack expansion as comparison
2021-01-23 16:01 [Bug c++/98804] New: GCC misparses template in pack expansion as comparison foom at fuhm dot net
@ 2021-01-24 20:33 ` richard-gccbugzilla at metafoo dot co.uk
2021-02-12 4:38 ` mpolacek at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2021-01-24 20:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98804
--- Comment #1 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
Somewhat more reduced:
struct X { constexpr X(int&) {} };
template<X> struct Y {};
int a;
auto h(int b) -> Y<a>; // #1
auto h(int b) -> Y<b>; // #2
GCC accepts #1, but for #2 it produces seven (!) error messages:
<source>:6:21: error: template argument 1 is invalid
6 | auto h(int b) -> Y<b>;
| ^
<source>:6:21: error: template argument 1 is invalid
<source>:6:21: error: template argument 1 is invalid
<source>:6:21: error: template argument 1 is invalid
<source>:6:18: error: invalid template-id
6 | auto h(int b) -> Y<b>;
| ^
<source>:6:21: error: use of parameter outside function body before '>' token
6 | auto h(int b) -> Y<b>;
| ^
<source>:6:6: error: deduced class type 'Y' in function return type
6 | auto h(int b) -> Y<b>;
| ^
<source>:2:20: note: 'template<X <anonymous> > struct Y' declared here
2 | template<X> struct Y {};
| ^
As far as I'm aware, both #1 and #2 are valid. (I think the "use of parameter
outside function body" restriction is referring to [dcl.fct.default]/9, but
that refers only to uses of parameters within default arguments, not uses in
other contexts in the function declaration.)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/98804] GCC misparses template in pack expansion as comparison
2021-01-23 16:01 [Bug c++/98804] New: GCC misparses template in pack expansion as comparison foom at fuhm dot net
2021-01-24 20:33 ` [Bug c++/98804] " richard-gccbugzilla at metafoo dot co.uk
@ 2021-02-12 4:38 ` mpolacek at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-02-12 4:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98804
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-02-12
CC| |mpolacek at gcc dot gnu.org
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-12 4:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-23 16:01 [Bug c++/98804] New: GCC misparses template in pack expansion as comparison foom at fuhm dot net
2021-01-24 20:33 ` [Bug c++/98804] " richard-gccbugzilla at metafoo dot co.uk
2021-02-12 4:38 ` mpolacek 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).