You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
C: diagnose pointer conversions that add qualifiers below the first level [GH #514] - #498
In C, the front end accepted an implicit conversion that adds qualifiers below the first level, such as int ** to const int *const *, without a diagnostic. C++ allows this conversion. In C the pointed-to types are not compatible, so it violates the constraints of simple assignment (C23 6.5.17.2), and a diagnostic is required. GCC 14 and later reject it by default.
In types.c, a C conversion that takes this path now gets the caller's default warning when no more specific warning applies. The conversion is still accepted.
regressions/gh-514 checks for the warning in assignment, initialization, argument passing, return, and a three-level conversion, in GNU C23 mode and with --strict_warnings. regressions/gh-514-positive checks that adding const only at the first level, or converting with an explicit cast, gets no diagnostic in strict mode, and regressions/gh-514-cpp that C++ is unchanged.
Tested with the full test suites for edg_x86_64 and edg_x86_64_cp, and with the new and changed tests for edg_x86_32 and edg_x86_32_cp.
C mode now warns when pointer conversions add const qualifiers below the first pointer level, including assignments, initializations, function arguments, and return values.
Conversions that add qualifiers only at the first pointer level remain accepted without the new warning.
C++ mode continues to accept the corresponding deep-qualification conversions.
Tests
Added regression coverage for these conversion cases in C and C++.
No actionable comments were generated in the recent review.
Walkthrough
C mode now warns for implicit pointer conversions that add qualifiers below the first pointer level. Regression tests cover the diagnostic cases, accepted first-level qualification, explicit casts, and corresponding C++ conversions.
C mode assigns a default warning to these conversions when the qualification check does not return a specific warning. The change note describes the conversion as accepted with a diagnostic in C and contrasts this with C++.
C and C++ regression coverage tests/tests/regressions/gh-514.sft.c, tests/tests/regressions/gh-514-positive.sft.c, tests/tests/regressions/gh-514-cpp.sft.cpp, tests/tests/regressions/.gh-514*.rto/*, tests/tests/regressions/.gh-514-cpp.rto/*
C tests cover assignment, initialization, argument passing, return values, and three pointer levels. Positive cases cover first-level qualification and explicit casts. C++ tests cover the corresponding conversion, and expected outputs record the C diagnostics.
edgcpp/compiler#455: Changes the pointer-qualification fallback in impl_pointer_conversion, which is also changed here for C mode.
Suggested labels:bug
Suggested reviewers:nv-cmeerw
Merge Risk: Minimal · up to 5c924
C code that implicitly adds qualifiers below the first pointer level now gets a warning, and the conversion is still accepted. No actionable merge-blocking risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: the C front end now diagnoses pointer conversions that add qualifiers below the first pointer level, which matches the types.c change, the GH #514 change note, and the…
Linked Issues check
Issue #514 requires a diagnostic for implicit C pointer conversions that add qualifiers below the first level (for example, int ** to const int *const *) in assignment, initialization, argument passin…
Out of Scope Changes check
The whole-PR changes are limited to src/types.c (a conditional C-mode warning on the below-first-level qualifier conversion path), a pending change note for #514, and regression tests named gh-514, gh…
Full details: Title check
Explanation
The title names the main change: the C front end now diagnoses pointer conversions that add qualifiers below the first pointer level, which matches the types.c change, the GH #514 change note, and the regression tests. The bracketed issue reference is accurate. The PR objectives cite a different PR number (#498) in the body, but the title itself matches the changeset.
Full details: Linked Issues check
Explanation
Issue #514 requires a diagnostic for implicit C pointer conversions that add qualifiers below the first level (for example, int ** to const int *const *) in assignment, initialization, argument passing, and return. The diff to src/types.c adds a branch in the qualifier-addition path. When C_mode() is true and no specific warning was set (warning_suggested == ec_no_error), the branch sets warning_suggested to default_warning_code. The conversion stays accepted, and any specific warning from the check is kept. The same conversion path serves all four contexts, so the diagnostic applies to each. The added tests cover assignment, initialization, argument passing, return, and a three-level conversion (regressions/gh-514, with the expected output in default.1.1.txt and default.2.1.txt). regressions/gh-514-positive covers first-level-only const addition and explicit casts with no diagnostic. regressions/gh-514-cpp covers C++ behavior. The regression expected outputs were not inspected line by line, so the exact diagnostic text is not confirmed. The code change is consistent with the stated requirement.
Full details: Out of Scope Changes check
Explanation
The whole-PR changes are limited to src/types.c (a conditional C-mode warning on the below-first-level qualifier conversion path), a pending change note for #514, and regression tests named gh-514, gh-514-positive, and gh-514-cpp. The source change implements the #514 requirement. The tests and change note support that change. No unrelated functional change was found in the reviewed files.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
Comment: Rather than adding a second comment, could you fold this into the existing one just above (which still says "This is an extension in C mode.")? Something like:
/* Allow conversion between pointers where type qualifiers are being added at levels other than the first, e.g., "int **" -> "const int * const *". These are the const-safe cases. In C mode, this is an extension, and a diagnostic is issued since the types pointed to are not "compatible". */
(Also, front-end comments usually capitalize after a colon, as in "...: The pointed-to types are incompatible." The exception is if the colon
is followed by a list that cannot be a standalone sentence.)
Test headers: Please add a //remark: line to each of the three tests (it's what shows up in the test results and expectation logs), e.g.:
//remark:C: impl. ptr conv. w/ qualifiers below first level
Test coverage: c-deep-pointer-qualification only covers assignment. Since initialization, argument passing, and return each produce a different diagnostic, it would be good to include them too Also, add a three-level case.
C++ test: Its recording contains warning: variable "q" was set but never used (the front end issues that in C++ even with (void)q, independently of this change). Not a problem, but if you were to use q differently (e.g., pass it to a function), the recording wouldn't be as noisy.
…evel [GH edgcpp#514]
In C, an implicit conversion such as "int **" to "const int *const *" is
valid in C++ but violates the constraints of simple assignment, because
the types pointed to are not compatible (C23 6.5.17.2), so a diagnostic
is required (C23 5.1.1.3). The front end accepted it as an extension
without one. Issue the caller's default warning when no more specific
warning applies; the conversion is still accepted.
71iq
changed the title
C: diagnose pointer conversions that add qualifiers below the first level []
C: diagnose pointer conversions that add qualifiers below the first level [GH #514]
Nov 11, 2026
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
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.
In C, the front end accepted an implicit conversion that adds qualifiers below the first level, such as
int **toconst int *const *, without a diagnostic. C++ allows this conversion. In C the pointed-to types are not compatible, so it violates the constraints of simple assignment (C23 6.5.17.2), and a diagnostic is required. GCC 14 and later reject it by default.In
types.c, a C conversion that takes this path now gets the caller's default warning when no more specific warning applies. The conversion is still accepted.regressions/gh-514checks for the warning in assignment, initialization, argument passing,return, and a three-level conversion, in GNU C23 mode and with--strict_warnings.regressions/gh-514-positivechecks that addingconstonly at the first level, or converting with an explicit cast, gets no diagnostic in strict mode, andregressions/gh-514-cppthat C++ is unchanged.Tested with the full test suites for edg_x86_64 and edg_x86_64_cp, and with the new and changed tests for edg_x86_32 and edg_x86_32_cp.
Fixes #514
Summary by CodeRabbit
constqualifiers below the first pointer level, including assignments, initializations, function arguments, and return values.