public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rl.alt.accnt at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105143] New: ICE when trying to emit a [[nodiscard]] warning Date: Mon, 04 Apr 2022 03:02:18 +0000 [thread overview] Message-ID: <bug-105143-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105143 Bug ID: 105143 Summary: ICE when trying to emit a [[nodiscard]] warning Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rl.alt.accnt at gmail dot com Target Milestone: --- I'm getting an internal compiler error when I try to compile the code below: ``` #include <algorithm> #include <type_traits> #include <string> template <size_t sz> struct str_lit { char data[sz]{}; constexpr str_lit(const char (&_data)[sz]) { std::copy_n(_data, sz, data); } template <typename str> constexpr bool operator==(const str& s) const { return sizeof data == sizeof s.data && __builtin_strcmp(data, s.data) == 0; } }; template <str_lit _name, typename _type = std::string> struct option { using type = _type; static constexpr inline decltype(_name) name = _name; }; template <typename... opts> struct command_line_options { template <str_lit s, typename... options> struct type_of; template <str_lit s, typename option, typename option2> struct type_of<s, option, option2> { using type = std::conditional_t<s == option::name, typename option::type, typename option2::type>; }; template <str_lit s, typename option, typename... options> struct type_of<s, option, options...> { using type = std::conditional_t<sizeof...(options) == 0 || s == option::name, typename option::type, typename type_of<s, options...>::type>; }; template <str_lit s> using type_of_t = typename type_of<s, opts...>::type; struct parsed_options { template <str_lit s> [[nodiscard]] type_of_t<s> get() { return {}; } }; }; using options = command_line_options< option<"--filename">, option<"--size", int64_t>>; int main() { options::parsed_options opts; opts.get<"--filename">(); // (void) opts.get<"--filename">(); // Doing this instead works } ``` It seems that this happens while it is trying to emit a warning about the unused return value of `opts.get<"--filename">()` since when I do use it or cast it to (void) it compiles just fine. The same problem also occurs with `[[gnu::warn_unused_result]]` instead of `[[nodiscard]]`. Here's the backtrace: ``` ' Internal compiler error: Error reporting routines re-entered. 0xf3d164 warning(int, char const*, ...) ???:0 0x1190cb1 tsubst(tree_node*, tree_node*, int, tree_node*) ???:0 0x1479e26 pp_format(pretty_printer*, text_info*) ???:0 0xf3d5cf diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*) ???:0 0xf953af warning_at(unsigned int, int, char const*, ...) ???:0 0x10fa93c convert_to_void(tree_node*, impl_conv_void, int) ???:0 0x10f9d03 finish_expr_stmt(tree_node*) ???:0 0x14e7873 c_parse_file() ???:0 0x14c9d9e c_common_parse_file() ???:0 ``` I'm running gcc 11.2.0 on x86_64 Arch Linux, but I've also tested this with several versions of GCC on compiler explorer including trunk and I ran into much the same problem. Here's a link to that: https://godbolt.org/z/qPY4ccPfr.
next reply other threads:[~2022-04-04 3:02 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-04 3:02 rl.alt.accnt at gmail dot com [this message] 2022-04-06 14:48 ` [Bug c++/105143] c++20: ICE when trying to emit a [[nodiscard]] warning and non-type template arugument ppalka at gcc dot gnu.org 2022-04-06 15:46 ` cvs-commit at gcc dot gnu.org 2022-04-06 15:48 ` ppalka at gcc dot gnu.org 2022-04-07 19:19 ` cvs-commit at gcc dot gnu.org 2022-04-07 19:28 ` ppalka 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-105143-4@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).