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

            Bug ID: 118047
           Summary: Incorrect direct-initialization of vector of struct of
                    array of struct of enum
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: MillerBenjaminT at johndeere dot com
  Target Milestone: ---

Created attachment 59869
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59869&action=edit
Preprocessed source file

I've been hunting down an error in the Qt sources and I think I might have
found a compiler bug involving list appertainment.

In short, if a vector of structs, each containing one element that is a
default-initialized array of structs containing one enum that is assigned a
value is list-initialized with { { } }, the vector will contain 0 elements.  My
best guess here is that g++ is creating an empty initializer list and copy
constructing another empty initializer list, rather than calling the default
constructor of the outermost struct.



#include <vector>

enum E {
    One
};

struct A {
    E e = One;
};

struct B {
    A as[3] {};
};

int main() {
    std::vector<B> bs { { } };
    if (bs.size() != 1) {
        throw; // Throws on g++ >= 12.1.0
    }

    return 0;
}


Here is a godbolt snippet of this minimal example:
https://godbolt.org/z/zf96vY3Ev


The vector will have 0 elements on any g++ >= 12.1.0 and will have 1 element on
any suitable clang or icc compiler.

Reply via email to