public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: non-dependent .* folding [PR112427]
@ 2023-11-08 21:59 Patrick Palka
  2023-11-10  0:28 ` Jason Merrill
  0 siblings, 1 reply; 7+ messages in thread
From: Patrick Palka @ 2023-11-08 21:59 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?

-- >8 --

Here when building up the non-dependent .* expression, we crash from
fold_convert on 'b.a' due to this (templated) COMPONENT_REF having an
IDENTIFIER_NODE instead of FIELD_DECL operand that middle-end routines
expect.  Like in r14-4899-gd80a26cca02587, this patch fixes this by
replacing the problematic piecemeal folding with a single call to
cp_fully_fold.

	PR c++/112427

gcc/cp/ChangeLog:

	* typeck2.cc (build_m_component_ref): Use cp_convert, build2 and
	cp_fully_fold instead of fold_build_pointer_plus and fold_convert.

gcc/testsuite/ChangeLog:

	* g++.dg/template/non-dependent29.C: New test.
---
 gcc/cp/typeck2.cc                               |  5 ++++-
 gcc/testsuite/g++.dg/template/non-dependent29.C | 13 +++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/template/non-dependent29.C

diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc
index 309903afed8..208004221da 100644
--- a/gcc/cp/typeck2.cc
+++ b/gcc/cp/typeck2.cc
@@ -2378,7 +2378,10 @@ build_m_component_ref (tree datum, tree component, tsubst_flags_t complain)
       /* Build an expression for "object + offset" where offset is the
 	 value stored in the pointer-to-data-member.  */
       ptype = build_pointer_type (type);
-      datum = fold_build_pointer_plus (fold_convert (ptype, datum), component);
+      datum = cp_convert (ptype, datum, complain);
+      datum = build2 (POINTER_PLUS_EXPR, ptype,
+		      datum, convert_to_ptrofftype (component));
+      datum = cp_fully_fold (datum);
       datum = cp_build_fold_indirect_ref (datum);
       if (datum == error_mark_node)
 	return error_mark_node;
diff --git a/gcc/testsuite/g++.dg/template/non-dependent29.C b/gcc/testsuite/g++.dg/template/non-dependent29.C
new file mode 100644
index 00000000000..41bd11ae6b4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/non-dependent29.C
@@ -0,0 +1,13 @@
+// PR c++/112427
+
+struct A { int m; void f(); };
+struct B { A a; };
+
+template<class T>
+void f(B b) {
+  int A::*pd = &A::m;
+  b.a.*pd;
+
+  void (A::*pf)() = &A::f;
+  (b.a.*pf)();
+}
-- 
2.43.0.rc1


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

end of thread, other threads:[~2023-11-14 22:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-08 21:59 [PATCH] c++: non-dependent .* folding [PR112427] Patrick Palka
2023-11-10  0:28 ` Jason Merrill
2023-11-10 15:12   ` Patrick Palka
2023-11-10 15:28     ` Patrick Palka
2023-11-10 21:36       ` Jason Merrill
2023-11-14 15:43         ` Patrick Palka
2023-11-14 22:29           ` 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).