diff mbox series

c++: ICE in requires-expressions with invalid args [PR95735]

Message ID 20200618151120.562874-1-polacek@redhat.com
State New
Headers show
Series c++: ICE in requires-expressions with invalid args [PR95735] | expand

Commit Message

Marek Polacek June 18, 2020, 3:11 p.m. UTC
This ICE-on-invalid goes back to GCC 6.  In finish_template_variable,
if coerce_innermost_template_parms returns error_mark_node, we pass
it down to constraints_satisfied_p and that error_mark_node flows
down to various satisfy_* functions and then to various tsubst_*
functions, where we crash.  diagnose_constraints also doesn't cope
with error arglist, so I think we should just return as in the
patch below.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

gcc/cp/ChangeLog:

	PR c++/95735
	* pt.c (finish_template_variable): Return if
	coerce_innermost_template_parms return error_mark_node.

gcc/testsuite/ChangeLog:

	PR c++/95735
	* g++.dg/cpp2a/concepts-err2.C: New test.
---
 gcc/cp/pt.c                                |  2 ++
 gcc/testsuite/g++.dg/cpp2a/concepts-err2.C | 11 +++++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-err2.C


base-commit: 72cb486456a39524c6f822327ba8654b0221ff4c

Comments

Jason Merrill June 18, 2020, 3:47 p.m. UTC | #1
On 6/18/20 11:11 AM, Marek Polacek wrote:
> This ICE-on-invalid goes back to GCC 6.  In finish_template_variable,
> if coerce_innermost_template_parms returns error_mark_node, we pass
> it down to constraints_satisfied_p and that error_mark_node flows
> down to various satisfy_* functions and then to various tsubst_*
> functions, where we crash.  diagnose_constraints also doesn't cope
> with error arglist, so I think we should just return as in the
> patch below.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

OK.

> gcc/cp/ChangeLog:
> 
> 	PR c++/95735
> 	* pt.c (finish_template_variable): Return if
> 	coerce_innermost_template_parms return error_mark_node.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c++/95735
> 	* g++.dg/cpp2a/concepts-err2.C: New test.
> ---
>   gcc/cp/pt.c                                |  2 ++
>   gcc/testsuite/g++.dg/cpp2a/concepts-err2.C | 11 +++++++++++
>   2 files changed, 13 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-err2.C
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 9732e3b78c7..1c0759edcae 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -10154,6 +10154,8 @@ finish_template_variable (tree var, tsubst_flags_t complain)
>     arglist = coerce_innermost_template_parms (parms, arglist, templ, complain,
>   					     /*req_all*/true,
>   					     /*use_default*/true);
> +  if (arglist == error_mark_node)
> +    return error_mark_node;
>   
>     if (flag_concepts && !constraints_satisfied_p (templ, arglist))
>       {
> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-err2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-err2.C
> new file mode 100644
> index 00000000000..c0372a6096b
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-err2.C
> @@ -0,0 +1,11 @@
> +// PR c++/95735
> +// { dg-do compile { target concepts } }
> +
> +template <auto F>
> +    requires requires { F(); }
> +bool v{};
> +
> +void f() {
> +    int x;
> +    static_assert(v<[&] { x++; }>); // { dg-error "not a constant expression" }
> +}
> 
> base-commit: 72cb486456a39524c6f822327ba8654b0221ff4c
>
diff mbox series

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 9732e3b78c7..1c0759edcae 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10154,6 +10154,8 @@  finish_template_variable (tree var, tsubst_flags_t complain)
   arglist = coerce_innermost_template_parms (parms, arglist, templ, complain,
 					     /*req_all*/true,
 					     /*use_default*/true);
+  if (arglist == error_mark_node)
+    return error_mark_node;
 
   if (flag_concepts && !constraints_satisfied_p (templ, arglist))
     {
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-err2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-err2.C
new file mode 100644
index 00000000000..c0372a6096b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-err2.C
@@ -0,0 +1,11 @@ 
+// PR c++/95735
+// { dg-do compile { target concepts } }
+
+template <auto F>
+    requires requires { F(); }
+bool v{};
+
+void f() {
+    int x;
+    static_assert(v<[&] { x++; }>); // { dg-error "not a constant expression" }
+}