This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

g++.old-deja/g++.mike/p7325.C - suspected bogus test case


Test case g++.old-deja/g++.mike/p7325.C (appended to this message, for
reference) appears to be invalid.

In the function f(), we call A::operator= twice; operator= expects its
'o' argument to be at the same address both times.  f is passing in
the return value of foo(), which is an A.  The compiler is free to
implement this by copying A to a temporary - either in f, or in
A::operator= when the address is taken.  So there is no reason to
expect that the address will be the same both times (nor is there
reason to expect that it won't).

Similarly, in g(), all three invocations of A::A() involve the
implicit creation of stack temporaries, which may or may not have the
same address (since their lifetimes are disjoint).

I do not know what this test was intended to test.  It has seen only
trivial changes since the creation of the EGCS CVS repository (there
was a brief period around the beginning of 1998 when it wasn't XFAIL).
The cited PR number does not refer to our bugzilla database.  It's
probably referring to Cygnus's old internal GNATS database, which I do
not have access to (if it even still exists).  It is possible that
someone was trying to test that the compiler reused stack slots for
temporaries with overlapping lifetimes, which is all well and good,
but this is not the way to do it (a really clever optimizer might
notice that a pointer escaped, and deliberately not reuse the stack
slot).

Why do I care?  Because it XPASSes on ia64-hpux due to vagaries of the
platform ABI, and I'm tired of the noise in my test results.  I
propose to delete it off mainline and 3.4 branch.

zw

// { dg-do run { xfail *-*-* } }
// I hate this type of test case.  I'm not sure how to code it better.
// See the PR for what this tests.
// prms-id: 7325

int fail = 0;

struct A {
  int i;
  static const A* match_this;
  static const A* match_arg;
  A(): i(7) {
    if (match_this)
      if (match_this != this)
	fail = 1;
  }
  A* get_this() { return this; }
  A& operator = (const A& o) {
    if (match_this)
      if (match_this != this)
	fail = 1;
    if (match_arg)
      if (match_arg != &o)
	fail = 1;
    match_arg = &o;
    return *this;
  }
};

const A* A::match_this;
const A* A::match_arg;
A a;

A foo() { return a; }
void f ()
{
  A a;
  A::match_this = &a;
  a = foo ();
  a = foo ();
  A::match_this = 0;
}

void g ()
{
  A::match_this = A().get_this();
  A();
  A();
  A::match_this = 0;
}

int main() {
  f();
  g();
  return fail;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]