public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111008] New: '>' in a lambda as a template argument causes a syntax error
@ 2023-08-13 22:10 shin1_morita at yahoo dot co.jp
2023-08-13 22:12 ` [Bug c++/111008] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: shin1_morita at yahoo dot co.jp @ 2023-08-13 22:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111008
Bug ID: 111008
Summary: '>' in a lambda as a template argument causes a syntax
error
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: shin1_morita at yahoo dot co.jp
Target Milestone: ---
Created attachment 55732
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55732&action=edit
Complete code for reproducing the bug
The following code (a lambda as a template argument) produces a syntax error,
which is compiled successfully by clang or msvc:
return F<[](auto x)
{
return x > 0 ? x : 0;
}>()(0);
'>' in the lambda seems to cause the error.
A workaround is surrounding it with parentheses:
return (x > 0) ? x : 0;
See the attachment for complete code.
$ g++ -std=c++20 lambda.cc
lambda.cc: In lambda function:
lambda.cc:14:17: error: expected ';' before '>' token
14 | return x > 0 ? x : 0;
| ^~
| ;
lambda.cc:14:18: error: expected primary-expression before '>' token
14 | return x > 0 ? x : 0;
| ^
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,objc,obj-c++ --enable-bootstrap
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-__cxa_atexit --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.1 20230801 (GCC)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/111008] '>' in a lambda as a template argument causes a syntax error
2023-08-13 22:10 [Bug c++/111008] New: '>' in a lambda as a template argument causes a syntax error shin1_morita at yahoo dot co.jp
@ 2023-08-13 22:12 ` pinskia at gcc dot gnu.org
2023-08-13 22:17 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-13 22:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111008
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The most obvious workaround is to add parentheses around `x > 0`.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/111008] '>' in a lambda as a template argument causes a syntax error
2023-08-13 22:10 [Bug c++/111008] New: '>' in a lambda as a template argument causes a syntax error shin1_morita at yahoo dot co.jp
2023-08-13 22:12 ` [Bug c++/111008] " pinskia at gcc dot gnu.org
@ 2023-08-13 22:17 ` pinskia at gcc dot gnu.org
2023-08-13 22:22 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-13 22:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111008
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2023-08-13
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed reduced testcase:
template<bool f()>struct F{};
F<[]() { return (1 > 0); }> a;
F<[]() { return 1 > 0; }> a0;
The line containing a0 is rejected.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/111008] '>' in a lambda as a template argument causes a syntax error
2023-08-13 22:10 [Bug c++/111008] New: '>' in a lambda as a template argument causes a syntax error shin1_morita at yahoo dot co.jp
2023-08-13 22:12 ` [Bug c++/111008] " pinskia at gcc dot gnu.org
2023-08-13 22:17 ` pinskia at gcc dot gnu.org
@ 2023-08-13 22:22 ` pinskia at gcc dot gnu.org
2023-08-13 22:44 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-13 22:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111008
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
A related non-lambda testcase:
```
struct b{int a;};
template<b>struct F1{};
F1<b{(1>0)}> a;
F1<b{1>0}> a0;
```
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/111008] '>' in a lambda as a template argument causes a syntax error
2023-08-13 22:10 [Bug c++/111008] New: '>' in a lambda as a template argument causes a syntax error shin1_morita at yahoo dot co.jp
` (2 preceding siblings ...)
2023-08-13 22:22 ` pinskia at gcc dot gnu.org
@ 2023-08-13 22:44 ` pinskia at gcc dot gnu.org
2023-08-13 22:46 ` pinskia at gcc dot gnu.org
2023-08-14 18:13 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-13 22:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111008
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a C++11 testcase that also fails in a similar way:
```
typedef int b;
template<b>struct F1{};
F1<b{(1>0)}> a;
F1<b{1>0}> a0;
```
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/111008] '>' in a lambda as a template argument causes a syntax error
2023-08-13 22:10 [Bug c++/111008] New: '>' in a lambda as a template argument causes a syntax error shin1_morita at yahoo dot co.jp
` (3 preceding siblings ...)
2023-08-13 22:44 ` pinskia at gcc dot gnu.org
@ 2023-08-13 22:46 ` pinskia at gcc dot gnu.org
2023-08-14 18:13 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-13 22:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111008
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=33744
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I suspect the fix will look similar to the fix of PR 33744 .
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/111008] '>' in a lambda as a template argument causes a syntax error
2023-08-13 22:10 [Bug c++/111008] New: '>' in a lambda as a template argument causes a syntax error shin1_morita at yahoo dot co.jp
` (4 preceding siblings ...)
2023-08-13 22:46 ` pinskia at gcc dot gnu.org
@ 2023-08-14 18:13 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-14 18:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111008
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is another valid C++20 which is also causing issues, this time with `>>`
rather than `>`:
```
typedef int b;
template<b>struct F1{};
template<auto>struct F2{};
F1<b{(1>0)}> a;
constexpr int t = 3;
F2<F1<b{t>>0}>{}> a0;
```
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-08-14 18:13 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-13 22:10 [Bug c++/111008] New: '>' in a lambda as a template argument causes a syntax error shin1_morita at yahoo dot co.jp
2023-08-13 22:12 ` [Bug c++/111008] " pinskia at gcc dot gnu.org
2023-08-13 22:17 ` pinskia at gcc dot gnu.org
2023-08-13 22:22 ` pinskia at gcc dot gnu.org
2023-08-13 22:44 ` pinskia at gcc dot gnu.org
2023-08-13 22:46 ` pinskia at gcc dot gnu.org
2023-08-14 18:13 ` 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).