Fix PR c++/70096 (wrong code for pointer-to-member-function copy)

gcc/cp/ChangeLog:

	PR c++/70096
	* pt.c (tsubst_decl): Clear the DECL_MODE of the new decl.

gcc/testsuite/ChangeLog:

	PR c++/70096
	* g++.dg/template/ptrmem30.C: New test.

From-SVN: r234391
This commit is contained in:
Patrick Palka 2016-03-22 02:02:01 +00:00
parent a3e2b43831
commit 16f6d7dc5c
4 changed files with 57 additions and 0 deletions

View File

@ -1,3 +1,8 @@
2016-03-22 Patrick Palka <ppalka@gcc.gnu.org>
PR c++/70096
* pt.c (tsubst_decl): Clear the DECL_MODE of the new decl.
2016-03-22 Patrick Palka <ppalka@gcc.gnu.org>
PR c++/70204

View File

@ -12374,6 +12374,8 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
/* The initializer must not be expanded until it is required;
see [temp.inst]. */
DECL_INITIAL (r) = NULL_TREE;
if (VAR_P (r))
DECL_MODE (r) = VOIDmode;
if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL))
SET_DECL_RTL (r, NULL);
DECL_SIZE (r) = DECL_SIZE_UNIT (r) = 0;

View File

@ -1,3 +1,8 @@
2016-03-22 Patrick Palka <ppalka@gcc.gnu.org>
PR c++/70096
* g++.dg/template/ptrmem30.C: New test.
2016-03-22 Patrick Palka <ppalka@gcc.gnu.org>
PR c++/70204

View File

@ -0,0 +1,45 @@
// PR c++/70096
// { dg-do run }
int read;
struct Holder
{
void foo () { read = data; }
int data;
};
void
poison_stack ()
{
volatile char a[256];
__builtin_memset ((void *)a, 0xa, sizeof a);
}
template <typename F>
void test1 ()
{
Holder h;
h.data = 42;
F Holder::*fptr = &Holder::foo;
(h.*fptr)();
}
template <typename F>
void test2 ()
{
Holder h;
h.data = 42;
F Holder::*fptr1 = &Holder::foo;
F Holder::*fptr2 = fptr1;
(h.*fptr2)();
}
int main ()
{
poison_stack ();
test1<void()>();
poison_stack ();
test2<void()>();
}