Repository navigation
fix(const-param): say when a callee's const parameter is the only evidence - #198
Merged
Merged
Conversation
…idence A parameter only passed where a pointer to const is expected is reported as "never used to modify the pointed object", yet the callee's body is not checked and may cast the qualifier away (#167). Add a fixture with such a callee, its expected message and a witness whose own body is the evidence, a check of the same case across files, and update the headline of the two existing expectations that rest on a callee's const parameter alone.
…dence A parameter passed where a pointer or reference to const is expected counted as not written, from the callee's declaration alone, within one file and across files (#157). The message then stated that the object is never modified, although the callee's body is not checked and may cast the qualifier away. Track that case as its own write state, kept by the merge whenever one use depends on it, and say only what the rule establishes: the parameter is only read, or passed where a pointer to const is expected, and the callee's body is not checked. The same parameters are reported, and a diagnostic established by the function's own uses keeps its message. Fixes #167
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.
Fixes #167
Problem
A parameter passed where a pointer or reference to const is expected counted as not written from the callee's declaration alone, within one file and across files (#157). The message then said "is never used to modify the pointed object", although the callee's body is not checked:
Fix
The rule keeps reporting the same parameters, as the cross-TU design keeps the callee's interface contract (A1). It now tells the two kinds of evidence apart:
NoWriteByContract, for a callee's const parameter in the same file or from another file;The reference,
T *constand rvalue-reference variants follow the same rule. A diagnostic established by the function's own uses keeps its message.Tests
test/pointer_reference-const_correctness/const-callee-contract.c: the cast case with its new message and anot contains:on the old one, plus a witness without a call that keeps the old message.check_const_param_contract_message_across_files: the same case with the callee in another file.caller_const(advanced-cases.c) andcaller_ref(advanced-cases.cpp).run_test.pyignores Info diagnostics, so a line inserted mid-block would break those expectations beyond their headline.main: 4/4 failing. GREEN: all pass.Before / after (
mainb0982b2 vs this branch, macOS arm64)defaultandz3: 848 runs, 1285 = 1285 diagnostics. 8 runs differ, by message only, on the 4 expected files.runCrossTUSummaryPass(2),DirectModuleLoadingExecutionStrategy::execute, and 4 instances inStackComputation.cpp.Limits
Code scanning
CI is green on fc4dc03: 13 checks pass, the release attach step is skipped.
main: none new, none gone.github-advanced-securitycomment on this PR. No newcoretrace-concurrency-analyzeralert.Linux validation
Run on Linux x86_64 (WSL, Ubuntu 24.04, LLVM 20) with
mainb0982b2 and this branch:defaultandz3: 848 runs, 1291 = 1291 diagnostics. 8 runs differ, by message only, on the same 4 files as on macOS.