From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9F739397B80E; Thu, 15 Jul 2021 10:56:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F739397B80E From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/96286] Unhelpful errors after a failed static_assert Date: Thu, 15 Jul 2021 10:56:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.1.1 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Jul 2021 10:56:43 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96286 --- Comment #2 from Jonathan Wakely --- It also doesn't help that the compiler thwarts my attempt to trigger errors earlier like so: // Return index of _Tp in _Types. // Ill-formed if _Tp doesn't occur exactly once in _Types. template constexpr size_t __find_uniq_type_in_pack() { constexpr ptrdiff_t __idx =3D std::__find_type_in_pack<_Tp, _Types...= >(); static_assert(__idx >=3D 0, "the type T in std::get must occur exactly once in the tuple"); return size_t{__idx}; } The return statement *should* be an ill-formed narrowing conversion, but G++ (and Clang) think that because I'm in a system header we probably wanted to ignore that, so we return a huge value and get 200 lines of errors again. Maybe this will work? { constexpr ptrdiff_t __idx =3D std::__find_type_in_pack<_Tp, _Types...= >(); static_assert(__idx >=3D 0, "the type T in std::get must occur exactly once in the tuple"); if (__idx >=3D 0) return __idx; __builtin_unreachable(); } No, now I get 200 lines telling me that the I in std::get is not a const= ant expression because of __builtin_unreachable. OK, let's try return enable_if_t<__idx >=3D 0, size_t>{__idx}; This prints "error: no type named 'type' in 'struct std::enable_if'" as expected, but then 200 lines telling me std::get is not a constant expression because it flows off the end of the function. Why is the compiler even doing overload resolution for std::get if I is = an invalid constant expression?! It's not going to match any overload! It shouldn't be this hard. Just stop compiling already.=