[Clang] Defer access checks in leading attributes on external declarations #244030
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.38) × (1 − Review Confidence (0.91)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.38 · 169 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.93 · 2 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.307
Real PR Conversation Timeline
3 items
Maybe it might be worth mentioning [class.access.general]/6 somewhere, as it states this: https://eel.is/c++draft/class.access.general#6
what I dont quite understand in __attribute__((aligned(C::kAlign))) int C::s3 = 0, unrelated_var = 0;
above we have:
if (!LeadingAttrDiags.getDelayedDiagnosticPool().pool_empty() && Result &&
!Result.get().isNull()) {
ParsingDeclRAIIObject FlushDiags(*this, &LeadingAttrDiags);
FlushDiags.complete(*Result.get().begin());
}
would mean the pool is consumed on C::s3, right ? So the whole line actually would pass, but the test expects error on that line. Maybe it's fine, but I'd just like to understand what actually happens and why
daniel-petrovic
nigham
Leading C++11 and GNU attributes in global, namespace, and linkage-block scopes are parsed before
ParseExternalDeclarationentersParseDeclarationOrFunctionDefinition(whereParsingDeclSpecpushes aDelayedDiagnosticPool). As a result, Sema evaluated access and availability checks on attribute arguments immediately in the enclosing file or namespace scope rather than deferring them until the declarator is parsed (rejecting valid out-of-line member definitions such as__attribute__((locks_excluded(C::mu_))) void C::f() {}). Commit b78d5380da11 introduced this for leading GNU attributes at global scope, and commit 4e9d349ab86d (#240734) extended the same loop to namespace scope.Factor the leading-attribute parsing loop into
ParseExternalDeclarationWithAttrs()and wrap only the attribute loop in aParsingDeclRAIIObject(abortAndRemember()), so non-declarator constructs parsed afterward (static_assert, nested namespaces, etc.) do not run with an active delayed-diagnostic pool. WhenParseExternalDeclarationreachesParseDeclarationOrFunctionDefinition, transfer those delayed diagnostics intoParsingDeclSpecso they are checked per declarator; otherwise, flush any remaining diagnostics against the resultingDeclso invalid accesses on non-declarator constructs are still diagnosed.Assited by: Antigravity w/ Gemini, reviewed by me.