public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "johelegp at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110936] if constexpr: member function pointers cannot be checked with ubsan Date: Fri, 01 Sep 2023 02:21:26 +0000 [thread overview] Message-ID: <bug-110936-4-4U4YuRSPxH@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-110936-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110936 --- Comment #2 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> --- FWIW, it seems that you can use <https://quuxplusone.github.io/blog/2022/01/04/test-constexpr-friendliness/> to test the validity during constant evaluation. It seems that an invalid constant expression implies a `false` result. So I guard the check with a validity check: <https://compiler-explorer.com/z/had59d6nv>. ```C++ #include <type_traits> template<auto F> concept is_constant = requires { typename std::integral_constant<int, (F(), 0)>; }; template<auto l, auto r> constexpr bool implements() { using R = decltype(r); if constexpr (requires { static_cast<R>(l); }) #if !defined(__GNUC__) || defined(__clang__) return static_cast<R>(l) != r; #else // Workaround <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962>. return !is_constant<[]() { return static_cast<R>(l) != r; }> || static_cast<R>(l) != r; #endif return false; } struct B { void f(); }; struct D0 : B { }; struct D1 : B { void f(); }; struct D2 : B { void f() const; }; // struct D3 : B { int f(); void f() const; }; static_assert(!implements<&D0::f, &B::f>()); static_assert(implements<&D1::f, &B::f>()); static_assert(!implements<&D2::f, &B::f>()); // static_assert(!implements<&D3::f, &B::f>()); ```
next prev parent reply other threads:[~2023-09-01 2:21 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-08-07 15:52 [Bug sanitizer/110936] New: " jeanmichael.celerier at gmail dot com 2023-09-01 1:54 ` [Bug c++/110936] " johelegp at gmail dot com 2023-09-01 2:21 ` johelegp at gmail dot com [this message] 2023-11-09 1:42 ` nathanieloshead at gmail dot com 2023-11-09 1:44 ` johelegp at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-110936-4-4U4YuRSPxH@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).