public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] cp: Allow converted constant expressions to INTCAP_TYPE
@ 2022-11-22 22:18 Alex Coplan
  0 siblings, 0 replies; only message in thread
From: Alex Coplan @ 2022-11-22 22:18 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:605b79c1e1a10a565d42070f5069c7167fd52ec4

commit 605b79c1e1a10a565d42070f5069c7167fd52ec4
Author: Alex Coplan <alex.coplan@arm.com>
Date:   Tue Nov 15 17:53:03 2022 +0000

    cp: Allow converted constant expressions to INTCAP_TYPE
    
    This allows conversions between intcap and integer types in both
    directions in the context of converted constant expressions. There was
    an unjustified asymmetry in how we handled this before, causing the
    testcase added with this patch to be rejected.

Diff:
---
 gcc/cp/call.c                                | 3 ++-
 gcc/cp/pt.c                                  | 1 +
 gcc/testsuite/g++.dg/template/intptr-param.C | 4 ++++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index bd5dea9ed24..18990dcb359 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4417,7 +4417,8 @@ build_converted_constant_expr_internal (tree type, tree expr,
 	  t = next_conversion (c)->type;
 	  if ((INTEGRAL_OR_ENUMERATION_TYPE_P (t)
 	       || INTCAP_TYPE_P (t))
-	      && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
+	      && (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
+		  || INTCAP_TYPE_P (type)))
 	    /* Integral promotion or conversion.  */
 	    break;
 	  if (NULLPTR_TYPE_P (t))
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 9957c11034f..69d48892d25 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -7213,6 +7213,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
 	   to leave it in that form rather than lower it to a
 	   CONSTRUCTOR.  */;
       else if (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
+	       || INTCAP_TYPE_P (type)
 	       || cxx_dialect >= cxx17)
 	{
 	  /* C++17: A template-argument for a non-type template-parameter shall
diff --git a/gcc/testsuite/g++.dg/template/intptr-param.C b/gcc/testsuite/g++.dg/template/intptr-param.C
new file mode 100644
index 00000000000..b9ca2a89a76
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/intptr-param.C
@@ -0,0 +1,4 @@
+// { dg-do compile }
+template<__INTPTR_TYPE__ x>
+int f() { return x; }
+int g() { return f<1>(); }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-22 22:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22 22:18 [gcc(refs/vendors/ARM/heads/morello)] cp: Allow converted constant expressions to INTCAP_TYPE Alex Coplan

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).