[clang] std::meta is an associated namespace of reflect-expressions. (PR #242722)

Daniel M. Katz via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 1 09:04:56 PST 2026


================
@@ -12706,6 +12706,27 @@ NamespaceDecl *Sema::getStdNamespace() const {
                                  StdNamespace.get(Context.getExternalSource()));
 }
 
+NamespaceDecl *Sema::lookupStdMetaNamespace() {
+  NamespaceDecl *StdMeta = cast_or_null<NamespaceDecl>(
+      StdMetaNamespace.get(Context.getExternalSource()));
+  if (StdMeta)
+    return StdMeta;
+
+  NamespaceDecl *Std = getStdNamespace();
----------------
katzdm wrote:

I think it's a bit different -
- `getStdNamespace` just returns `StdNamespace` if it's already been defined (either through opening `namespace std` - which we have special logic in `ActOnStartNamespaceDef` to assign the opened `NamespaceDecl` to `StdNamespace` when this happens - or through `getOrCreateStdNamespace`).
- `getOrCreateStdNamespace` will create `::std` if it hasn't already been defined.

So `lookupStdMetaNamespace` is slightly different from either one: It returns `StdMetaNamespace` if it's already been defined and looked up, or looks it up in `std` otherwise.

If we wanted to, we could also add special handling for `std::meta` to `ActOnStartNamespaceDef`, so as to capture `std::meta` into `StdMetaNamespace` at its first point of definition; then we could replace `lookupStdMetaNamespace` with `getStdMetaNamespace` that just returns the (possibly null) `NamespaceDecl` from `StdMetaNamespace`. But that feels more invasive.

So I think we should leave the function as-is, and keep the naming to reinforce that it works slightly differently than the `std` case. What do you think?

https://github.com/llvm/llvm-project/pull/242722


More information about the cfe-commits mailing list