public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/96645] New: std::variant default constructor
@ 2020-08-17  7:58 dev at hrookami dot icu
  2020-08-17 14:21 ` [Bug c++/96645] [9/10/11 Regression] " redi at gcc dot gnu.org
                   ` (33 more replies)
  0 siblings, 34 replies; 35+ messages in thread
From: dev at hrookami dot icu @ 2020-08-17  7:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96645

            Bug ID: 96645
           Summary: std::variant default constructor
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dev at hrookami dot icu
  Target Milestone: ---

Appears in version 9 and above.
Flags: -std=c++17

Code:

#include <variant>

void testVariant()
{
    struct DataWithVariant {
        using Member = std::variant<int, float>;
        Member d;
    };
    auto d = DataWithVariant{};
}

void testVarStruct()
{
    struct DataWithStruct {
        struct A {
            int number = 5; // compiles, if remove initialization
        };

        struct B {
            bool flag = false;
        };

        using Member = std::variant<A, B>;
        Member data;
    };
    auto d = DataWithStruct{};
}

int main() {
    testVariant();
    testVarStruct();
}




Compiler output:
<source>: In function 'void testVarStruct()':

<source>:26:29: error: use of deleted function 'std::variant<_Types>::variant()
[with _Types = {testVarStruct()::DataWithStruct::A,
testVarStruct()::DataWithStruct::B}]'

   26 |     auto d = DataWithStruct{};

      |                             ^

In file included from <source>:1:

/opt/compiler-explorer/gcc-9.1.0/include/c++/9.1.0/variant:1287:7: note:
'std::variant<_Types>::variant() [with _Types =
{testVarStruct()::DataWithStruct::A, testVarStruct()::DataWithStruct::B}]' is
implicitly deleted because the default definition would be ill-formed:

 1287 |       variant() = default;

      |       ^~~~~~~

/opt/compiler-explorer/gcc-9.1.0/include/c++/9.1.0/variant:1287:7: error: use
of deleted function 'constexpr std::_Enable_default_constructor<false,
_Tag>::_Enable_default_constructor() [with _Tag =
std::variant<testVarStruct()::DataWithStruct::A,
testVarStruct()::DataWithStruct::B>]'

In file included from
/opt/compiler-explorer/gcc-9.1.0/include/c++/9.1.0/variant:38,

                 from <source>:1:

/opt/compiler-explorer/gcc-9.1.0/include/c++/9.1.0/bits/enable_special_members.h:110:15:
note: declared here

  110 |     constexpr _Enable_default_constructor() noexcept = delete;

      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~





It compiles if move nested structs in global namespace or remove initializer.

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2024-05-21  9:10 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-17  7:58 [Bug libstdc++/96645] New: std::variant default constructor dev at hrookami dot icu
2020-08-17 14:21 ` [Bug c++/96645] [9/10/11 Regression] " redi at gcc dot gnu.org
2020-08-17 14:24 ` dev at hrookami dot icu
2020-08-17 14:30 ` redi at gcc dot gnu.org
2020-08-17 14:40 ` redi at gcc dot gnu.org
2020-08-18  7:49 ` dev at hrookami dot icu
2020-08-25 10:31 ` rguenth at gcc dot gnu.org
2020-10-12 12:33 ` rguenth at gcc dot gnu.org
2021-01-25 13:53 ` jakub at gcc dot gnu.org
2021-02-15 15:28 ` ppalka at gcc dot gnu.org
2021-04-02 18:20 ` jason at gcc dot gnu.org
2021-04-02 18:21 ` jason at gcc dot gnu.org
2021-04-03 11:27 ` redi at gcc dot gnu.org
2021-06-01  8:18 ` [Bug c++/96645] [9/10/11/12 " rguenth at gcc dot gnu.org
2021-09-06 19:56 ` eyalroz1 at gmx dot com
2021-11-23 17:08 ` redi at gcc dot gnu.org
2022-03-22 14:12 ` [Bug c++/96645] [9/10/11/12 Regression] [CWG2335] std::variant default constructor and unparsed DMI jason at gcc dot gnu.org
2022-03-22 16:15 ` jason at gcc dot gnu.org
2022-03-22 16:22 ` jason at gcc dot gnu.org
2022-03-22 17:31 ` ppalka at gcc dot gnu.org
2022-03-22 20:56 ` eyalroz1 at gmx dot com
2022-03-22 21:29 ` redi at gcc dot gnu.org
2022-03-23 13:36 ` jason at gcc dot gnu.org
2022-03-24 18:31 ` cvs-commit at gcc dot gnu.org
2022-03-26 23:22 ` jason at gcc dot gnu.org
2022-03-31  1:43 ` cvs-commit at gcc dot gnu.org
2022-04-01 14:00 ` cvs-commit at gcc dot gnu.org
2022-04-01 14:07 ` jason at gcc dot gnu.org
2022-04-01 14:14 ` jason at gcc dot gnu.org
2022-04-22  8:26 ` redi at gcc dot gnu.org
2022-05-15  6:35 ` [Bug c++/96645] [9/10/11/12/13 " pinskia at gcc dot gnu.org
2022-08-15  4:53 ` [Bug c++/96645] [10/11/12/13 " pinskia at gcc dot gnu.org
2023-04-26  6:55 ` [Bug c++/96645] [10/11/12/13/14 " rguenth at gcc dot gnu.org
2023-07-27  9:22 ` [Bug c++/96645] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-05-21  9:10 ` [Bug c++/96645] [11/12/13/14/15 " jakub 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).