From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DCBB23858CDB; Wed, 6 Dec 2023 17:07:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DCBB23858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701882455; bh=7P64Hu3C9UhinI+p6hJJQcPll1LmdeNKydTKq24qXx8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EAexnaCBRU8wZk+mvdnSG63B5B7TUMTJsXHwMNizAnbwcaofcaBN504HoyvsBdKXH o+MCU23VyCFhsBZHXjPZUFsYh8YjcZzJA8sBIWtCsHXCraWoPZw58H8NdqDDnEkXkd hKSfwIo/LxwnwjEaaenUqiKsp/6GACzawJTRWLkQ= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/112882] [14 Regression] std::clamp no longer usable in header only mode Date: Wed, 06 Dec 2023 17:07:35 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: 14.0 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=3D112882 --- Comment #2 from Jonathan Wakely --- That change was broken anyway: when _GLIBCXX_ASSERTIONS was not defined, the condition in the assertion is if constexpr (is_constant_evaluated()) which = is always true, even when not actually doing constant eval. I'll test this: --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -538,6 +538,7 @@ namespace std // This can be used without checking if the compiler supports the featur= e. // The macro _GLIBCXX_HAVE_IS_CONSTANT_EVALUATED can be used to check if // the compiler support is present to make this function work as expecte= d. + __attribute__((__always_inline__)) _GLIBCXX_CONSTEXPR inline bool __is_constant_evaluated() _GLIBCXX_NOEXCEPT { @@ -589,19 +590,28 @@ namespace std #endif #if defined(_GLIBCXX_ASSERTIONS) -# define _GLIBCXX_DO_ASSERT true -#elif _GLIBCXX_HAVE_IS_CONSTANT_EVALUATED -# define _GLIBCXX_DO_ASSERT std::__is_constant_evaluated() -#else -# define _GLIBCXX_DO_ASSERT false -#endif - # define __glibcxx_assert(cond)=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20 \ do { \ - if _GLIBCXX17_CONSTEXPR (_GLIBCXX_DO_ASSERT) \ - if (__builtin_expect(!bool(cond), false))=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 \ - _GLIBCXX_ASSERT_FAIL(cond); \ + if (__builtin_expect(!bool(cond), false)) \ + _GLIBCXX_ASSERT_FAIL(cond); \ } while (false) +#elif _GLIBCXX_HAVE_IS_CONSTANT_EVALUATED +namespace std +{ + __attribute__((__always_inline__,visibility("default"))) + inline void + __glibcxx_compile_time_assert_fail() + { } +} +# define __glibcxx_assert(cond)=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20 \ + do { \ + if (std::__is_constant_evaluated())=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20 \ + if (__builtin_expect(!bool(cond), false))=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 \ + __glibcxx_compile_time_assert_fail(); \ + } while (false) +#else +# define __glibcxx_assert(cond) +#endif // Macro indicating that TSAN is in use. #if __SANITIZE_THREAD__=