Skip to content

[libc++][ranges] Fix the LWG 3568 test for basic_istream_view - #215589

Merged
frederick-vs-ja merged 3 commits into
llvm:mainfrom
iskandarem:ub-basic_istream_view-test
Aug 13, 2026
Merged

[libc++][ranges] Fix the LWG 3568 test for basic_istream_view#215589
frederick-vs-ja merged 3 commits into
llvm:mainfrom
iskandarem:ub-basic_istream_view-test

Conversation

@iskandarem

@iskandarem iskandarem commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

The previous test was dereferencing begin() iterator on empty view which is UB, because begin() == end().

A new test case was suggested in a post-merge feedback in #193891, which verifies LWG3568 through constant evaluation. Such a constexpr basic_istream_view variable can only be created if it is completely initialized, including its exposition-only value_ member.

The existing test case is changed to use a non-empty stream and a testing class type for which operator>> is no-op. The state of the class object stored in basic_istream_view is unchanged even after the initial operator>> call.

This avoids dereferencing a past-the-end iterator while testing LWG3568.

@iskandarem
iskandarem requested a review from a team as a code owner August 11, 2026 15:36
@github-actions

Copy link
Copy Markdown

Hello @iskandarem 👋

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

  • All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
  • The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.
  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.


Frequently asked questions

How do I add reviewers?

This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

What if there are no comments?

If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

Are any special GitHub settings required to contribute to LLVM?

We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.


If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

Thank you,
The LLVM Community

@llvmorg-github-actions llvmorg-github-actions Bot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Aug 11, 2026
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-libcxx

Author: Iskandar Emomzoda (iskandarem)

Changes

The previous test was dereferencing begin() iterator on empty view which is UB, because begin() == end().

This solution was suggested by @frederick-vs-ja in #193891, which verifies lwg3568 through constant evaluation. A constexpr basic_istream_view can only be created if its complete state, including value_.

This avoids dereferencing a past-the-end iterator while testing lwg 3568.


Full diff: https://github.com/llvm/llvm-project/pull/215589.diff

1 Files Affected:

  • (modified) libcxx/test/std/ranges/range.factories/range.istream.view/ctor.pass.cpp (+2-4)
diff --git a/libcxx/test/std/ranges/range.factories/range.istream.view/ctor.pass.cpp b/libcxx/test/std/ranges/range.factories/range.istream.view/ctor.pass.cpp
index beeeea4c1bbe1..d15225674049c 100644
--- a/libcxx/test/std/ranges/range.factories/range.istream.view/ctor.pass.cpp
+++ b/libcxx/test/std/ranges/range.factories/range.istream.view/ctor.pass.cpp
@@ -39,10 +39,8 @@ void test() {
 
   // LWG 3568. basic_istream_view needs to initialize value_
   {
-    auto iss = make_string_stream<CharT>("");
-    std::ranges::basic_istream_view<int, CharT> isv{iss};
-    auto iter = isv.begin();
-    assert(*iter == 0);
+    static auto fn_local_iss = make_string_stream<CharT>("");
+    [[maybe_unused]] constexpr auto isv = std::views::istream<int>(fn_local_iss);
   }
 }
 

@iskandarem

Copy link
Copy Markdown
Contributor Author

Hello @iskandarem 👋

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

* All contributions to LLVM must follow our [LLVM AI Tool Use Policy](https://llvm.org/docs/AIToolPolicy.html). In particular, if you used AI while working on this PR, remember to add a note to the PR description.

* The [LLVM Code-Review Policy and Practices](https://llvm.org/docs/CodeReview.html) document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.

* Our [LLVM Developer Policy](https://llvm.org/docs/DeveloperPolicy.html) describes our expectations for code quality, commit summaries and contains notes on our CI system.

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.

Frequently asked questions

How do I add reviewers?

This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

What if there are no comments?

If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

Are any special GitHub settings required to contribute to LLVM?

We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.

If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

Thank you, The LLVM Community

confirmed. i have read the LLVM policies.

@Zingam Zingam added the ranges Issues related to `<ranges>` label Aug 12, 2026
@Zingam Zingam changed the title Fix the LWG 3568 test for basic_istream_view [libc++][ranges] Fix the LWG 3568 test for basic_istream_view Aug 12, 2026
@Zingam

Zingam commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

I updated the title to be more in line with our practices.

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.

@frederick-vs-ja frederick-vs-ja left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworded the PR description to avoid tagging anybody and explained the modifications to the existing test case. Please double-check the changes.

We generally use the PR title and description as the squashed commit message by default. It will be disturbing if the squashed commit contains tagging and is replicated in some forks in GitHub since GitHub will send mail(s) when the replicated commit is pushed.

@github-actions

Copy link
Copy Markdown

@iskandarem Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

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

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. ranges Issues related to `<ranges>`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants