Repository navigation
Make subscripting an array prvalue or xvalue produce an xvalue [GH #430, GH #440] - #617
Draft
Momen-G-Ar wants to merge 2 commits into
Draft
Momen-G-Ar wants to merge 2 commits into
Momen-G-Ar wants to merge 2 commits into
Conversation
…gcpp#430, GH edgcpp#440] Subscripting an array prvalue or xvalue, such as "A().i[0]", produces an xvalue ([expr.sub], Core issue 1213). EDG produced an lvalue. Since the changes for GH edgcpp#90 made "A().b" an xvalue, the conditional expression "c ? A().b : A().i[0]" had operands of different value categories, so it was a prvalue, and a reference bound to it was bound to a copy while the A temporary was destroyed at the end of the full-expression. A new mode flag, subscript_of_array_rvalue_is_xvalue, is set beside the Core issue 616 flag: in C++14 and later modes, and in C++11 mode when emulating GCC 9 or later or Clang 7 or later, but not in Microsoft modes, since MSVC still produces an lvalue. scan_subscript_operator marks the result of a built-in subscript as an xvalue when the array operand was a prvalue or xvalue before array-to-pointer decay. A GNU static compound literal still produces an lvalue. As in GCC 9 and Clang 7, taking the address of such a subscript or assigning to it is now an error. regressions/edgcppgh-90-warn uses "make().arr + 1" instead of "&make().arr[1]" for that reason. New tests: regressions/edgcppgh-430, regressions/edgcppgh-440, regressions/edgcppgh-440-neg and cwg/cwg1213. cwg/cwg1299a and imported gnu/cpp/pr60517 now pass, and imported clang cwg12xx loses three errors.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
Collaborator
|
AcknowlEDG review results updated for
|
Collaborator
|
AcknowlEDG review results updated for
CI failure. |
Collaborator
|
AcknowlEDG review results updated for
CI success. |
… GH edgcpp#440] The GNU two-operand conditional "x ? : y" saves "x" with make_expr_reusable_copy so that it can be reused. That routine saved the address only of an lvalue; an xvalue such as "S().s" or "A().i[0]" was saved by value, so its value category no longer matched the operand, and an assertion in conv_glvalue_to_prvalue failed. Now the address of any glvalue is saved, and both the saved expression and its reuse stay xvalues. New test: regressions/edgcppgh-430-gnu-cond. Imported gnu/cpp/ext/temp-extend1, gnu/cpp/cpp0x/temp-extend2 and gnu/cpp/cpp1z/array-prvalue2 now pass, and imported clang SemaCXX/vector-size-conditional and SemaCXX/ext-vector-type-conditional no longer abort.
Momen-G-Ar
force-pushed
the
gh-430-cwg1213
branch
from
November 28, 2026 07:23
6209d33 to
43f8203
Compare
Collaborator
|
AcknowlEDG review results updated for
CI success. |
This branch has not been deployed
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.
Subscripting an array prvalue or xvalue, such as
A().i[0], produces an xvalue ([expr.sub], Core issue 1213). EDG produced an lvalue. Since the changes for GH #90 madeA().ban xvalue, the conditional expressionc ? A().b : A().i[0]had operands of different value categories, so it was a prvalue, and a reference bound to it was bound to a copy while theAtemporary was destroyed at the end of the full-expression.A new mode flag,
subscript_of_array_rvalue_is_xvalue, is set beside the Core issue 616 flag: in C++14 and later modes, and in C++11 mode when emulating GCC 9 or later or Clang 7 or later, but not in Microsoft modes, since MSVC still produces an lvalue.scan_subscript_operatormarks the result of a built-in subscript as an xvalue when the array operand was a prvalue or xvalue before array-to-pointer decay. A GNU static compound literal still produces an lvalue.As in GCC 9 and Clang 7, taking the address of such a subscript or assigning to it is now an error.
regressions/gh-90-warnusesmake().arr + 1instead of&make().arr[1]for that reason.The GNU two-operand conditional
x ? : ysavesxwithmake_expr_reusable_copyso that it can be reused. That routine saved the address only of an lvalue, so an xvaluexsuch asS().sorA().i[0]was saved by value, its value category no longer matched the operand, and an assertion inconv_glvalue_to_prvaluefailed. This was already the case forS().safter the changes for GH #90; it showed up here in importedgnu/cpp/ext/temp-extend1. Now the address of any glvalue is saved, and both the saved expression and its reuse stay xvalues.New tests:
regressions/gh-430,regressions/gh-430-gnu-cond,regressions/gh-440,regressions/gh-440-negandcwg/cwg1213.cwg/cwg1299aand importedgnu/cpp/pr60517,gnu/cpp/ext/temp-extend1,gnu/cpp/cpp0x/temp-extend2andgnu/cpp/cpp1z/array-prvalue2now pass, imported clangcwg12xxloses three errors, and imported clangSemaCXX/vector-size-conditionalandSemaCXX/ext-vector-type-conditionalno longer abort.