From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DC1A43858CDB; Wed, 29 Mar 2023 08:34:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC1A43858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680078846; bh=J4nBt1WZdYOkgkoVKZxmapX5+da31In/3vjUK0Kg3cw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UReGTIyZSLCVWTxeqSJE75iDCzHY7m+6OYW2mvielnF5Zqt+MP4zyRZ0mOAQAVzW0 /ufoaLDXQiixrTCbkkbK3Xw6A1IaAGctOnJx2ghL6MbmiSGKvwnGKj2HG2ePBwlG/3 S4QBHRbjghuMzvH813/eFwfjSWPQsR3iUOPjmj9Y= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/106608] [12/13 Regression] std::optional requires unavailable dtor Date: Wed, 29 Mar 2023 08:33:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.1.1 X-Bugzilla-Keywords: needs-bisection, rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106608 --- Comment #7 from Jonathan Wakely --- (In reply to Egor Pugin from comment #1) > All major compilers (MSVC, GCC, Clang) of all (tried) modern versions (in > case of GCC =E2=80=94 before 12) build this code without problems. Is thi= s a GCC > regression? Your links clearly show you're compiling with Clang though, not GCC. The pa= ste starts with: [1/135] /usr/lib/ccache/bin/clang++ The code can be reduced to: template struct vector { T* ptr; vector(); vector(const vector&); ~vector() { ++ptr; } // requires T to be complete }; struct nullopt_t { }; constexpr nullopt_t nullopt{}; template struct optional_payload { optional_payload() =3D default; ~optional_payload() { if (engaged) value.~T(); } union { unsigned char dummy; T value; }; bool engaged =3D false; }; template struct optional_base { optional_base() =3D default; ~optional_base() =3D default; optional_payload payload; }; template struct optional : optional_base { constexpr optional(nullopt_t) { } }; struct ScanInfo; struct List { List(optional>&& =3D nullopt); }; GCC compiles this, but Clang doesn't: $ clang++ -std=3Dc++17 -c inc.cc inc.cc:36:13: error: call to implicitly-deleted default constructor of 'optional_base>' constexpr optional(nullopt_t) { } ^ inc.cc:47:39: note: in instantiation of member function 'optional>::optional' requested here List(optional>&& =3D nullopt); ^ inc.cc:28:3: note: explicitly defaulted function was implicitly deleted here optional_base() =3D default; ^ inc.cc:30:23: note: default constructor of 'optional_base>= ' is implicitly deleted because field 'payload' has a deleted default constructor optional_payload payload; ^ inc.cc:16:3: note: explicitly defaulted function was implicitly deleted here optional_payload() =3D default; ^ inc.cc:20:7: note: default constructor of 'optional_payload>' is implicitly deleted because variant field 'value' has a non-trivial defau= lt constructor T value; ^ 1 error generated. Neither does EDG: $ edg --c++17 -c inc.cc "inc.cc", line 36: error: the default constructor of "optional_base>" cannot be referenced -- it is a deleted function constexpr optional(nullopt_t) { } ^ detected during instantiation of "optional::optional(nullopt_t) [with T=3Dvector]" at line 42 "inc.cc", line 7: error: expression must be a pointer to a complete object = type ~vector() { ++ptr; } // requires T to be complete ^ detected during: instantiation of "vector::~vector() [with T=3DScanInfo]" at = line 17 instantiation of "optional_payload::~optional_payload() [with T=3Dvector]" at line 43 2 errors detected in the compilation of "inc.cc". Nor MSVC: (7): error C2036: 'ScanInfo *': unknown size (7): note: while compiling class template member function 'vector::~vector(void)' (44): note: see reference to function template instantiation 'vector::~vector(void)' being compiled (20): note: see reference to class template instantiation 'vector' being compiled (30): note: see reference to class template instantiation 'optional_payload' being compiled with [ T=3Dvector ] (35): note: see reference to class template instantiation 'optional_base' being compiled with [ T=3Dvector ] (42): note: see reference to class template instantiation 'optional>' being compiled Compiler returned: 2 Maybe the code is ill-formed (no diagnostic required), or maybe G++ is being too generous to compile it, but I don't think there's a libstdc++ bug here.=