[clang] [clang-tools-extra] [llvm] [clang]: reflection operator parsing for global namespace and primitive types (PR #164692)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 28 19:16:03 PDT 2025


================
@@ -0,0 +1,78 @@
+//===--- ParseReflect.cpp - C++26 Reflection Parsing ---------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file implements parsing for reflection facilities.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/LocInfoType.h"
+#include "clang/Basic/DiagnosticParse.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/EnterExpressionEvaluationContext.h"
+using namespace clang;
+
+ExprResult Parser::ParseCXXReflectExpression(SourceLocation DoubleCaretLoc) {
+  // TODO(reflection) : support parsing for more reflect-expressions.
+  EnterExpressionEvaluationContext Unevaluated(
+      Actions, Sema::ExpressionEvaluationContext::Unevaluated);
+
+  CXXScopeSpec SS;
+  if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr,
+                                     /*ObjectHasErrors=*/false,
+                                     /*EnteringContext=*/false)) {
+    SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch);
----------------
Sirraide wrote:

```suggestion
```
I don’t think expression parsing code should be skipping anything (unless it involves things like balanced brackets), because (one of) the caller(s) usually has a better idea how to recover from this.

(e.g. if we’re in a function argument list, we probably want to skip to the next `,` or `)` instead)

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


More information about the cfe-commits mailing list