Repository navigation
verify: Turn off AssertMacros.h's names without underscores on Apple targets - #42
Merged
Merged
Conversation
…targets, which expand cppverify::check.
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.
Apple's
<AssertMacros.h>, which some of Apple's framework headers include, definescheck(assertion)as__Check(assertion)unless__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORESis 0, and defaults it to 1. In production builds__Checkexpands to nothing. The macro is function-like and the preprocessor runs before the parser sees a construct, so everycppverify::check(...)after the header breaks. With Apple's latest published copy of the header (CarbonHeaders-18.1, apple-oss-distributions) and anarm64-apple-macosx14.0target, main reports:The header's own comment names the fix: define the switch to 0, and it defines only its
__Check,__Require, and__Verifynames, which Apple recommends over the old ones.The change: with
-fverify-contractson a Darwin target,InitializePreprocessordefines__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORESto 0 before the implicit<cppverify.h>, unless the command line defines it. It comes after the command line's-Doptions, so-D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=1keeps the old names. A#defineof 1 in the source also takes effect, with a-Wmacro-redefinedwarning. Other targets and compilations without the flag are unaffected.Docs: the syntax page gains a section on macros named like a construct. It has a checked example of a
checkmacro breaking the construct, with its exact error and the#undefthat restores it, and explains Apple's header and how a file that uses the old macro names keeps them. DESIGN records the predefinition. The release notes get an entry under "C++ that compiles now".Testing:
Verify/assert_macros_darwin.cpp, with a mockInputs/apple/AssertMacros.hthat keeps the header's logic, runs:-verifyand no diagnostics;On main exactly the three Apple-with-flag lines fail and the three control lines pass. With Apple's real header the function verifies through
cpp-verify -- -target arm64-apple-macosx14.0(main: the error above). I could not run it on macOS itself; the macOS CI job runs the Verify suite there.Checked: the Verify and Preprocessor suites (813 tests) pass in a release build, except
Preprocessor/llvm-windres.rc, which needsllvm-windresand that build does not have it. In a build with assertions they pass (800 passed, 13 unsupported). After the rebase onto #39, the documentation examples pass and the site builds with-W.