From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DAEB33851C10; Sat, 19 Feb 2022 03:31:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAEB33851C10 From: "foom at fuhm dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/104602] New: std::source_location::current uses cast from void* Date: Sat, 19 Feb 2022 03:31:47 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: foom at fuhm dot net 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: Sat, 19 Feb 2022 03:31:48 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104602 Bug ID: 104602 Summary: std::source_location::current uses cast from void* Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: foom at fuhm dot net Target Milestone: --- I'm working on implementing __builtin_source_location() in Clang (https://reviews.llvm.org/D120159). In testing it against the libstdc++ header, I ran into a minor issue. "current()" in GNU libstdc++ is defined as so: static consteval source_location current(const void* __p =3D __builtin_source_location()) noexcept { source_location __ret; __ret._M_impl =3D static_cast (__p); return __ret; } But! A static_cast from a `const void*` parameter to `const __impl*` is not permitted in constexpr evaluation: """ 5. An expression E is a core constant expression unless the evaluation of E, [...] would evaluate one of the following: [...] 5.15. a conversion from type cv void* to a pointer-to-object type;" """ http://eel.is/c++draft/expr.const#5.15 Clang diagnoses this rule, but GCC apparently does not. (it's not really cl= ear to me why this rule really needs to exist in the standard -- why bother to police which kinds of pointer casts you're allowed to do, instead of just raising an error upon _access_ through the wrong type?) Anyhow, to workaround this issue, I plan to simply hardcode an exception to= the check in Clang for casts which occur in a "std::source_location::current" method. Yet, although it's perhaps too late to avoid this workaround, it'd = be nice if libstdc++ didn't require the use of an invalid cast. In clang (in my proposed change), __builtin_source_location already returns= the expected `const __impl*` type, rather than `const void*` as it does in GCC.= So, the issue is only the cast TO `void*` and back again in libstdc++. ISTM this would be fixed by moving the `static_cast ` into the default parameter expression. That would then be a no-op cast on clang, and an (inv= alid but undiagnosed) cast from void in GCC.=