[libcxx-commits] [libcxx] [libc++][module] Fixes std::string UDL. (PR #75000)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 12 10:02:00 PST 2023
================
@@ -182,14 +182,37 @@ void header_exportable_declarations::registerMatchers(clang::ast_matchers::Match
/// * exception has equality operators for the type \c exception_ptr
/// * initializer_list has the functions \c begin and \c end
///
-/// \warning In some cases the returned name can be an empty string.
-/// The cause has not been investigated.
+/// When the named declaration uses a reserved name the result is an
+/// empty string.
static std::string get_qualified_name(const clang::NamedDecl& decl) {
- std::string result = decl.getQualifiedNameAsString();
-
- if (result.starts_with("std::__1::"))
- result.erase(5, 5);
-
+ std::string result = decl.getNameAsString();
+ // Reject reserved names (ignoring _ in global namespace).
+ if (result.size() >= 2 && result[0] == '_')
+ if (result[1] == '_' || std::isupper(result[1]))
+ if (result != "_Exit")
+ return "";
+
+ for (auto* context = llvm::dyn_cast_or_null<clang::NamespaceDecl>(decl.getDeclContext()); //
+ context;
+ context = llvm::dyn_cast_or_null<clang::NamespaceDecl>(context->getDeclContext())) {
+ std::string ns = std::string(context->getName());
+
+ if (ns.starts_with("__")) {
+ // When the reserved name is an inline namespace the namespace is
+ // not added to the qualified name instead of removed. Libc++ uses
+ // several inline namespace with reserved names. For example,
+ // __1 for every declaration, __cpo in range-based algorithms.
+ //
----------------
ldionne wrote:
Tabs here I think.
https://github.com/llvm/llvm-project/pull/75000
More information about the libcxx-commits
mailing list