public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2883] c++: fix ptrmemfunc template instantiation [PR101219]
@ 2021-08-12 18:44 Sergei Trofimovich
  0 siblings, 0 replies; only message in thread
From: Sergei Trofimovich @ 2021-08-12 18:44 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:27a1fb385b7fe706f05608e53f3e91d7d3442b8b

commit r12-2883-g27a1fb385b7fe706f05608e53f3e91d7d3442b8b
Author: Sergei Trofimovich <siarheit@google.com>
Date:   Fri Aug 6 16:14:16 2021 +0100

    c++: fix ptrmemfunc template instantiation [PR101219]
    
    r12-1804 ("cp: add support for per-location warning groups.") among other
    things removed warning suppression from a few places including ptrmemfuncs.
    
    This exposed a bug in warning detection code as a reference to missing
    BINFO (it's intentionally missing for ptrmemfunc types):
    
        crash_signal
            gcc/toplev.c:328
        perform_or_defer_access_check(tree_node*, tree_node*, tree_node*, int, access_failure_info*)
            gcc/cp/semantics.c:490
        finish_non_static_data_member(tree_node*, tree_node*, tree_node*)
            gcc/cp/semantics.c:2208
        ...
    
    The change special cases ptrmemfuncs in templace substitution by using
    build_ptrmemfunc_access_expr() instead of finish_non_static_data_member().
    
    gcc/cp/ChangeLog:
    
            PR c++/101219
            * pt.c (tsubst_copy_and_build): Use build_ptrmemfunc_access_expr
            to construct ptrmemfunc expression instantiation.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/101219
            * g++.dg/warn/pr101219.C: New test.

Diff:
---
 gcc/cp/pt.c                          |  8 +++++++-
 gcc/testsuite/g++.dg/warn/pr101219.C | 11 +++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b396ddd0089..42ea51cebc0 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20530,7 +20530,13 @@ tsubst_copy_and_build (tree t,
 	if (member == error_mark_node)
 	  RETURN (error_mark_node);
 
-	if (TREE_CODE (member) == FIELD_DECL)
+	if (object_type && TYPE_PTRMEMFUNC_P (object_type)
+	    && TREE_CODE (member) == FIELD_DECL)
+	  {
+	    r = build_ptrmemfunc_access_expr (object, DECL_NAME (member));
+	    RETURN (r);
+	  }
+	else if (TREE_CODE (member) == FIELD_DECL)
 	  {
 	    r = finish_non_static_data_member (member, object, NULL_TREE);
 	    if (TREE_CODE (r) == COMPONENT_REF)
diff --git a/gcc/testsuite/g++.dg/warn/pr101219.C b/gcc/testsuite/g++.dg/warn/pr101219.C
new file mode 100644
index 00000000000..0d23d73c9ec
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/pr101219.C
@@ -0,0 +1,11 @@
+/* PR c++/101219 - ICE on use of uninitialized memfun pointer
+   { dg-do compile }
+   { dg-options "-Wall" } */
+
+struct S { void m(); };
+
+template <int> bool f() {
+  void (S::*mp)();
+
+  return &S::m == mp; // no warning emitted here (no instantiation)
+}


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

only message in thread, other threads:[~2021-08-12 18:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 18:44 [gcc r12-2883] c++: fix ptrmemfunc template instantiation [PR101219] Sergei Trofimovich

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