aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2022-03-30 10:13:11 -0400
committerPatrick Palka <ppalka@redhat.com>2022-03-30 10:13:11 -0400
commit3aaf9bf77047aecc23072fe3db7f13ecff72a7cf (patch)
treee15c7dfec64ccf61c1d69ad1b49ee016bebe37f6
parent6a777ceb0e975f0efc823d2d82e676346f068151 (diff)
downloadgcc-3aaf9bf77047aecc23072fe3db7f13ecff72a7cf.zip
gcc-3aaf9bf77047aecc23072fe3db7f13ecff72a7cf.tar.gz
gcc-3aaf9bf77047aecc23072fe3db7f13ecff72a7cf.tar.bz2
c++: ICE with failed __is_constructible constraint [PR100474]
Here we're crashing when diagnosing an unsatisfied __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 adding a new trait we'll get a warning that diagnose_trait_expr needs to handle it. 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.
-rw-r--r--gcc/cp/constraint.cc43
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C66
2 files changed, 108 insertions, 1 deletions
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index c5a991b..94f6222 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3654,8 +3654,49 @@ 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 %<nothrow%> 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 %<nothrow%> default constructible", t1);
+ else
+ inform (loc, " %qT is not %<nothrow%> constructible from %qE", t1, t2);
+ break;
+ case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
+ inform (loc, " %qT does not have unique object representations", t1);
+ break;
+ case CPTK_BASES:
+ case CPTK_DIRECT_BASES:
+ case CPTK_UNDERLYING_TYPE:
+ /* We shouldn't see these non-expression traits. */
gcc_unreachable ();
+ /* We deliberately omit the default case so that when adding a new
+ trait we'll get reminded (by way of a warning) to handle it here. */
}
}
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 0000000..f20608b6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C
@@ -0,0 +1,66 @@
+// PR c++/100474
+// { dg-do compile { target c++20 } }
+
+struct S { S() = delete; S(const S&); };
+
+template<class T>
+concept Aggregate = __is_aggregate(T);
+// { dg-message "'S' is not an aggregate" "" { target *-*-* } .-1 }
+
+template<class T>
+concept TriviallyCopyable = __is_trivially_copyable(T);
+// { dg-message "'S' is not trivially copyable" "" { target *-*-* } .-1 }
+
+template<class T, class U>
+concept Assignable = __is_assignable(T, U);
+// { dg-message "'S' is not assignable from 'int'" "" { target *-*-* } .-1 }
+
+template<class T, class U>
+concept TriviallyAssignable = __is_trivially_assignable(T, U);
+// { dg-message "'S' is not trivially assignable from 'int'" "" { target *-*-* } .-1 }
+
+template<class T, class U>
+concept NothrowAssignable = __is_nothrow_assignable(T, U);
+// { dg-message "'S' is not 'nothrow' assignable from 'int'" "" { target *-*-* } .-1 }
+
+template<class T, class... Args>
+concept Constructible = __is_constructible(T, Args...);
+// { dg-message "'S' is not default constructible" "" { target *-*-* } .-1 }
+// { dg-message "'S' is not constructible from 'int'" "" { target *-*-* } .-2 }
+// { dg-message "'S' is not constructible from 'int, char'" "" { target *-*-* } .-3 }
+
+template<class T, class... Args>
+concept TriviallyConstructible = __is_trivially_constructible(T, Args...);
+// { dg-message "'S' is not trivially default constructible" "" { target *-*-* } .-1 }
+// { dg-message "'S' is not trivially constructible from 'int'" "" { target *-*-* } .-2 }
+// { dg-message "'S' is not trivially constructible from 'int, char'" "" { target *-*-* } .-3 }
+
+template<class T, class... Args>
+concept NothrowConstructible = __is_nothrow_constructible(T, Args...);
+// { dg-message "'S' is not 'nothrow' default constructible" "" { target *-*-* } .-1 }
+// { dg-message "'S' is not 'nothrow' constructible from 'int'" "" { target *-*-* } .-2 }
+// { dg-message "'S' is not 'nothrow' constructible from 'int, char'" "" { target *-*-* } .-3 }
+
+template<class T>
+concept UniqueObjReps = __has_unique_object_representations(T);
+// { dg-message "'S' does not have unique object representations" "" { target *-*-* } .-1 }
+
+static_assert(Aggregate<S>); // { dg-error "assert" }
+static_assert(TriviallyCopyable<S>); // { dg-error "assert" }
+static_assert(Assignable<S, int>); // { dg-error "assert" }
+static_assert(TriviallyAssignable<S, int>); // { dg-error "assert" }
+static_assert(NothrowAssignable<S, int>); // { dg-error "assert" }
+
+static_assert(Constructible<S>); // { dg-error "assert" }
+static_assert(Constructible<S, int>); // { dg-error "assert" }
+static_assert(Constructible<S, int, char>); // { dg-error "assert" }
+
+static_assert(TriviallyConstructible<S>); // { dg-error "assert" }
+static_assert(TriviallyConstructible<S, int>); // { dg-error "assert" }
+static_assert(TriviallyConstructible<S, int, char>); // { dg-error "assert" }
+
+static_assert(NothrowConstructible<S>); // { dg-error "assert" }
+static_assert(NothrowConstructible<S, int>); // { dg-error "assert" }
+static_assert(NothrowConstructible<S, int, char>); // { dg-error "assert" }
+
+static_assert(UniqueObjReps<S>); // { dg-error "assert" }