From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 610D13857031; Wed, 21 Oct 2020 14:57:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 610D13857031 From: "barry.revzin at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/97518] New: Improving static_assert diagnostics Date: Wed, 21 Oct 2020 14:57:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: barry.revzin at gmail dot com X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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: Wed, 21 Oct 2020 14:57:27 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97518 Bug ID: 97518 Summary: Improving static_assert diagnostics Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: barry.revzin at gmail dot com Target Milestone: --- Consider the following: template struct is_same { static constexpr bool va= lue =3D false; }; template struct is_same { static constexpr bool value =3D true; }; template using some_metafunction_t =3D T; template void foo(T ) { using X =3D T*; using Y =3D some_metafunction_t; static_assert(is_same::value); } void bar() { foo(0); } gcc emits: : In instantiation of 'void foo(T) [with T =3D int]': :15:10: required from here :11:34: error: static assertion failed 11 | static_assert(is_same::value); |=20=20=20=20=20=20=20=20 Notably, it does not tell me what either X or Y are. All I know is that the= y're not the same. I get T, but the computation of X and Y could be fairly complicated and T may not help (or even be relevant, necessarily). This end= s up being useless for me, to the point where I actually created my own verify_s= ame type such that verify_same is only defined when T =3D=3D U, and creat= e a variable like: [[maybe_unused]] verify_same _; It would be a lot cooler if gcc could diagnose all the types and values that were used in a static_assert condition.=20 clang, for instance, gives me: :11:5: error: static_assert failed due to requirement 'is_same::value' static_assert(is_same::value); ^ ~~~~~~~~~~~~~~~~~~~~ :15:5: note: in instantiation of function template specialization 'foo' requested here foo(0); ^ Which, while it doesn't tell me that X=3Dint* and Y=3Dint, at least clearly illustrates both types, and is a much more useful error diagnostic.=