public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-8235] c++: address of class NTTP object as targ [PR113242]
Date: Thu, 18 Jan 2024 15:53:44 +0000 (GMT)	[thread overview]
Message-ID: <20240118155345.5F6C83858D33@sourceware.org> (raw)

https://gcc.gnu.org/g:4ffb23975b32bfd285915c3d6659b837868b5aa9

commit r13-8235-g4ffb23975b32bfd285915c3d6659b837868b5aa9
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Jan 17 13:01:01 2024 -0500

    c++: address of class NTTP object as targ [PR113242]
    
    invalid_tparm_referent_p was rejecting using the address of a class NTTP
    object as a template argument, but this should be fine.
    
            PR c++/113242
            PR c++/99493
    
    gcc/cp/ChangeLog:
    
            * pt.cc (invalid_tparm_referent_p) <case ADDR_EXPR>: Suppress
            DECL_ARTIFICIAL rejection test for class NTTP objects.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/nontype-class61.C: New test.
            * g++.dg/cpp2a/nontype-class62.C: New test.
    
    Reviewed-by: Jason Merrill <jason@redhat.com>
    (cherry picked from commit 68cea2d32a9fd525154b6a48042e5835d4c5e371)

Diff:
---
 gcc/cp/pt.cc                                 |  4 +++-
 gcc/testsuite/g++.dg/cpp2a/nontype-class61.C | 25 +++++++++++++++++++++++++
 gcc/testsuite/g++.dg/cpp2a/nontype-class62.C |  8 ++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index c04dd8f8fbd..3214ce8df49 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -7180,8 +7180,10 @@ invalid_tparm_referent_p (tree type, tree expr, tsubst_flags_t complain)
 	   * a string literal (5.13.5),
 	   * the result of a typeid expression (8.2.8), or
 	   * a predefined __func__ variable (11.4.1).  */
-	else if (VAR_P (decl) && DECL_ARTIFICIAL (decl))
+	else if (VAR_P (decl) && DECL_ARTIFICIAL (decl)
+		 && !DECL_NTTP_OBJECT_P (decl))
 	  {
+	    gcc_checking_assert (DECL_TINFO_P (decl) || DECL_FNAME_P (decl));
 	    if (complain & tf_error)
 	      error ("the address of %qD is not a valid template argument",
 		     decl);
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class61.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class61.C
new file mode 100644
index 00000000000..4033cf0f271
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class61.C
@@ -0,0 +1,25 @@
+// PR c++/113242
+// { dg-do compile { target c++20 } }
+
+struct wrapper { int n; };
+
+template<const wrapper& X>
+void f1() {
+  static_assert(X.n == 42);
+}
+
+template<const wrapper* X>
+void f2() {
+  static_assert(X->n == 42);
+}
+
+template<wrapper X>
+void g() {
+  f1<X>();
+  f2<&X>();
+}
+
+int main() {
+  constexpr wrapper X = {42};
+  g<X>();
+}
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class62.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class62.C
new file mode 100644
index 00000000000..f5068fbd009
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class62.C
@@ -0,0 +1,8 @@
+// PR c++/99493
+// { dg-do compile { target c++20 } }
+
+struct owner{int m;};
+struct view{const int*m;constexpr view(const owner&o):m{&o.m}{}};
+template<view V>struct constant{};
+template<owner O>constexpr constant<O>v{};
+constexpr auto a=v<owner{}>;

                 reply	other threads:[~2024-01-18 15:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240118155345.5F6C83858D33@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).