PR symtab/12704
authorKeith Seitz <keiths@redhat.com>
Tue, 31 May 2011 21:54:49 +0000 (21:54 +0000)
committerKeith Seitz <keiths@redhat.com>
Tue, 31 May 2011 21:54:49 +0000 (21:54 +0000)
* gdb.cp/anon-ns.cc: New file.
* gdb.cp/anon-ns.exp: New file.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.cp/anon-ns.cc [new file with mode: 0644]
gdb/testsuite/gdb.cp/anon-ns.exp [new file with mode: 0644]

index 3d89273..2e5e4cb 100644 (file)
@@ -1,3 +1,9 @@
+2010-05-31  Keith Seitz  <keiths@redhat.com>
+
+       PR symtab/12704
+       * gdb.cp/anon-ns.cc: New file.
+       * gdb.cp/anon-ns.exp: New file.
+
 2011-05-31  Pedro Alves  <pedro@codesourcery.com>
 
        * gdb.arch/i386-dr3-watch.c: New file.
diff --git a/gdb/testsuite/gdb.cp/anon-ns.cc b/gdb/testsuite/gdb.cp/anon-ns.cc
new file mode 100644 (file)
index 0000000..949754d
--- /dev/null
@@ -0,0 +1,92 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+   Contributed by Red Hat, originally written by Keith Seitz.  */
+
+#include <stdlib.h>
+
+namespace
+{
+  void doit1 (void) { } // doit1(void)
+  void doit1 (int a) { } // doit1(int)
+  void doit1 (char *a) { } // doit1(char *)
+
+  class one
+  {
+  public:
+    one (void) { } // one::one(void)
+    one (int a) { } // one::one(int)
+    one (char *a) { } // one::one(char *)
+    static void doit (void) { } // one::doit(void)
+  };
+
+  namespace A
+  {
+    void doit2 (void) { } // A::doit2(void)
+    void doit2 (int a) { } // A::doit2(int)
+    void doit2 (char *a) { } // A::doit2(char *)
+
+    class two
+    {
+    public:
+      two (void) { } // A::two::two(void)
+      two (int a) { } // A::two::two(int)
+      two (char *a) { } // A::two::two(char *)
+      static void doit (void) { } // A::two::doit(void)
+    };
+
+    namespace
+    {
+      namespace
+      {
+       void doit3 (void) { } // A::doit3(void)
+       void doit3 (int a) { } // A::doit3(int)
+       void doit3 (char *a) { } // A::doit3(char *)
+
+       class three
+       {
+       public:
+         three (void) { } // A::three::three(void)
+         three (int a) { } // A::three::three(int)
+         three (char *a) { } // A::three::three(char *)
+         static void doit (void) { } // A::three::doit(void)
+       };
+      }
+    }
+  }
+}
+
+int
+main (void)
+{
+  one a, b (3), c (static_cast<char *> (NULL));
+  one::doit ();
+  A::two d, e (3), f (static_cast<char *> (NULL));
+  A::two::doit ();
+  A::three g, h (3), i (static_cast<char *> (NULL));
+  A::three::doit ();
+  doit1 ();
+  doit1 (3);
+  doit1 (static_cast<char *> (NULL));
+  A::doit2 ();
+  A::doit2 (3);
+  A::doit2 (static_cast<char *> (NULL));
+  A::doit3 ();
+  A::doit3 (3);
+  A::doit3 (static_cast<char *> (NULL));
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/anon-ns.exp b/gdb/testsuite/gdb.cp/anon-ns.exp
new file mode 100644 (file)
index 0000000..07d804c
--- /dev/null
@@ -0,0 +1,70 @@
+# Copyright 2011 Free Software Foundation, Inc.
+#
+# Contributed by Red Hat, originally written by Keith Seitz.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the gdb testsuite.
+
+if {[skip_cplus_tests]} { continue }
+
+# Tests for c++/12750/12704
+set testfile "anon-ns"
+set srcfile $testfile.cc
+
+if {[prepare_for_testing $testfile $testfile $srcfile {c++ debug}]} {
+    return -1
+}
+
+if {![runto_main]} {
+    perror "couldn't run to breakpoint"
+    continue
+}
+
+set ans {(anonymous namespace)}
+set types {"void" "int" "char *"}
+set methods {}
+foreach t $types {
+    lappend methods "${ans}::doit1($t)"
+    lappend methods "${ans}::one::one($t)"
+    lappend methods "${ans}::A::doit2($t)"
+    lappend methods "${ans}::A::two::two($t)"
+    lappend methods "${ans}::A::${ans}::${ans}::doit3($t)"
+    lappend methods "${ans}::A::${ans}::${ans}::three::three($t)"
+}
+
+lappend methods "${ans}::one::doit(void)"
+lappend methods "${ans}::A::two::doit(void)"
+lappend methods "${ans}::A::${ans}::${ans}::three::doit(void)"
+
+gdb_test_no_output "set listsize 1" ""
+
+foreach test $methods {
+    # The result we expect is the source code name of the symbol,
+    # i.e., without "(anonymous namespace)".
+    regsub -all [string_to_regexp "${ans}::"] $test "" expected
+    set result ".*// [string_to_regexp $expected]"
+
+    gdb_test "list $test" $result
+    gdb_test "list '$test'" $result
+    if {[gdb_breakpoint $test]} {
+       pass "break $test"
+    }
+    if {[gdb_breakpoint '$test']} {
+       pass "break '$test'"
+    }
+}
+
+gdb_exit
+return 0