Page MenuHomePhabricator

[libcxx] Adds [concept.same]
Needs ReviewPublic

Authored by cjdb on Sat, Feb 8, 4:54 PM.

Details

Summary

Adds std::same_as to libc++. Since there aren't clang-format rules for requires-expressions, I'll need to disable the formatter in certain areas.

Diff Detail

Event Timeline

cjdb created this revision.Sat, Feb 8, 4:54 PM
cjdb updated this revision to Diff 243426.Sat, Feb 8, 8:23 PM

Added a check for constness and removed some Unicode zero-width joiners.

cjdb updated this revision to Diff 243427.Sat, Feb 8, 8:26 PM
miscco added inline comments.Sat, Feb 8, 11:29 PM
libcxx/include/concepts
149

You are missing the uglification of all namens throughout the code. Mind not in Tests.

T -> _Tp

This looks already quite good.

There are some pecularities of standard implementations that need to be considered. I started with the easy parts recently here

https://github.com/miscco/llvm-project/tree/concepts_wip

libcxx/include/concepts
150

Thinking about it more, this will not work with other compilers such as MSVC. You should seither check the Compiler aka #ifdef clang or the existence of the keyword

libcxx/test/std/concepts/lang/same_as.pass.cpp
9

This test is only valid in C++20 so you should add that

// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17

12

Usually there is a comment about what is tested here

template<class T, class U>
concept same_as;

miscco added inline comments.Sat, Feb 8, 11:41 PM
libcxx/include/concepts
150

As the code was not displayed properly

template <class _Tp, class _Up>
concept __same_as_impl =
#ifdef __clang__
    __is_same(_Tp, _Up);
#else
    _VSTD::is_same_v<_Tp, _Up>;
#endif
CaseyCarter requested changes to this revision.Sun, Feb 9, 8:28 AM

Missing a bunch of "Add a new header" changes (https://github.com/llvm/llvm-project/blob/master/libcxx/NOTES.TXT#L19-L29).

libcxx/include/concepts
9

Shouldn't this line have the same length as line 2?

140
146

Should this also guard with defined(__cpp_concepts) && __cpp_concepts >= 201811L? There are a great many compiler (version)s with C++20 mode that don't implement concepts - I assume libc++ wants to continue supporting them.

150

Clang has supported __is_same since roughly clang 3. I didn't remember precisely how far back libc++ supports, but it's not that far - so assuming __is_same when __clang__ is fine. GCC since version 6 supports __is_same_as with the same semantics. (MSVC has none of the above, but std::is_same_v is one of the type traits we recognize and implement directly in the compiler front end, so it's ideal to simply use is_same_v with MSVC.)

libcxx/test/std/concepts/lang/same_as.pass.cpp
82

I think we can trust a C++20 compiler to implement C++11 correctly and accept >> here without the space ;)

154

libc++ tests always use int main(int, char**) { (something something freestanding - I don't recall the details)

190

There's tons of coverage here for class types and reference types. What about void, function types, pointers, arrays, pointers-to-members? (I don't know about clang/libc++, but the MSVC STL tests for type traits tend to _be_ the tests for compiler intrinsics used to implement those traits, so we consequently cover everything under the sun.)

191

libc++ tests also always explicitly return 0. (Ditto freestanding yada yada)

This revision now requires changes to proceed.Sun, Feb 9, 8:28 AM
miscco added a comment.Sun, Feb 9, 1:05 PM

For what its worth, I found some time today to cleanup what I had already done with @CaseyCarter old implementation D49118 (common_type and common_reference were missing).

I havent yet implemented swap as that should be handled consistently with the other CPOs when implementing ranges.

Feel free to salvage as much as you like

https://github.com/miscco/llvm-project/tree/concepts_wip

zoecarver added inline comments.
libcxx/include/concepts
150

You can also use _IsSame which should pick the best possible definition for you.

cjdb updated this revision to Diff 243733.Mon, Feb 10, 8:46 PM
cjdb marked 17 inline comments as done.
cjdb added inline comments.Mon, Feb 10, 8:47 PM
libcxx/include/concepts
146

Agreed.

149

Fixed.

libcxx/test/std/concepts/lang/same_as.pass.cpp
82

Agreed. *Stares intensely at clang-format*

190
  • void (/)
  • function types (/)
  • pointers (/)
  • arrays (/)
  • pointers-to-members (/)
  • pointers-to-member functions (/)
miscco added inline comments.Fri, Feb 14, 2:37 AM
libcxx/test/std/concepts/lang/same_as.pass.cpp
46

Out of curiosity should that be T1 t1; and below T2 t2;

188

Nitpick, if we go for all the different qualifiers/references there should be a test for volatile to

    // Checks std::same_as<volatile T, volatile T> is true
    CheckSameAs<std::add_volatile>();
`
229

Same as above volatile is missing

CaseyCarter resigned from this revision.Fri, Feb 14, 3:15 AM

LGTM. I'll resign rather than approving so the "real" approvers won't be confused and never look at this.

cjdb marked an inline comment as done.Sun, Feb 16, 9:16 PM
cjdb added inline comments.
libcxx/test/std/concepts/lang/same_as.pass.cpp
46

It probably could be, but it doesn't make a difference for this test.