Repository navigation
[clang] preserve the static_assert keyword in C++ capture - #2330
Merged
Merged
Conversation
Contributor
|
This is adding pretty complex test scripts, I wonder if that's really necessary. |
VladimirMakaev
force-pushed
the
pr/static-assert-1125
branch
from
November 26, 2026 22:29
10ffa21 to
8b88ef5
Compare
The force-included C++ macro erased assertions and rejected directives in their operands.
Keep the legacy C macro and let Clang validate the C++ keyword. Translate StaticAssertDecl
without runtime instructions so it preserves the enclosing function.
Libc++'s comparator diagnostic can inspect an incomplete key through its generic invocation
trait. Match that diagnostic during capture and check the direct binary call, retaining its
warning attribute and severity.
For example, capture used to reject this valid layout check:
static_assert([] {
#pragma pack(push, 1)
struct Packed { char first; int second; };
#pragma pack(pop)
return sizeof(Packed) == sizeof(char) + sizeof(int);
}(), "packed layout");
Limitations: C++ assertions failing under the capture compiler fail that unit. The accepted
compiler-validation cost is 1.56% total instructions (2.96-4.91% on three tested projects).
## Test plan
Native build and 73 Linux direct suites plus annotations pass. The C++20 frontend fixture
covers directive operands, local assertions and incomplete-key comparators; three controls
fail without the relevant behavior. Additional local compiler/diagnostic checks pass.
The fresh macOS full-suite gate is pending for this revised test tree.
VladimirMakaev
force-pushed
the
pr/static-assert-1125
branch
from
December 1, 2026 20:03
8b88ef5 to
3eb9d77
Compare
Contributor
Author
|
Fair point, they weren't necessary. I removed the shell and Python test scripts and their fixtures. The PR now has a single frontend test, |
Contributor
|
Thank you, I think it's best to avoid making our testing frameworks more complex unnecessarily. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The force-included variadic macro erased C++ assertions and made directives in their operands
invalid macro arguments. Restrict it to C. The compiler checks C++ assertions and the frontend
continues to skip StaticAssertDecl when producing runtime instructions.
For example, capture used to reject this valid packed-layout check:
static_assert([] {
#pragma pack(push, 1)
struct Packed { char first; int second; };
#pragma pack(pop)
return sizeof(Packed) == sizeof(char) + sizeof(int);
}(), "packed layout");
Legacy C macro behavior is retained.
Limitations: C++ assertions failing under the capture compiler now fail capture of that unit.
Compiler validation adds about 1.56% total instructions (2.96-4.91% on three tested projects).
This cost is accepted for the capture correction.
Test plan
Check raw and captured compiler acceptance/rejection in C++11/14/17/20 and C11, unchanged
statement/block/loop CFGs, and compile-time-lambda versus runtime-null reports. Run the full
regression suite and compare all real-code projects for capture, report and cost changes.
Overlap with #2153
This PR carries a six-line addition to
declStmt_transininfer/src/clang/cTrans.mlthat addsStaticAssertDeclto the existing no-op list alongsideNamespaceAliasDecl,TypedefDecl,TypeAliasDecl,UsingDeclandUsingDirectiveDecl.That hunk also appears in #2153 ("[clang] translate block-scope enum, function and local label
declarations"), which is currently closed. It is included here because without it this change is
not self-contained: once
static_assertis no longer erased in C++, astatic_assertinside afunction body becomes a real
StaticAssertDecl,declStmt_transraisesunimplemented, and thefrontend discards the whole enclosing procedure. The effect is silent — no report and no
user-visible error — so every C++ function containing a
static_assertwould simply stop beinganalysed.
If #2153 is reopened and lands, the two will conflict trivially on that one list and either side
can be dropped.