From c8ba13ad37c98262b94f99cc4f84ac0066c48cc2 Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Wed, 18 Oct 2017 11:05:45 -0700 Subject: Canonicalize conversion operators Consider a conversion operator such as: operator foo const* const* (); There are two small parser problems, highlighted by this test: (gdb) p operator foo const* const* There is no field named operatorfoo const* const * GDB is looking up the symbol "operatorfoo const* const*" -- it is missing a space between the keyword "operator" and the type name "foo const* const*". Additionally, this input of the user-defined type needs to be canonicalized so that different "spellings" of the type are recognized: (gdb) p operator const foo* const * There is no field named operator const foo* const * gdb/ChangeLog: * c-exp.y (oper): Canonicalize conversion operators of user-defined types. Add whitespace to front of type name. gdb/testsuite/ChangeLog: * gdb.cp/cpexprs.cc (base) : New method. (main): Call it. * gdb.cp/cpexprs.exp: Add new conversion operator to test matrix. Add additional user-defined conversion operator tests. --- gdb/c-exp.y | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'gdb/c-exp.y') diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 7c050b4..18c74d8 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -1554,7 +1554,7 @@ oper: OPERATOR NEW | OPERATOR '>' { $$ = operator_stoken (">"); } | OPERATOR ASSIGN_MODIFY - { const char *op = "unknown"; + { const char *op = " unknown"; switch ($2) { case BINOP_RSH: @@ -1630,7 +1630,13 @@ oper: OPERATOR NEW c_print_type ($2, NULL, &buf, -1, 0, &type_print_raw_options); - $$ = operator_stoken (buf.c_str ()); + + /* This also needs canonicalization. */ + std::string canon + = cp_canonicalize_string (buf.c_str ()); + if (canon.empty ()) + canon = std::move (buf.string ()); + $$ = operator_stoken ((" " + canon).c_str ()); } ; -- cgit v1.1