public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org>
Cc: Bruno Larsen <blarsen@redhat.com>
Subject: Re: [PATCH v3 2/2] gdb/c++: Detect ambiguous variables in imported namespaces
Date: Tue, 20 Dec 2022 14:10:48 -0700	[thread overview]
Message-ID: <875ye5kch3.fsf@tromey.com> (raw)
In-Reply-To: <20221122113319.1760546-3-blarsen@redhat.com> (Bruno Larsen via Gdb-patches's message of "Tue, 22 Nov 2022 12:33:20 +0100")

>>>>> "Bruno" == Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org> writes:

Bruno> When running gdb.cp/nsusing.cc and stopping at line 17, we can ask GDB
Bruno> to print x and get a compiler-dependent answer. Using gcc 12.2.1, GDB
Bruno> will print M::x, and using clang 16.0.0 prints N::x. Not only is this
Bruno> behavior confusing to users, it is also not consistent with compiler
Bruno> behaviors, which would warn that using x is ambiguous at this point.

Thanks for the patch.

Bruno> +      error (_("%s"), error_str.c_str ());
Bruno> +    }
Bruno> +  else
Bruno> +    return found_symbols;
Bruno> +
Bruno> +  /* This is needed to silence a -Werror=return-type warning, because
Bruno> +     the above if case doesn't have a return statement.  */
Bruno> +  gdb_assert_not_reached ();
Bruno>  }

This is surprising, because error is marked as noreturn.
Anyway perhaps a better workaround would be to just remove the 'else'.

Bruno> +  /* Despite getting a map, it should have at most one element, otherwise
Bruno> +     cp_lookup_symbol_via_import will have already reported the ambiguity.  */
Bruno> +  std::map<std::string, struct block_symbol> result
Bruno> +    = cp_lookup_symbol_via_imports (scope, name, block, domain, 0, 1, 1);

I think it would be better to have some kind of wrapper, where
cp_lookup_symbol_via_imports takes a set as a parameter (to avoid having
to merge sets), and then the wrapper extracts the result.

Maybe the error handling could be stuck in the wrapper as well.  I
didn't look into that.

Tom

  reply	other threads:[~2022-12-20 21:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22 11:33 [PATCH v3 0/2] Improve handling of using directives Bruno Larsen
2022-11-22 11:33 ` [PATCH v3 1/2] gdb/c++: validate 'using' directives based on the current line Bruno Larsen
     [not found]   ` <CAJVr-EMEbyP4pgDk=U50p5nWrybJgFbdZ0iLCp4W6WbWJKGc9A@mail.gmail.com>
2022-12-15 13:26     ` Fwd: " Alexandra Petlanova Hajkova
2022-12-15 14:50       ` Bruno Larsen
2022-12-20 21:06   ` Tom Tromey
2022-11-22 11:33 ` [PATCH v3 2/2] gdb/c++: Detect ambiguous variables in imported namespaces Bruno Larsen
2022-12-20 21:10   ` Tom Tromey [this message]
2022-12-07 13:53 ` [PATCH v3 0/2] Improve handling of using directives Bruno Larsen
2022-12-15 10:17   ` [PINGv2][PATCH " Bruno Larsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875ye5kch3.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=blarsen@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).