[clang] [BoundsSafety] unify ParseLexedAttribute (PR #186033)

Yeoul Na via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 14 15:49:57 PDT 2026


================
@@ -751,20 +753,21 @@ void Parser::ParseLexedAttribute(LateParsedAttribute &LA,
 
   if (LA.Decls.size() > 0) {
     Decl *D = LA.Decls[0];
-    NamedDecl *ND  = dyn_cast<NamedDecl>(D);
-    RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext());
+    bool HasFuncScope =
+        EnterScope && LA.Decls.size() == 1 && D->isFunctionOrFunctionTemplate();
+    if (getLangOpts().CPlusPlus) {
----------------
rapidsna wrote:

I think we can reuse more code between C++ and C by conditionalizing the RAII scopes instead of branching on `getLangOpts().CPlusPlus`. Both guards already support a "disabled" mode:

`CXXThisScopeRAII(Sema &S, Decl *ContextDecl, Qualifiers, bool Enabled = true)` — no-ops when `!Enabled || !ContextDecl`
`ReenterTemplateScopeRAII(Parser &P, Decl *D, bool Enter = true)` — no-ops when `!Enter`

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


More information about the cfe-commits mailing list