-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement P0298R3: 'std::byte'. Reviewed as https://reviews.llvm.org/…
…D31022 llvm-svn: 298689
- Loading branch information
Showing
21 changed files
with
623 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
libcxx/test/std/language.support/support.types/byte.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <cstddef> | ||
| #include <type_traits> | ||
| #include <test_macros.h> | ||
|
|
||
| // XFAIL: c++98, c++03, c++11, c++14 | ||
|
|
||
| // std::byte is not an integer type, nor a character type. | ||
| // It is a distinct type for accessing the bits that ultimately make up object storage. | ||
|
|
||
| static_assert( std::is_pod<std::byte>::value, "" ); | ||
| static_assert(!std::is_arithmetic<std::byte>::value, "" ); | ||
| static_assert(!std::is_integral<std::byte>::value, "" ); | ||
|
|
||
| static_assert(!std::is_same<std::byte, char>::value, "" ); | ||
| static_assert(!std::is_same<std::byte, signed char>::value, "" ); | ||
| static_assert(!std::is_same<std::byte, unsigned char>::value, "" ); | ||
|
|
||
| // The standard doesn't outright say this, but it's pretty clear that it has to be true. | ||
| static_assert(sizeof(std::byte) == 1, "" ); | ||
|
|
||
| int main () {} |
39 changes: 39 additions & 0 deletions
39
libcxx/test/std/language.support/support.types/byteops/and.assign.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <cstddef> | ||
| #include <test_macros.h> | ||
|
|
||
| // UNSUPPORTED: c++98, c++03, c++11, c++14 | ||
|
|
||
| // constexpr byte& operator &=(byte l, byte r) noexcept; | ||
|
|
||
|
|
||
| constexpr std::byte test(std::byte b1, std::byte b2) { | ||
| std::byte bret = b1; | ||
| return bret &= b2; | ||
| } | ||
|
|
||
|
|
||
| int main () { | ||
| std::byte b; // not constexpr, just used in noexcept check | ||
| constexpr std::byte b1{1}; | ||
| constexpr std::byte b8{8}; | ||
| constexpr std::byte b9{9}; | ||
|
|
||
| static_assert(noexcept(b &= b), "" ); | ||
|
|
||
| static_assert(std::to_integer<int>(test(b1, b8)) == 0, ""); | ||
| static_assert(std::to_integer<int>(test(b1, b9)) == 1, ""); | ||
| static_assert(std::to_integer<int>(test(b8, b9)) == 8, ""); | ||
|
|
||
| static_assert(std::to_integer<int>(test(b8, b1)) == 0, ""); | ||
| static_assert(std::to_integer<int>(test(b9, b1)) == 1, ""); | ||
| static_assert(std::to_integer<int>(test(b9, b8)) == 8, ""); | ||
| } |
31 changes: 31 additions & 0 deletions
31
libcxx/test/std/language.support/support.types/byteops/and.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <cstddef> | ||
| #include <test_macros.h> | ||
|
|
||
| // UNSUPPORTED: c++98, c++03, c++11, c++14 | ||
|
|
||
| // constexpr byte operator&(byte l, byte r) noexcept; | ||
|
|
||
| int main () { | ||
| constexpr std::byte b1{1}; | ||
| constexpr std::byte b8{8}; | ||
| constexpr std::byte b9{9}; | ||
|
|
||
| static_assert(noexcept(b1 & b8), "" ); | ||
|
|
||
| static_assert(std::to_integer<int>(b1 & b8) == 0, ""); | ||
| static_assert(std::to_integer<int>(b1 & b9) == 1, ""); | ||
| static_assert(std::to_integer<int>(b8 & b9) == 8, ""); | ||
|
|
||
| static_assert(std::to_integer<int>(b8 & b1) == 0, ""); | ||
| static_assert(std::to_integer<int>(b9 & b1) == 1, ""); | ||
| static_assert(std::to_integer<int>(b9 & b8) == 8, ""); | ||
| } |
28 changes: 28 additions & 0 deletions
28
libcxx/test/std/language.support/support.types/byteops/lshift.assign.fail.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <cstddef> | ||
| #include <test_macros.h> | ||
|
|
||
| // UNSUPPORTED: c++98, c++03, c++11, c++14 | ||
|
|
||
| // template <class IntegerType> | ||
| // constexpr byte& operator<<=(byte& b, IntegerType shift) noexcept; | ||
| // This function shall not participate in overload resolution unless | ||
| // is_integral_v<IntegerType> is true. | ||
|
|
||
|
|
||
| constexpr std::byte test(std::byte b) { | ||
| return b <<= 2.0; | ||
| } | ||
|
|
||
|
|
||
| int main () { | ||
| constexpr std::byte b1 = test(std::byte{1}); | ||
| } |
36 changes: 36 additions & 0 deletions
36
libcxx/test/std/language.support/support.types/byteops/lshift.assign.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <cstddef> | ||
| #include <test_macros.h> | ||
|
|
||
| // UNSUPPORTED: c++98, c++03, c++11, c++14 | ||
|
|
||
| // template <class IntegerType> | ||
| // constexpr byte& operator<<=(byte& b, IntegerType shift) noexcept; | ||
| // This function shall not participate in overload resolution unless | ||
| // is_integral_v<IntegerType> is true. | ||
|
|
||
|
|
||
| constexpr std::byte test(std::byte b) { | ||
| return b <<= 2; | ||
| } | ||
|
|
||
|
|
||
| int main () { | ||
| std::byte b; // not constexpr, just used in noexcept check | ||
| constexpr std::byte b2{2}; | ||
| constexpr std::byte b3{3}; | ||
|
|
||
| static_assert(noexcept(b <<= 2), "" ); | ||
|
|
||
| static_assert(std::to_integer<int>(test(b2)) == 8, "" ); | ||
| static_assert(std::to_integer<int>(test(b3)) == 12, "" ); | ||
|
|
||
| } |
23 changes: 23 additions & 0 deletions
23
libcxx/test/std/language.support/support.types/byteops/lshift.fail.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <cstddef> | ||
| #include <test_macros.h> | ||
|
|
||
| // UNSUPPORTED: c++98, c++03, c++11, c++14 | ||
|
|
||
| // template <class IntegerType> | ||
| // constexpr byte operator <<(byte b, IntegerType shift) noexcept; | ||
| // These functions shall not participate in overload resolution unless | ||
| // is_integral_v<IntegerType> is true. | ||
|
|
||
| int main () { | ||
| constexpr std::byte b1{1}; | ||
| constexpr std::byte b2 = b1 << 2.0f; | ||
| } |
30 changes: 30 additions & 0 deletions
30
libcxx/test/std/language.support/support.types/byteops/lshift.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <cstddef> | ||
| #include <test_macros.h> | ||
|
|
||
| // UNSUPPORTED: c++98, c++03, c++11, c++14 | ||
|
|
||
| // template <class IntegerType> | ||
| // constexpr byte operator <<(byte b, IntegerType shift) noexcept; | ||
| // These functions shall not participate in overload resolution unless | ||
| // is_integral_v<IntegerType> is true. | ||
|
|
||
| int main () { | ||
| constexpr std::byte b1{1}; | ||
| constexpr std::byte b3{3}; | ||
|
|
||
| static_assert(noexcept(b3 << 2), "" ); | ||
|
|
||
| static_assert(std::to_integer<int>(b1 << 1) == 2, ""); | ||
| static_assert(std::to_integer<int>(b1 << 2) == 4, ""); | ||
| static_assert(std::to_integer<int>(b3 << 4) == 48, ""); | ||
| static_assert(std::to_integer<int>(b3 << 6) == 192, ""); | ||
| } |
27 changes: 27 additions & 0 deletions
27
libcxx/test/std/language.support/support.types/byteops/not.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <cstddef> | ||
| #include <test_macros.h> | ||
|
|
||
| // UNSUPPORTED: c++98, c++03, c++11, c++14 | ||
|
|
||
| // constexpr byte operator~(byte b) noexcept; | ||
|
|
||
| int main () { | ||
| constexpr std::byte b1{1}; | ||
| constexpr std::byte b2{2}; | ||
| constexpr std::byte b8{8}; | ||
|
|
||
| static_assert(noexcept(~b1), "" ); | ||
|
|
||
| static_assert(std::to_integer<int>(~b1) == 254, ""); | ||
| static_assert(std::to_integer<int>(~b2) == 253, ""); | ||
| static_assert(std::to_integer<int>(~b8) == 247, ""); | ||
| } |
40 changes: 40 additions & 0 deletions
40
libcxx/test/std/language.support/support.types/byteops/or.assign.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <cstddef> | ||
| #include <test_macros.h> | ||
|
|
||
| // UNSUPPORTED: c++98, c++03, c++11, c++14 | ||
|
|
||
| // constexpr byte& operator |=(byte l, byte r) noexcept; | ||
|
|
||
|
|
||
| constexpr std::byte test(std::byte b1, std::byte b2) { | ||
| std::byte bret = b1; | ||
| return bret |= b2; | ||
| } | ||
|
|
||
|
|
||
| int main () { | ||
| std::byte b; // not constexpr, just used in noexcept check | ||
| constexpr std::byte b1{1}; | ||
| constexpr std::byte b2{2}; | ||
| constexpr std::byte b8{8}; | ||
|
|
||
| static_assert(noexcept(b |= b), "" ); | ||
|
|
||
| static_assert(std::to_integer<int>(test(b1, b2)) == 3, ""); | ||
| static_assert(std::to_integer<int>(test(b1, b8)) == 9, ""); | ||
| static_assert(std::to_integer<int>(test(b2, b8)) == 10, ""); | ||
|
|
||
| static_assert(std::to_integer<int>(test(b2, b1)) == 3, ""); | ||
| static_assert(std::to_integer<int>(test(b8, b1)) == 9, ""); | ||
| static_assert(std::to_integer<int>(test(b8, b2)) == 10, ""); | ||
|
|
||
| } |
Oops, something went wrong.