diff mbox series

c++: decltype of invalid non-dependent expr [PR57943]

Message ID 20200514201927.3787724-1-ppalka@redhat.com
State New
Headers show
Series c++: decltype of invalid non-dependent expr [PR57943] | expand

Commit Message

Patrick Palka May 14, 2020, 8:19 p.m. UTC
We sometimes fail to reject a invalid non-dependent operand to decltype
when inside a template, because finish_decltype_type resolves the
decltype to the TREE_TYPE of the operand before we ever instantiate and
fully process the operand.  Fix this by adding a call to
instantiate_non_dependent_expr_sfinae in finish_decltype_type.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK to
commit?

gcc/cp/ChangeLog:

	PR c++/57943
	* semantics.c (finish_decltype_type): Call
	instantiate_non_dependent_expr_sfinae on the decltype's operand.

gcc/testsuite/ChangeLog:

	PR c++/57943
	* g++.dg/cpp0x/decltype76.C: New test.
---
 gcc/cp/semantics.c                      | 8 ++++++++
 gcc/testsuite/g++.dg/cpp0x/decltype76.C | 7 +++++++
 2 files changed, 15 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/decltype76.C

Comments

Jason Merrill May 15, 2020, 9:55 p.m. UTC | #1
On 5/14/20 4:19 PM, Patrick Palka wrote:
> We sometimes fail to reject a invalid non-dependent operand to decltype
> when inside a template, because finish_decltype_type resolves the
> decltype to the TREE_TYPE of the operand before we ever instantiate and
> fully process the operand.  Fix this by adding a call to
> instantiate_non_dependent_expr_sfinae in finish_decltype_type.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK to
> commit?

OK.

> gcc/cp/ChangeLog:
> 
> 	PR c++/57943
> 	* semantics.c (finish_decltype_type): Call
> 	instantiate_non_dependent_expr_sfinae on the decltype's operand.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c++/57943
> 	* g++.dg/cpp0x/decltype76.C: New test.
> ---
>   gcc/cp/semantics.c                      | 8 ++++++++
>   gcc/testsuite/g++.dg/cpp0x/decltype76.C | 7 +++++++
>   2 files changed, 15 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/decltype76.C
> 
> diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
> index d90816eabc9..64587c791c6 100644
> --- a/gcc/cp/semantics.c
> +++ b/gcc/cp/semantics.c
> @@ -9746,6 +9746,14 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
>   
>         return type;
>       }
> +  else if (processing_template_decl)
> +    {
> +      ++cp_unevaluated_operand;
> +      expr = instantiate_non_dependent_expr_sfinae (expr, complain);
> +      --cp_unevaluated_operand;
> +      if (expr == error_mark_node)
> +	return error_mark_node;
> +    }
>   
>     /* The type denoted by decltype(e) is defined as follows:  */
>   
> diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype76.C b/gcc/testsuite/g++.dg/cpp0x/decltype76.C
> new file mode 100644
> index 00000000000..239fe6d2a8f
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/decltype76.C
> @@ -0,0 +1,7 @@
> +// PR c+/57943
> +// { dg-do compile { target c++11 } }
> +
> +struct a { };
> +
> +template <typename T = decltype (a(0))> // { dg-error "" }
> +void f() { }
>
diff mbox series

Patch

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index d90816eabc9..64587c791c6 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -9746,6 +9746,14 @@  finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
 
       return type;
     }
+  else if (processing_template_decl)
+    {
+      ++cp_unevaluated_operand;
+      expr = instantiate_non_dependent_expr_sfinae (expr, complain);
+      --cp_unevaluated_operand;
+      if (expr == error_mark_node)
+	return error_mark_node;
+    }
 
   /* The type denoted by decltype(e) is defined as follows:  */
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype76.C b/gcc/testsuite/g++.dg/cpp0x/decltype76.C
new file mode 100644
index 00000000000..239fe6d2a8f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/decltype76.C
@@ -0,0 +1,7 @@ 
+// PR c+/57943
+// { dg-do compile { target c++11 } }
+
+struct a { };
+
+template <typename T = decltype (a(0))> // { dg-error "" }
+void f() { }