public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: address of NTTP object as targ [PR113242]
@ 2024-01-05 16:50 Patrick Palka
  2024-01-15 19:34 ` Patrick Palka
  2024-01-15 21:00 ` Jason Merrill
  0 siblings, 2 replies; 5+ messages in thread
From: Patrick Palka @ 2024-01-05 16:50 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
for trunk and perhaps 13?

-- >8 --

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

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.
---
 gcc/cp/pt.cc                                 |  3 ++-
 gcc/testsuite/g++.dg/cpp2a/nontype-class61.C | 27 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class61.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 154ac76cb65..8c7d178328d 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -7219,7 +7219,8 @@ 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_NTTP_OBJECT_P (decl)
+		 && DECL_ARTIFICIAL (decl))
 	  {
 	    if (complain & tf_error)
 	      error ("the address of %qD is not a valid template argument",
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..90805a05ecf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class61.C
@@ -0,0 +1,27 @@
+// 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>();
+}
-- 
2.43.0.254.ga26002b628


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-17 16:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-05 16:50 [PATCH] c++: address of NTTP object as targ [PR113242] Patrick Palka
2024-01-15 19:34 ` Patrick Palka
2024-01-15 21:00 ` Jason Merrill
2024-01-17 15:43   ` Patrick Palka
2024-01-17 16:34     ` Jason Merrill

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