Bug 102367 - types can be defined in lambdas in unevaluated expression (decltype/sizeof) in C++20
Summary: types can be defined in lambdas in unevaluated expression (decltype/sizeof) i...
Status: RESOLVED DUPLICATE of bug 101911
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: lambdas
  Show dependency treegraph
 
Reported: 2021-09-16 14:48 UTC by Fedor Chelnokov
Modified: 2022-06-04 17:59 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-09-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fedor Chelnokov 2021-09-16 14:48:44 UTC
Since C++20 lambdas are allowed in not-evaluated context. So the code as follows must be valid:
```
using T = decltype( []{ struct S{}; return S{}; }() );

[[maybe_unused]] constexpr auto N 
          = sizeof( []{ struct S{}; return S{}; }() );
```

It is indeed accepted by MSVC and Clang, but rejected by GCC, demo: https://gcc.godbolt.org/z/jYjxcr1eP

The error is
```
error: types may not be defined in 'decltype' expressions
    1 | using T = decltype( []{ struct S{}; return S{}; }() );
      |                                 ^
<source>: In lambda function:
<source>:4:33: error: types may not be defined in 'sizeof' expressions
    4 |           = sizeof( []{ struct S{}; return S{}; }() );
      |             
```
Comment 1 Andrew Pinski 2021-09-16 18:41:48 UTC
I thought there was a dup of this bug somewhere.
Anyways confirmed.
Comment 2 Andrew Pinski 2021-10-12 23:40:53 UTC
(In reply to Andrew Pinski from comment #1)
> I thought there was a dup of this bug somewhere.
> Anyways confirmed.

I did, PR 101911.

*** This bug has been marked as a duplicate of bug 101911 ***