public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: fix disas of destructors in nested namespaces
@ 2022-08-17  7:14 fent
  0 siblings, 0 replies; only message in thread
From: fent @ 2022-08-17  7:14 UTC (permalink / raw)
  To: gdb-patches; +Cc: tom, simon.marchi, Philipp Fent

From: Philipp Fent <fent@in.tum.de>

Remove the destructor name validity check. The check did not properly
handle nested namespaces or complex templates with nested angle
brackets. Overload resolution already checks the name and reports any
mismatches, so this check seems unnecessary.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27045
Signed-off-by: Philipp Fent <fent@in.tum.de>
---
 gdb/c-exp.y                      |  2 --
 gdb/testsuite/gdb.cp/classes.cc  |  8 ++++++++
 gdb/testsuite/gdb.cp/classes.exp |  4 ++++
 gdb/valops.c                     | 27 ---------------------------
 gdb/value.h                      |  2 --
 5 files changed, 12 insertions(+), 31 deletions(-)

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 61a61fcba09..7ef557bd38f 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1151,8 +1151,6 @@ qualified_name:	TYPENAME COLONCOLON name
 			  std::string name = "~" + std::string ($4.ptr,
 								$4.length);
 
-			  /* Check for valid destructor name.  */
-			  destructor_name_p (name.c_str (), $1.type);
 			  pstate->push_new<scope_operation> (type,
 							     std::move (name));
 			}
diff --git a/gdb/testsuite/gdb.cp/classes.cc b/gdb/testsuite/gdb.cp/classes.cc
index 3bb52d2433c..c59413cddbd 100644
--- a/gdb/testsuite/gdb.cp/classes.cc
+++ b/gdb/testsuite/gdb.cp/classes.cc
@@ -401,6 +401,13 @@ class Base1 {
   ~Base1 () { }
 };
 
+namespace nested {
+class Base {
+public:
+  ~Base () {}
+};
+}
+
 typedef Base1 base1;
 
 class Foo
@@ -627,6 +634,7 @@ void use_methods ()
   i = class_param.Aval_x (g_A);
 
   base1 b (3);
+  nested::Base nb;
 }
 
 struct Inner
diff --git a/gdb/testsuite/gdb.cp/classes.exp b/gdb/testsuite/gdb.cp/classes.exp
index 7b8b315ac1f..14c2e04e492 100644
--- a/gdb/testsuite/gdb.cp/classes.exp
+++ b/gdb/testsuite/gdb.cp/classes.exp
@@ -654,6 +654,10 @@ proc do_tests {} {
 	"print dtor of typedef class"
 
     gdb_test "list ByAnyOtherName::times" ".*int Foo::times.*"
+
+    gdb_test "disassemble nested::Base::~Base" \
+    "Dump of assembler code for function.*Base.*" \
+    "disassemble dtor in nested namespace"
 }
 
 do_tests
diff --git a/gdb/valops.c b/gdb/valops.c
index 27e84d9f6b3..59b8cf04fbf 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3315,33 +3315,6 @@ classify_oload_match (const badness_vector &oload_champ_bv,
   return worst;
 }
 
-/* C++: return 1 is NAME is a legitimate name for the destructor of
-   type TYPE.  If TYPE does not have a destructor, or if NAME is
-   inappropriate for TYPE, an error is signaled.  Parameter TYPE should not yet
-   have CHECK_TYPEDEF applied, this function will apply it itself.  */
-
-int
-destructor_name_p (const char *name, struct type *type)
-{
-  if (name[0] == '~')
-    {
-      const char *dname = type_name_or_error (type);
-      const char *cp = strchr (dname, '<');
-      unsigned int len;
-
-      /* Do not compare the template part for template classes.  */
-      if (cp == NULL)
-	len = strlen (dname);
-      else
-	len = cp - dname;
-      if (strlen (name + 1) != len || strncmp (dname, name + 1, len) != 0)
-	error (_("name of destructor must equal name of class"));
-      else
-	return 1;
-    }
-  return 0;
-}
-
 /* Find an enum constant named NAME in TYPE.  TYPE must be an "enum
    class".  If the name is found, return a value representing it;
    otherwise throw an exception.  */
diff --git a/gdb/value.h b/gdb/value.h
index 7e1eec22413..4f2bf9d4c99 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1062,8 +1062,6 @@ extern int binop_user_defined_p (enum exp_opcode op, struct value *arg1,
 
 extern int unop_user_defined_p (enum exp_opcode op, struct value *arg1);
 
-extern int destructor_name_p (const char *name, struct type *type);
-
 extern value_ref_ptr release_value (struct value *val);
 
 extern int record_latest_value (struct value *val);
-- 
2.37.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-17  7:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-17  7:14 [PATCH] gdb: fix disas of destructors in nested namespaces fent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).