Skip to content

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
edgcpp:mainfrom
Momen-G-Ar:gh-430-cwg1213
Draft

Momen-G-Ar wants to merge 2 commits into
edgcpp:mainfrom
Momen-G-Ar:gh-430-cwg1213

Conversation

@Momen-G-Ar

@Momen-G-Ar Momen-G-Ar commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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 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/gh-90-warn uses make().arr + 1 instead of &make().arr[1] for that reason.

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, so an xvalue x such as S().s or A().i[0] was saved by value, its value category no longer matched the operand, and an assertion in conv_glvalue_to_prvalue failed. This was already the case for S().s after the changes for GH #90; it showed up here in imported gnu/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-neg and cwg/cwg1213. cwg/cwg1299a and imported gnu/cpp/pr60517, gnu/cpp/ext/temp-extend1, gnu/cpp/cpp0x/temp-extend2 and gnu/cpp/cpp1z/array-prvalue2 now pass, imported clang cwg12xx loses three errors, and imported clang SemaCXX/vector-size-conditional and SemaCXX/ext-vector-type-conditional no longer abort.

…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.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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.

Share

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 87a945f31dee:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 87a945f31dee:

CI failure.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 6209d338850c:

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.
@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 43f8203ea711:

CI success.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants