Patchwork Fix an invalid C++ testcase

login
register
mail settings
Submitter Bernd Schmidt
Date April 24, 2013, 10:12 a.m.
Message ID <5177B00A.8060701@codesourcery.com>
Download mbox | patch
Permalink /patch/239133/
State New
Headers show

Comments

Bernd Schmidt - April 24, 2013, 10:12 a.m.
The pr8781.C testcase appears to have undefined behaviour as far as I
can tell. A function called noop is called with argument pred; this
creates a noop_t object which stores a reference to that argument, and
then the function returns the object. At that point I think the
reference becomes stale. This seems to be fixable by changing the pred
argument to be a reference itself.

Normally, inlining fixes up the situation, but this showed up as a
problem on a port where inlining was more difficult than usual.

Bootstrapped and tested on x86_64-linux. Ok?


Bernd

Patch

	* g++.dg/tree-ssa/pr8781.C (noop): Make argument a reference.

diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr8781.C b/gcc/testsuite/g++.dg/tree-ssa/pr8781.C
index cc518a0..a6050c4 100644
--- a/gcc/testsuite/g++.dg/tree-ssa/pr8781.C
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr8781.C
@@ -13,7 +13,7 @@  public:
 };
 
 template<typename predicate>
-inline noop_t<predicate> noop(const predicate pred) {
+inline noop_t<predicate> noop(const predicate &pred) {
     return noop_t<predicate>(pred);
 }