From: Jakub Jelinek Date: Sat, 15 May 2010 20:23:59 +0000 (+0200) Subject: re PR c++/44148 (C++ genericization/gimplification may clobber templare arguments) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1f9109426d0b24206fd90c1b46f73bf9f5ee0685;p=gcc.git re PR c++/44148 (C++ genericization/gimplification may clobber templare arguments) PR c++/44148 * pt.c (tsubst): Unshare template argument. * g++.dg/torture/pr44148.C: New test. From-SVN: r159443 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1f56ae0b503..fda48be1907 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2010-05-15 Jakub Jelinek + + PR c++/44148 + * pt.c (tsubst): Unshare template argument. + 2010-05-15 Steven Bosscher * decl.c: Include tree-iterator.h, as fixup for tree-inline.h changes. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1ff1fe2b577..7a66d367826 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10150,7 +10150,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) } else /* TEMPLATE_TEMPLATE_PARM or TEMPLATE_PARM_INDEX. */ - return arg; + return unshare_expr (arg); } if (level == 1) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2ee5942ebd2..b41cfacc2de 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-05-15 Jakub Jelinek + + PR c++/44148 + * g++.dg/torture/pr44148.C: New test. + 2010-05-15 Joseph Myers * gcc.dg/c1x-anon-struct-1.c, gcc.dg/c1x-anon-struct-2.c, diff --git a/gcc/testsuite/g++.dg/torture/pr44148.C b/gcc/testsuite/g++.dg/torture/pr44148.C new file mode 100644 index 00000000000..a60ba9aa3a6 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr44148.C @@ -0,0 +1,60 @@ +// PR c++/44148 +// { dg-do compile } +// { dg-options "" } +// { dg-options "-fpic" { target fpic } } + +template struct S2 +{ + typedef const T &t2; + t2 operator* () const {} +}; +template struct S3 +{ + typedef S2 t5; +}; +template T2 foo1 (T1 x, T2 y) { y (*x); } +template struct S4 +{ + T &operator* () const; +}; +struct S7 {}; +struct S8 +{ + typedef::S3 >::t5 t6; + t6 m1 () const; +}; +template struct S9 +{ + typedef T t3; + inline t3 &operator[] (unsigned int) {} +}; +template struct S10 +{ + S10 (T2 &x, unsigned int y = 0) : u (x), v (y) {} + void operator () (const S4 &x) { T4 (*x, u[v++]); } + T2 &u; + unsigned int v; +}; +struct S15; +struct S11 +{ + static void m3 (const S8 &, S15 &); +}; +struct S16; +struct S12; +struct S13 +{ + static void m4 (const S7 &,S16 &); +}; +typedef S10 t10; +struct S12: S9 +{ +}; +struct S15 +{ + S12 p; +}; +void S11::m3 (const S8 &x, S15 &y) +{ + foo1 (x.m1 (), t10 (y.p)); +}