From 6ef15591e356a69b0a573c207d5a254124dbad0e Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 17 Dec 2015 11:51:52 -0500 Subject: [PATCH] re PR c++/67576 (expression of typeid( expression ) is evaluated twice) PR c++/67576 PR c++/25466 * rtti.c (build_typeid): Use save_expr, not stabilize_reference. From-SVN: r231776 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/rtti.c | 2 +- gcc/testsuite/g++.dg/rtti/typeid11.C | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/rtti/typeid11.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a192f00713d..73906f3cb12 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-12-17 Jason Merrill + + PR c++/67576 + PR c++/25466 + * rtti.c (build_typeid): Use save_expr, not stabilize_reference. + 2015-12-16 Patrick Palka PR c++/16333 diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index b397b55b78c..f42b1cbf922 100644 --- a/gcc/cp/rtti.c +++ b/gcc/cp/rtti.c @@ -332,7 +332,7 @@ build_typeid (tree exp, tsubst_flags_t complain) /* So we need to look into the vtable of the type of exp. Make sure it isn't a null lvalue. */ exp = cp_build_addr_expr (exp, complain); - exp = stabilize_reference (exp); + exp = save_expr (exp); cond = cp_convert (boolean_type_node, exp, complain); exp = cp_build_indirect_ref (exp, RO_NULL, complain); } diff --git a/gcc/testsuite/g++.dg/rtti/typeid11.C b/gcc/testsuite/g++.dg/rtti/typeid11.C new file mode 100644 index 00000000000..384b0f41705 --- /dev/null +++ b/gcc/testsuite/g++.dg/rtti/typeid11.C @@ -0,0 +1,16 @@ +// { dg-do run } + +#include + +struct Base { virtual void foo() {} }; // polymorphic + +int main() +{ + Base b; + Base *ary[] = { &b, &b, &b}; + + int iter = 0; + typeid(*ary[iter++]); + if (iter != 1) // should be 1 + __builtin_abort(); // but 2 +} -- 2.30.2