This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] LWG2485: get() should be overloaded for const tuple&&
ClosedPublic

Authored by K-ballo on Nov 19 2015, 12:56 PM.

Details

Summary

Implement LWG2485, get() should be overloaded for const tuple&&.

Diff Detail

Event Timeline

K-ballo updated this revision to Diff 40694.Nov 19 2015, 12:56 PM
K-ballo retitled this revision from to [libcxx] LWG2485: get() should be overloaded for const tuple&&.
K-ballo updated this object.
K-ballo added reviewers: mclow.lists, EricWF.
K-ballo added a subscriber: cfe-commits.
EricWF edited edge metadata.Dec 9 2015, 12:56 PM

Added initial review comments.

I need to look a little more into how we form the rvalue reference to the returned element in the case where the element is an lvalue reference. I think it's currently correct but I just want to double check. I think the new language is a bit vague when it says get returns a reference to the element.

test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp
33
  1. Please test the constexprness of this function in C++14 and beyond.
  2. Please static_assert the return type using decltype. The assignment to the expected type might hide conversions (though I doubt it in this case).
test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.fail.cpp
31

Add // expected-error {{call to deleted function 'cref'}} to the end of this line to make the test use clang verify.

test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.pass.cpp
27

Same note as on the array test.

test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp
25

I prefer using // UNSUPPORTED: c++98, c++03 instead of conditional compilation. That way LIT can report that the test was not run.

26

Same note as the array and tuple tests.

test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp
59

This test seems wrong to me. The name of the file suggests we are testing the "by-type" overloads but your tests use indexes with get. It seems like the test above yours does the same thing as well.

Also please add constexpr tests and tests for the second type as well.

EricWF added a comment.Dec 9 2015, 1:05 PM

To expand on my concerns about lvalue elements, I would like to see tests something like this:

int x = 42;
int const y = 43;
std::pair<int&, int const&> const p(x, y);
static_assert(std::is_same<int const&, decltype(std::get<0>(std::move(p)))>::value, "");
static_assert(std::is_same<int const&, decltype(std::get<1>(std::move(p)))>::value, "");

I assume you agree that this test has the correct behavior?

K-ballo marked 2 inline comments as done.Dec 10 2015, 7:37 AM
int x = 42;
int const y = 43;
std::pair<int&, int const&> const p(x, y);
static_assert(std::is_same<int const&, decltype(std::get<0>(std::move(p)))>::value, "");
static_assert(std::is_same<int const&, decltype(std::get<1>(std::move(p)))>::value, "");

I assume you agree that this test has the correct behavior?

I believe the first static_assert is incorrect, const is shallow so it should be just int&.

K-ballo updated this revision to Diff 42432.Dec 10 2015, 8:54 AM
K-ballo edited edge metadata.

Addressed review comments

Pair and array look good. Still have to look at tuple.

Could you add test that check the overloads are actually noexcept as well?

include/utility
151

Can you add the by-type overloads to the synopsis? I noticed the current overloads are missing as well, so if your feeling kind can you add those?

test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp
22

#include "test_macros.h"

test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp
25

This needs #include "test_macros.h" to get TEST_STD_VER

test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp
20–21

Can you TEST_STD_VER this while your here?

LGTM after the requested changes. Thanks.

test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.fail.cpp
31

Could you add a comment about why this test is important? On it's face it looks a little silly but it's really the rational for this entire change.

test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.pass.cpp
26

#include "test_macros.h"

51

Test for int&& and int const&& as well please.

test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp
21–22

You can remove this guard. The test is already supported for C++11 and earlier.

71

Same as above: Rvalue ref tests.

test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp
39

Same as above: Rvalue ref tests.

test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp
62

rvalue ref tests please.

int x = 42;
int const y = 43;
std::pair<int&, int const&> const p(x, y);
static_assert(std::is_same<int const&, decltype(std::get<0>(std::move(p)))>::value, "");
static_assert(std::is_same<int const&, decltype(std::get<1>(std::move(p)))>::value, "");

I assume you agree that this test has the correct behavior?

I believe the first static_assert is incorrect, const is shallow so it should be just int&.

BTW your correct.

K-ballo updated this revision to Diff 42892.Dec 15 2015, 12:32 PM
K-ballo marked 15 inline comments as done.

Addressed review comments. Use UNSUPPORTED in pairs.by.type.pass.

EricWF accepted this revision.Dec 17 2015, 4:37 PM
EricWF edited edge metadata.

LGTM. Thanks.

This revision is now accepted and ready to land.Dec 17 2015, 4:37 PM
EricWF closed this revision.Dec 17 2015, 4:40 PM

r255941.