Bug 105222 - gcc totally broken with ternary operator for lambda in requires clause
Summary: gcc totally broken with ternary operator for lambda in requires clause
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, rejects-valid
Depends on:
Blocks: concepts
  Show dependency treegraph
 
Reported: 2022-04-11 14:38 UTC by 康桓瑋
Modified: 2023-07-20 05:22 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description 康桓瑋 2022-04-11 14:38:15 UTC
int main() {
  auto b = requires { true ? [] {} : [] {}; };
}
Comment 1 康桓瑋 2022-04-11 14:39:38 UTC
gcc rejects this valid syntax with

source>:2:32: error: expected ':' before '{' token
    2 |   auto b = requires { true ? [] {} : [] {}; };
      |                                ^~
      |                                :
<source>:2:33: error: expected primary-expression before '{' token
    2 |   auto b = requires { true ? [] {} : [] {}; };
      |                                 ^
<source>:2:35: error: expected ';' before ':' token
    2 |   auto b = requires { true ? [] {} : [] {}; };
      |                                   ^~
      |                                   ;

https://godbolt.org/z/4c3PPb5Pb
Comment 2 康桓瑋 2022-04-11 14:41:24 UTC
And gcc accepts the following invalid syntax:

int main() {
  auto b = requires { true ? [] : [] {}; };
}

https://godbolt.org/z/xeE1oYs1Y
Comment 3 康桓瑋 2022-04-11 14:46:22 UTC
(In reply to 康桓瑋 from comment #2)
> And gcc accepts the following invalid syntax:
> 
> int main() {
>   auto b = requires { true ? [] : [] {}; };
> }
> 
> https://godbolt.org/z/xeE1oYs1Y

It seems like the single [] makes gcc totally broken.

int main() {
  auto b = requires { true ? [] : []!-!-[]?[]; };
}

https://godbolt.org/z/EPTE6zf5E
Comment 4 康桓瑋 2022-04-11 16:22:04 UTC
maybe dup of PR99546.