public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-9095] c++: ICE with -Wlogical-op [PR107755] Date: Wed, 1 Feb 2023 13:43:34 +0000 (GMT) [thread overview] Message-ID: <20230201134334.B9C143858D33@sourceware.org> (raw) https://gcc.gnu.org/g:fb2d50f72caf3b84b315bc760368670680999749 commit r12-9095-gfb2d50f72caf3b84b315bc760368670680999749 Author: Marek Polacek <polacek@redhat.com> Date: Tue Jan 31 14:36:30 2023 -0500 c++: ICE with -Wlogical-op [PR107755] Here we crash in the middle end because warn_logical_operator calls build_range_check which calls various fold_* functions and those don't work too well when we're still processing template trees. For instance here we crash because we're converting a RECORD_TYPE to bool. At this point VIEW_CONVERT_EXPR<struct Foo>(b) hasn't yet been converted to Foo::operator bool (&b). I was excited to fix this with instantiation_dependent_expression_p which can now be called from c-family/ as well, but the problem isn't that the expression is dependent. So, p_t_d it is. PR c++/107755 gcc/cp/ChangeLog: * call.cc (build_new_op): Don't call warn_logical_operator when processing a template. gcc/testsuite/ChangeLog: * g++.dg/warn/Wlogical-op-4.C: New test. (cherry picked from commit 5ce8961b46f050a96e8c542b34b1cf024ba95f1b) Diff: --- gcc/cp/call.cc | 2 +- gcc/testsuite/g++.dg/warn/Wlogical-op-4.C | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 67c30f380f2..ae9a029ee56 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -6901,7 +6901,7 @@ build_new_op (const op_location_t &loc, enum tree_code code, int flags, case TRUTH_ORIF_EXPR: case TRUTH_AND_EXPR: case TRUTH_OR_EXPR: - if (complain & tf_warning) + if ((complain & tf_warning) && !processing_template_decl) warn_logical_operator (loc, code, boolean_type_node, code_orig_arg1, arg1, code_orig_arg2, arg2); diff --git a/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C b/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C new file mode 100644 index 00000000000..745c9117a3d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C @@ -0,0 +1,23 @@ +// PR c++/107755 +// { dg-do compile } +// { dg-options "-Wlogical-op" } + +struct Foo +{ + operator bool() const { return false; } +}; + +bool a; +Foo b; + +template <typename ignored> +static bool Bar() +{ + return (true && (false ? a : b)); + return (false || (false ? a : b)); +} + +bool Baz() +{ + return Bar<void>(); +}
reply other threads:[~2023-02-01 13:43 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230201134334.B9C143858D33@sourceware.org \ --to=mpolacek@gcc.gnu.org \ --cc=gcc-cvs@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).