From 8a998f3a681afa866d709ab13c019d73ac663f30 Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Wed, 19 Apr 2017 10:18:23 -0700 Subject: [PATCH] Fix cut-n-paste-o comment in compile_cplus_instance::leave_scope. Also add tests for (real) anonymous struct and union. Introduces six new FAILs. --- gdb/compile/compile-cplus-types.c | 5 +- .../gdb.compile/cp-simple-anonymous.cc | 79 +++++++++++-------- .../gdb.compile/cp-simple-anonymous.exp | 2 + 3 files changed, 48 insertions(+), 38 deletions(-) diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c index 084d94d0754..a91ac5b94bf 100644 --- a/gdb/compile/compile-cplus-types.c +++ b/gdb/compile/compile-cplus-types.c @@ -370,8 +370,7 @@ compile_cplus_instance::leave_scope () if (debug_compile_cplus_scopes) printf_unfiltered ("leaving scope %p\n", current); - /* Pop namespaces. Do not push the last scope_component -- that's - the type we are converting, not a namespace. */ + /* Pop namespaces. */ std::for_each (current.begin (),current.end () - 1, [this] (const auto &comp) { gdb_assert (TYPE_CODE (SYMBOL_TYPE (comp.bsymbol.symbol)) @@ -1631,8 +1630,6 @@ ccp_convert_namespace (compile_cplus_instance *instance, if (TYPE_NAME (type) != NULL) name = cp_func_name (TYPE_NAME (type)); - else - name = xstrdup (""); // !!keiths: anonymous namespace?! /* Push scope. */ instance->enter_scope (scope); diff --git a/gdb/testsuite/gdb.compile/cp-simple-anonymous.cc b/gdb/testsuite/gdb.compile/cp-simple-anonymous.cc index d604339feb6..c7970586893 100644 --- a/gdb/testsuite/gdb.compile/cp-simple-anonymous.cc +++ b/gdb/testsuite/gdb.compile/cp-simple-anonymous.cc @@ -13,45 +13,56 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -static enum {ABC = 1, DEF, GHI, JKL} anon_e = GHI; -static union -{ - char aa; - int bb; - float ff; - double dd; - void *pp; -} anon_u = { 'a' }; - -static struct -{ - char *ptr; - int len; -} anon_s = {"abracadabra", 11}; - -struct A -{ - A (void) : e (AA) +namespace { + static enum {ABC = 1, DEF, GHI, JKL} anon_e = GHI; + static union { - this->u.b = 0; - this->s.ptr = "hello"; - this->s.len = 5; - } + char aa; + int bb; + float ff; + double dd; + void *pp; + } anon_u = { 'a' }; - enum {AA = 10, BB, CC, DD} e; - union - { - char a; - int b; - float f; - double d; - void *p; - } u; - struct + static struct { char *ptr; int len; - } s; + struct + { + unsigned MAGIC; + }; + union + { + int ua; + char *ub; + }; + } anon_s = {"abracadabra", 11, 0xdead, 0xbeef}; + + struct A + { + A (void) : e (AA) + { + this->u.b = 0; + this->s.ptr = "hello"; + this->s.len = 5; + } + + enum {AA = 10, BB, CC, DD} e; + union + { + char a; + int b; + float f; + double d; + void *p; + } u; + struct + { + char *ptr; + int len; + } s; + }; }; int diff --git a/gdb/testsuite/gdb.compile/cp-simple-anonymous.exp b/gdb/testsuite/gdb.compile/cp-simple-anonymous.exp index 259caebc425..90f921f2e3c 100644 --- a/gdb/testsuite/gdb.compile/cp-simple-anonymous.exp +++ b/gdb/testsuite/gdb.compile/cp-simple-anonymous.exp @@ -48,6 +48,8 @@ CompileExpression::new "var" CompileExpression::test "anon_e" {(3|GHI)} CompileExpression::test "anon_u.aa" {97( 'a')?} CompileExpression::test "anon_s.len" 11 +CompileExpression::test "anon_s.MAGIC" "57005" +CompileExpression::test "anon_s.ua" "48879" CompileExpression::test "a.u.b" 0 CompileExpression::test "a.s.len" 5 CompileExpression::test "a.e" {(10|A::AA)} -- 2.47.2