Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent calling make_optional<int&>(i) or make_optional<const int&>(i) #59

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Commits on Sep 16, 2024

  1. Configuration menu
    Copy the full SHA
    83674c8 View commit details
    Browse the repository at this point in the history
  2. [test] Fix warnings from Clang trunk

    `static_cast` to lvalue suppresses Clang's self-assignment warning.
    Add (missing?) EXPECTs to silence Clang's unused-variable warning.
    Add an accessor to suppress Clang's unused-private-field warning.
    Drive-by rename "empty_base" to "disengaged_base", since the phrase
    "empty base" means something different in C++.
    Quuxplusone committed Sep 16, 2024
    Configuration menu
    Copy the full SHA
    50d8616 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    926663c View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    eba41fd View commit details
    Browse the repository at this point in the history
  5. Support optional<optional<int>&>

    Add two new tests: one for `optional<optional<int>&>`, and one
    testing that we can construct and assign to `optional<T&>` from
    `reference_wrapper<T>` (which should work: since `reference_wrapper<T>`
    is implicitly convertible to `T&`, it also should be implicitly
    convertible to `optional<T&>`).
    These tests are both red before this patch and green afterward.
    Quuxplusone committed Sep 16, 2024
    Configuration menu
    Copy the full SHA
    cd93469 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    fbf4b1c View commit details
    Browse the repository at this point in the history
  7. Support binding optional<const T&> to a non-const T, and add tests

    The new tests are red before the patch and green afterward.
    Quuxplusone committed Sep 16, 2024
    Configuration menu
    Copy the full SHA
    a6333d3 View commit details
    Browse the repository at this point in the history
  8. Support optional<T&>::emplace, and add tests

    The return type of `emplace` had been wrong; `emplace` returns a
    reference to the emplaced value (in this case, the T& reference
    that was bound), not `*this`.
    
    The new tests are red before the patch and green afterward.
    Quuxplusone committed Sep 16, 2024
    Configuration menu
    Copy the full SHA
    986b975 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    4448d97 View commit details
    Browse the repository at this point in the history

Commits on Sep 18, 2024

  1. [test] Add another green test for overload resolution

    This test fails with at least one alternative approach to the
    constructor overload set (involving =delete'd candidates which
    make this overload resolution ambiguous).
    Quuxplusone committed Sep 18, 2024
    Configuration menu
    Copy the full SHA
    8767b1e View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4422189 View commit details
    Browse the repository at this point in the history
  3. Prevent calling make_optional<int&>(i) or make_optional<const int&>(i)

    The status quo in C++23 is that
        int i;
        auto o = make_optional<int&>(i);
    produces an `optional<int>`, not an `optional<int&>`. This would be horribly
    confusing to propagate into C++26 — users would naturally expect to receive
    an `optional<int&>`. Worse,
        auto o = make_optional<int&>(std::ref(i));
    actually *would* give you an `optional<int&>`, because it would use a different
    overload of `make_optional`! So, we propose to add a "Mandates" element to
    `make_optional` that requires its explicit template argument (if any) to be
    a non-array object type.
    This breaks the "status quo" example at the top of this comment (requiring
    an Annex C entry); but it successfully prevents the pitfalls.
    
    Thanks to Tomasz Kamiński for the template-programming trick, which matches
    the technique used in https://eel.is/c++draft/out.ptr .
    Quuxplusone committed Sep 18, 2024
    Configuration menu
    Copy the full SHA
    7f0aa7e View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    9b8ce75 View commit details
    Browse the repository at this point in the history