Re: [PATCH] c++: ICE with failed __is_constructible constraint [PR100474]
On 3/30/22 08:56, Patrick Palka wrote: On Tue, 29 Mar 2022, Jason Merrill wrote: On 3/29/22 15:22, Patrick Palka wrote: 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? Hmm, it seems reasonable, but I think it would be better to actually handle all the traits. Removing the default, I get constraint.cc:3585:10: warning: enumeration value ‘CPTK_BASES’ not handled in switch [-Wswitch] constraint.cc:3585:10: warning: enumeration value ‘CPTK_DIRECT_BASES’ not handled in switch [-Wswitch] constraint.cc:3585:10: warning: enumeration value ‘CPTK_UNDERLYING_TYPE’ not handled in switch [-Wswitch] These we don't need to handle. constraint.cc:3585:10: warning: enumeration value ‘CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS’ not handled in switch \ constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_AGGREGATE’ not handled in switch [-Wswitch] constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_TRIVIALLY_ASSIGNABLE’ not handled in switch [-Wswit\ constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_TRIVIALLY_CONSTRUCTIBLE’ not handled in switch [-Ws\ constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_TRIVIALLY_COPYABLE’ not handled in switch [-Wswitch\ constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_ASSIGNABLE’ not handled in switch [-Wswitch] constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_CONSTRUCTIBLE’ not handled in switch [-Wswitch] constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_NOTHROW_ASSIGNABLE’ not handled in switch [-Wswitch\ constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_NOTHROW_CONSTRUCTIBLE’ not handled in switch [-Wswi\ These we should. I think we should leave off the default so that when we add more traits we get a warning that we need to handle them here. Sounds good, like so? Let's leave a comment about why there's no 'default'. OK with that change. -- >8 -- Subject: [PATCH] c++: ICE with failed __is_constructible constraint [PR100474] Here we're crashing when diagnosing a failed __is_constructible constraint because diagnose_trait_expr doesn't recognize this trait (along with a bunch of other traits). Fix this by adding handling for all remaining traits and removing the default case so that when we add a new trait we get a warning that diagnose_trait_expr needs to handle it. 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): Handle all remaining traits appropriately. Remove default case. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-traits3.C: New test. --- gcc/cp/constraint.cc | 41 +++- gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C | 66 +++ 2 files changed, 106 insertions(+), 1 deletion(-) 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..b970ac9772d 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3654,7 +3654,46 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; -default: +case CPTK_IS_AGGREGATE: + inform (loc, " %qT is not an aggregate", t1); + break; +case CPTK_IS_TRIVIALLY_COPYABLE: + inform (loc, " %qT is not trivially copyable", t1); + break; +case CPTK_IS_ASSIGNABLE: + inform (loc, " %qT is not assignable from %qT", t1, t2); + break; +case CPTK_IS_TRIVIALLY_ASSIGNABLE: + inform (loc, " %qT is not trivially assignable from %qT", t1, t2); + break; +case CPTK_IS_NOTHROW_ASSIGNABLE: + inform (loc, " %qT is not % assignable from %qT", t1, t2); + break; +case CPTK_IS_CONSTRUCTIBLE: + if (!t2) + inform (loc, " %qT is not default constructible", t1); + else + inform (loc, " %qT is not constructible from %qE", t1, t2); + break; +case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: + if (!t2) + inform (loc, " %qT is not trivially default constructible", t1); + else + inform (loc, " %qT is not trivially constructible from %qE", t1, t2); + break; +case CPTK_IS_NOTHROW_CONSTRUCTIBLE: + if (!t2) + inform (loc, " %qT is not % default constructible", t1); + else + inform (loc, " %qT is not % constructible from %qE", t1, t2); + break; +case CPTK_HAS_UNIQUE_
Re: [PATCH] c++: ICE with failed __is_constructible constraint [PR100474]
On Tue, 29 Mar 2022, Jason Merrill wrote: > On 3/29/22 15:22, Patrick Palka wrote: > > 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? > > Hmm, it seems reasonable, but I think it would be better to actually handle > all the traits. Removing the default, I get > > > constraint.cc:3585:10: warning: enumeration value ‘CPTK_BASES’ not handled > > in switch [-Wswitch] > > constraint.cc:3585:10: warning: enumeration value ‘CPTK_DIRECT_BASES’ not > > handled in switch [-Wswitch] > > constraint.cc:3585:10: warning: enumeration value ‘CPTK_UNDERLYING_TYPE’ not > > handled in switch [-Wswitch] > > These we don't need to handle. > > > constraint.cc:3585:10: warning: enumeration value > > ‘CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS’ not handled in switch \ > > constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_AGGREGATE’ not > > handled in switch [-Wswitch] > > constraint.cc:3585:10: warning: enumeration value > > ‘CPTK_IS_TRIVIALLY_ASSIGNABLE’ not handled in switch [-Wswit\ > > constraint.cc:3585:10: warning: enumeration value > > ‘CPTK_IS_TRIVIALLY_CONSTRUCTIBLE’ not handled in switch [-Ws\ > > constraint.cc:3585:10: warning: enumeration value > > ‘CPTK_IS_TRIVIALLY_COPYABLE’ not handled in switch [-Wswitch\ > > constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_ASSIGNABLE’ not > > handled in switch [-Wswitch] > > constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_CONSTRUCTIBLE’ > > not handled in switch [-Wswitch] > > constraint.cc:3585:10: warning: enumeration value > > ‘CPTK_IS_NOTHROW_ASSIGNABLE’ not handled in switch [-Wswitch\ > > constraint.cc:3585:10: warning: enumeration value > > ‘CPTK_IS_NOTHROW_CONSTRUCTIBLE’ not handled in switch [-Wswi\ > > These we should. > > I think we should leave off the default so that when we add more traits we get > a warning that we need to handle them here. Sounds good, like so? -- >8 -- Subject: [PATCH] c++: ICE with failed __is_constructible constraint [PR100474] Here we're crashing when diagnosing a failed __is_constructible constraint because diagnose_trait_expr doesn't recognize this trait (along with a bunch of other traits). Fix this by adding handling for all remaining traits and removing the default case so that when we add a new trait we get a warning that diagnose_trait_expr needs to handle it. 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): Handle all remaining traits appropriately. Remove default case. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-traits3.C: New test. --- gcc/cp/constraint.cc | 41 +++- gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C | 66 +++ 2 files changed, 106 insertions(+), 1 deletion(-) 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..b970ac9772d 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3654,7 +3654,46 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; -default: +case CPTK_IS_AGGREGATE: + inform (loc, " %qT is not an aggregate", t1); + break; +case CPTK_IS_TRIVIALLY_COPYABLE: + inform (loc, " %qT is not trivially copyable", t1); + break; +case CPTK_IS_ASSIGNABLE: + inform (loc, " %qT is not assignable from %qT", t1, t2); + break; +case CPTK_IS_TRIVIALLY_ASSIGNABLE: + inform (loc, " %qT is not trivially assignable from %qT", t1, t2); + break; +case CPTK_IS_NOTHROW_ASSIGNABLE: + inform (loc, " %qT is not % assignable from %qT", t1, t2); + break; +case CPTK_IS_CONSTRUCTIBLE: + if (!t2) + inform (loc, " %qT is not default constructible", t1); + else + inform (loc, " %qT is not constructible from %qE", t1, t2); + break; +case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: + if (!t2) + inform (loc, " %qT is not trivially default constructible", t1); + else + inform (loc, " %qT is not trivially constructible from %qE", t1, t2); + break; +case CPTK_IS_NOTHROW_CONSTRUCTIBLE: + if
Re: [PATCH] c++: ICE with failed __is_constructible constraint [PR100474]
On 3/29/22 15:22, Patrick Palka wrote: 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? Hmm, it seems reasonable, but I think it would be better to actually handle all the traits. Removing the default, I get constraint.cc:3585:10: warning: enumeration value ‘CPTK_BASES’ not handled in switch [-Wswitch] constraint.cc:3585:10: warning: enumeration value ‘CPTK_DIRECT_BASES’ not handled in switch [-Wswitch] constraint.cc:3585:10: warning: enumeration value ‘CPTK_UNDERLYING_TYPE’ not handled in switch [-Wswitch] These we don't need to handle. constraint.cc:3585:10: warning: enumeration value ‘CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS’ not handled in switch \ constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_AGGREGATE’ not handled in switch [-Wswitch] constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_TRIVIALLY_ASSIGNABLE’ not handled in switch [-Wswit\ constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_TRIVIALLY_CONSTRUCTIBLE’ not handled in switch [-Ws\ constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_TRIVIALLY_COPYABLE’ not handled in switch [-Wswitch\ constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_ASSIGNABLE’ not handled in switch [-Wswitch] constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_CONSTRUCTIBLE’ not handled in switch [-Wswitch] constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_NOTHROW_ASSIGNABLE’ not handled in switch [-Wswitch\ constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_NOTHROW_CONSTRUCTIBLE’ not handled in switch [-Wswi\ These we should. I think we should leave off the default so that when we add more traits we get a warning that we need to handle them here. 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) : 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 %", 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 000..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 +concept C = __is_constructible(T, Args...); // { dg-message "evaluated to 'false'" } +struct S { + S() = delete; +}; + +static_assert(C); // { dg-error "assert" }
[PATCH] c++: ICE with failed __is_constructible constraint [PR100474]
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) : 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 %", 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 000..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 +concept C = __is_constructible(T, Args...); // { dg-message "evaluated to 'false'" } +struct S { + S() = delete; +}; + +static_assert(C); // { dg-error "assert" } -- 2.35.1.677.gabf474a5dd