[Bug c++/105757] New: default argument of incomplete type with C++20
fsb4000 at yandex dot ru
gcc-bugzilla@gcc.gnu.org
Sat May 28 11:34:26 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105757
Bug ID: 105757
Summary: default argument of incomplete type with C++20
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fsb4000 at yandex dot ru
Target Milestone: ---
Hi!
One user reported that some code doesn't work with current MSVC but worked
before and works with gcc.
Reduced code:
template <class T>
struct A {
constexpr A() {}
constexpr ~A() { T t; }
};
struct B;
void f(const A<B>& = {});
$ g++ -std=c++20 -c main.cpp
https://gcc.godbolt.org/z/jWdd3Gc5h
MSVC devs think that the code is not valid and I decided to inform you:
Cameron DaCamara: "I'm pretty convinced this is a source bug and that GCC
hasn't quite implemented
P0859R0(https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0859r0.html)
fully yet. The reason this is now observable with newer MSVC versions is
because the compiler is required to instantiate special member functions if
they could be potentially used for constant evaluation. Since the default
argument here is going to end up being assigned to a variable the ctor and dtor
are actually odr-used in the default argument."
Also if we reformat the code slightly(A<B>{} instead of {}) then it is rejected
by gcc:
template <class T>
struct A {
constexpr A() {}
constexpr ~A() { T t; }
};
struct B;
void f(const A<B>& = A<B>{});
$ g++ -std=c++20 -c main.cpp
main.cpp: In instantiation of 'constexpr A<T>::~A() [with T = B]':
main.cpp:9:27: required from here
main.cpp:5:24: error: 'B t' has incomplete type
5 | constexpr ~A() { T t; }
|
My GCC version:
$ g++ -v
Using built-in specs.
COLLECT_GCC=C:\tools\msys64\mingw64\bin\g++.exe
COLLECT_LTO_WRAPPER=C:/tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-12.1.0/configure --prefix=/mingw64
--with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32
--host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32
--with-native-system-header-dir=/mingw64/include --libexecdir=/mingw64/lib
--enable-bootstrap --enable-checking=release --with-arch=x86-64
--with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit
--enable-shared --enable-static --enable-libatomic --enable-threads=posix
--enable-graphite --enable-fully-dynamic-string
--enable-libstdcxx-filesystem-ts --enable-libstdcxx-time
--disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-multilib
--disable-rpath --disable-win32-registry --disable-nls --disable-werror
--disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64
--with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64
--with-pkgversion='Rev2, Built by MSYS2 project'
--with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as
--with-gnu-ld --disable-libstdcxx-debug --with-boot-ldflags=-static-libstdc++
--with-stage1-ldflags=-static-libstdc++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.1.0 (Rev2, Built by MSYS2 project)
More information about the Gcc-bugs
mailing list