Bug 102820 - [DR2351] Failure to compile void{}
Summary: [DR2351] Failure to compile void{}
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: 12.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
: 108591 (view as bug list)
Depends on:
Blocks: c++-core-issues
  Show dependency treegraph
 
Reported: 2021-10-18 19:00 UTC by Gabriel Ravier
Modified: 2023-01-29 16:00 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-10-18 00:00:00


Attachments
gcc12-pr102820.patch (802 bytes, patch)
2021-10-20 15:22 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriel Ravier 2021-10-18 19:00:05 UTC
void f()
{
    void{};
}

This has been considered valid since http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2351 was accepted as a DR in 2018, but GCC fails to compile it, with this error:

<source>: In function 'void f()':
<source>:3:10: error: compound literal of non-object type 'void'
    3 |     void{};
      |          ^
Comment 1 Marek Polacek 2021-10-18 19:29:35 UTC
Confirmed.
Comment 2 Jakub Jelinek 2021-10-20 15:22:02 UTC
Created attachment 51638 [details]
gcc12-pr102820.patch

Untested fix.
Comment 3 CVS Commits 2021-10-29 07:31:47 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:eca767aa51d1f69614222ceb130ca6bb07713232

commit r12-4782-geca767aa51d1f69614222ceb130ca6bb07713232
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Oct 29 09:28:32 2021 +0200

    c++: Implement DR2351 - void{} [PR102820]
    
    Here is an implementation of DR2351 - void{} - where void{} after
    pack expansion is considered valid and the same thing as void().
    For templates, if CONSTRUCTOR_NELTS is 0, the CONSTRUCTOR is not dependent
    and we can return void_node right away, if it is dependent and contains
    only packs, then it is potentially zero element and so we need to build
    CONSTRUCTOR_IS_DEPENDENT CONSTRUCTOR, while if it contains any non-pack
    elts, we can diagnose it right away.
    
    2021-10-29  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/102820
            * semantics.c (maybe_zero_constructor_nelts): New function.
            (finish_compound_literal): Implement DR2351 - void{}.
            If type is cv void and compound_literal has no elements, return
            void_node.  If type is cv void and compound_literal might have no
            elements after expansion, handle it like other dependent compound
            literals.
    
            * g++.dg/cpp0x/dr2351.C: New test.
Comment 4 Jakub Jelinek 2021-10-29 07:32:26 UTC
Implemented now.
Comment 5 Andrew Pinski 2023-01-29 16:00:09 UTC
*** Bug 108591 has been marked as a duplicate of this bug. ***