diff mbox

[testsuite] replace bogus pointer-to-member test in gdb.cp/classes.exp

Message ID 5604A6E3.5020005@codesourcery.com
State New
Headers show

Commit Message

Sandra Loosemore Sept. 25, 2015, 1:44 a.m. UTC
While I was working on this patch

https://sourceware.org/ml/gdb-patches/2015-09/msg00566.html

to fix a regexp bug in gdb.cp/classes.exp, I also took a look at the 
long-standing failure involving the pmi comparison.  In addition to the 
uninitialized-variable problem noted in the comments (dating back to 
2004!), casting a pointer-to-member to an int and expecting it to have 
(or not have) any particular value seems highly dubious to me in terms 
of correctness and portability.  I also don't think it's representative 
of actual use cases involving pointer-to-member variables in the debugger.

This patch addresses the uninitialized variable and potential 
optimizing-away problems by moving the definition to file scope, and 
changes the test to just printing its value.

OK to commit?

-Sandra
diff mbox

Patch

diff --git a/gdb/testsuite/gdb.cp/classes.cc b/gdb/testsuite/gdb.cp/classes.cc
index 648452c..9fb687e 100644
--- a/gdb/testsuite/gdb.cp/classes.cc
+++ b/gdb/testsuite/gdb.cp/classes.cc
@@ -433,6 +433,7 @@  Foo::operator int() { return x; }
 
 ByAnyOtherName foo(10, 11);
 Bar bar(20, 21, 22);
+int Foo::* pmi = &Foo::y;
 
 /* Use a typedef for the baseclass to exercise gnu-v3-abi.c:gnuv3_dynamic_class
    recursion.  It's important that the class itself have no name to make sure
@@ -599,11 +600,6 @@  main()
   enums1 ();
   register_class ();
 
-  /* FIXME: pmi gets optimized out.  Need to do some more computation with
-     it or something.  (No one notices, because the test is xfail'd anyway,
-     but that probably won't always be true...).  */
-  int Foo::* pmi = &Foo::y;
-
   /* Make sure the AIX linker doesn't remove the variable.  */
   v_tagless.one = 5;
 
diff --git a/gdb/testsuite/gdb.cp/classes.exp b/gdb/testsuite/gdb.cp/classes.exp
index 00f16fc..9dab864 100644
--- a/gdb/testsuite/gdb.cp/classes.exp
+++ b/gdb/testsuite/gdb.cp/classes.exp
@@ -509,12 +509,7 @@  proc test_pointers_to_class_members {} {
     gdb_test "ptype Bar::z" "type = int"
     gdb_test "ptype &Bar::z" "type = int Bar::\\*"
 
-    # TODO: this is a bogus test.  It's looking at a variable that
-    # has not even been declared yet, so it's accessing random junk
-    # on the stack and comparing that it's NOT equal to a specific
-    # value.  It's been like this since gdb 4.10 in 1993!
-    # -- chastain 2004-01-01
-    gdb_test "print (int)pmi == sizeof(int)" ".* = false"
+    gdb_test "print pmi" "\\$\[0-9\]+ = &Foo::y"
 }
 
 # Test static members.