public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Patrick Palka <ppalka@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org, jason@redhat.com
Subject: Re: [PATCH] c++: sizeof(expr) in non-templated requires-expr [PR108563]
Date: Thu, 9 Feb 2023 13:22:35 -0500 (EST)	[thread overview]
Message-ID: <54df93ff-b7ff-4e2f-ce94-84643cde01fe@idea> (raw)
In-Reply-To: <20230209181722.3178411-1-ppalka@redhat.com>

On Thu, 9 Feb 2023, Patrick Palka wrote:

> When substituting into sizeof(expr), tsubst_copy_and_build elides
> substitution into the operand if args is NULL_TREE, and instead
> considers the TREE_TYPE of the operand.  But here the (templated)
> operand is a TEMPLATE_ID_EXPR with empty TREE_TYPE, so we can't elide
> substitution in this case.
> 
> Contrary to the associated comment (dating back to r69130) substituting
> args=NULL_TREE should generally work since we do exactly that in e.g.
> fold_non_dependent_expr, and I don't see why the operand of sizeof would
> be an exception.  So this patch just removes this special case.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?  Diff generated with -w to ignore noisy whitespace changes.

This time with -w actually passed to format-patch:

-- >8 --

	PR c++/108563

gcc/cp/ChangeLog:

	* pt.cc (tsubst_copy_and_build) <case SIZEOF_EXPR>: Remove
	special case for empty args.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-requires35.C: New test.
---
 gcc/cp/pt.cc                                     | 11 -----------
 gcc/testsuite/g++.dg/cpp2a/concepts-requires35.C | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 11 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires35.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 9f3fc1fa089..f21d28263d1 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -20652,16 +20652,6 @@ tsubst_copy_and_build (tree t,
 	  op1 = TREE_TYPE (op1);
 	bool std_alignof = (TREE_CODE (t) == ALIGNOF_EXPR
 			    && ALIGNOF_EXPR_STD_P (t));
-        if (!args)
-	  {
-	    /* When there are no ARGS, we are trying to evaluate a
-	       non-dependent expression from the parser.  Trying to do
-	       the substitutions may not work.  */
-	    if (!TYPE_P (op1))
-	      op1 = TREE_TYPE (op1);
-	  }
-	else
-	  {
 	++cp_unevaluated_operand;
 	++c_inhibit_evaluation_warnings;
 	if (TYPE_P (op1))
@@ -20670,7 +20660,6 @@ tsubst_copy_and_build (tree t,
 	  op1 = tsubst_copy_and_build (op1, args, complain, in_decl);
 	--cp_unevaluated_operand;
 	--c_inhibit_evaluation_warnings;
-	  }
         if (TYPE_P (op1))
 	  r = cxx_sizeof_or_alignof_type (input_location,
 					  op1, TREE_CODE (t), std_alignof,
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires35.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires35.C
new file mode 100644
index 00000000000..2bb4b2b0b5d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires35.C
@@ -0,0 +1,14 @@
+// PR c++/108563
+// { dg-do compile { target c++20 } }
+
+template<class T>
+struct foo {
+  static constexpr T value = 0;
+};
+
+template<class T>
+inline constexpr T foo_v = foo<T>::value;
+
+static_assert(requires { sizeof(foo_v<int>); });
+static_assert(requires { requires sizeof(foo_v<int*>) == sizeof(int*); });
+static_assert(requires { requires sizeof(foo_v<char>) == sizeof(char); });
-- 
2.39.1.418.g7876265d61


  reply	other threads:[~2023-02-09 18:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-09 18:17 Patrick Palka
2023-02-09 18:22 ` Patrick Palka [this message]
2023-02-14 23:02   ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54df93ff-b7ff-4e2f-ce94-84643cde01fe@idea \
    --to=ppalka@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).