https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106357
Bug ID: 106357 Summary: [12/13 Regression] direct-list-initialization of enum class from a variable of another enum class type fails Product: gcc Version: 12.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: enolan at alumni dot cmu.edu Target Milestone: --- This example fails with GCC 12: enum class A { a }; enum class B { b }; int main() { A a{}; B b{a}; } --- P0138 added this language to the standard for C++17 (see: https://eel.is/c++draft/dcl.init.list#3.8) > if T is an enumeration with a fixed underlying type ([dcl.enum]) U, the > initializer-list has a single element v, v can be implicitly converted to U, > and the initialization is direct-list-initialization, the object is > initialized with the value T(v) ([expr.type.conv]); The above test case works in GCC 7-11 but appears to have regressed in GCC 12 and on trunk. --- > the exact version of GCC gcc version 12.1.1 20220507 (Red Hat 12.1.1-1) (GCC) > the system type Fedora release 37 (Rawhide) > the options given when GCC was configured/built Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-12.1.1-20220507/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-offload-defaulted --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1 > the complete command line that triggers the bug g++ -std=c++17 poc2.cpp > the compiler output (error messages, warnings, etc.) poc2.cpp: In function ‘int main()’: poc2.cpp:10:9: error: cannot convert ‘A’ to ‘B’ in initialization 10 | B b{a}; | ^ | | | A > the preprocessed file (*.i*) that triggers the bug, generated by adding > -save-temps to the complete compilation command, or, in the case of a bug > report for the GNAT frontend, a complete set of source files (see below). # 0 "poc2.cpp" # 0 "<built-in>" # 0 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 0 "<command-line>" 2 # 1 "poc2.cpp" enum class A { a }; enum class B { b }; int main() { A a{}; B b{a}; }