public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-96286-4-4TpxJmecRU@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-96286-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96286 --- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- 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<typename _Tp, typename... _Types> constexpr size_t __find_uniq_type_in_pack() { constexpr ptrdiff_t __idx = std::__find_type_in_pack<_Tp, _Types...>(); static_assert(__idx >= 0, "the type T in std::get<T> 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 = std::__find_type_in_pack<_Tp, _Types...>(); static_assert(__idx >= 0, "the type T in std::get<T> must occur exactly once in the tuple"); if (__idx >= 0) return __idx; __builtin_unreachable(); } No, now I get 200 lines telling me that the I in std::get<I> is not a constant expression because of __builtin_unreachable. OK, let's try return enable_if_t<__idx >= 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<I> 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<I> 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.
next prev parent reply other threads:[~2021-07-15 10:56 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-07-22 15:00 [Bug c++/96286] New: " redi at gcc dot gnu.org 2021-07-15 10:44 ` [Bug c++/96286] " redi at gcc dot gnu.org 2021-07-15 10:56 ` redi at gcc dot gnu.org [this message] 2021-07-15 11:21 ` redi at gcc dot gnu.org 2021-08-30 21:27 ` cvs-commit at gcc dot gnu.org 2021-08-31 21:48 ` jason at gcc dot gnu.org 2021-09-02 12:27 ` jason at gcc dot gnu.org 2021-09-02 12:27 ` jason at gcc dot gnu.org 2021-09-02 12:56 ` redi at gcc dot gnu.org
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-96286-4-4TpxJmecRU@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).