Ensure name doesn't already exist

I am possibly renaming a class. I would like to make sure that the new name doesn’t already exist. Given that I am generating the new name, I have it in a std::string.

How would I check to see if there is already something with the new name in the DeclContext? I assume I would use DeclContext::lockup of some flavor. Also, the new name does not specify any namespaces (no :: anywhere in it).

I am possibly renaming a class. I would like to make sure that the new
name doesn't already exist. Given that I am generating the new name, I
have it in a std::string.

How would I check to see if there is already something with the new name
in the DeclContext? I assume I would use DeclContext::lockup of some
flavor. Also, the new name does not specify any namespaces (no :: anywhere
in it).

Unfortunately that's basically impossible in C++ (argument dependent lookup
etc). But the easy cases should be handled by doing DeclContext::lookup
throught all parent contexts.

I seem to remember reading somewhere that you could implement autocomplete using Clang, and it would list all symbols that are valid at that location. Couldn’t something like this be done to determine if a name already exists at a location?

I seem to remember reading somewhere that you could implement autocomplete
using Clang, and it would list all symbols that are valid at that
location. Couldn't something like this be done to determine if a name
already exists at a location?

The way autocomplete works (if I'm not mistaken) is that it parses up the
the point of completion and then halts in the semantic analysis and outputs
what can come there.
The problem is that this information is lost once the AST is built.