From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] c++: ICE with failed __is_constructible constraint [PR100474]
Date: Tue, 29 Mar 2022 15:22:30 -0400 [thread overview]
Message-ID: <20220329192230.255163-1-ppalka@redhat.com> (raw)
Here we're crashing when diagnosing a failed __is_constructible constraint
because diagnose_atomic_constraint don't know how to diagnose a trait
that diagnose_trait_expr doesn't specifically handle. This patch fixes
this by falling through to the default case in this situation.
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk and perhaps 11?
PR c++/100474
gcc/cp/ChangeLog:
* constraint.cc (diagnose_trait_expr): Rename to ...
(maybe_diagnose_trait_expr): ... this. Return a boolean
indicating whether we handled the trait.
(diagnose_atomic_constraint) <case TRAIT_EXPR>: Fall through to
the default case if maybe_diagnose_trait_expr returns false.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-traits3.C: New test.
---
gcc/cp/constraint.cc | 16 +++++++++-------
gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C | 10 ++++++++++
2 files changed, 19 insertions(+), 7 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index c5a991b9e71..27b1b9bb659 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3567,10 +3567,10 @@ get_constraint_error_location (tree t)
return input_location;
}
-/* Emit a diagnostic for a failed trait. */
+/* Maybe emit a friendlier diagnostic for the failed trait. */
-static void
-diagnose_trait_expr (tree expr, tree args)
+static bool
+maybe_diagnose_trait_expr (tree expr, tree args)
{
location_t loc = cp_expr_location (expr);
@@ -3655,8 +3655,9 @@ diagnose_trait_expr (tree expr, tree args)
inform (loc, " %qT is not a union", t1);
break;
default:
- gcc_unreachable ();
+ return false;
}
+ return true;
}
/* Diagnose a substitution failure in the atomic constraint T using ARGS. */
@@ -3685,9 +3686,6 @@ diagnose_atomic_constraint (tree t, tree args, tree result, sat_info info)
STRIP_ANY_LOCATION_WRAPPER (expr);
switch (TREE_CODE (expr))
{
- case TRAIT_EXPR:
- diagnose_trait_expr (expr, args);
- break;
case REQUIRES_EXPR:
gcc_checking_assert (info.diagnose_unsatisfaction_p ());
/* Clear in_decl before replaying the substitution to avoid emitting
@@ -3696,6 +3694,10 @@ diagnose_atomic_constraint (tree t, tree args, tree result, sat_info info)
info.in_decl = NULL_TREE;
tsubst_requires_expr (expr, args, info);
break;
+ case TRAIT_EXPR:
+ if (maybe_diagnose_trait_expr (expr, args))
+ break;
+ /* Fall through. */
default:
if (!same_type_p (TREE_TYPE (result), boolean_type_node))
error_at (loc, "constraint %qE has type %qT, not %<bool%>",
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C
new file mode 100644
index 00000000000..33152242988
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C
@@ -0,0 +1,10 @@
+// PR c++/100474
+// { dg-do compile { target c++20 } }
+
+template<class T, class... Args>
+concept C = __is_constructible(T, Args...); // { dg-message "evaluated to 'false'" }
+struct S {
+ S() = delete;
+};
+
+static_assert(C<S>); // { dg-error "assert" }
--
2.35.1.677.gabf474a5dd
next reply other threads:[~2022-03-29 19:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-29 19:22 Patrick Palka [this message]
2022-03-29 20:53 ` Jason Merrill
2022-03-30 12:56 ` Patrick Palka
2022-03-30 13:03 ` Jason Merrill
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=20220329192230.255163-1-ppalka@redhat.com \
--to=ppalka@redhat.com \
--cc=gcc-patches@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: link
Be 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).