From 21ae16e203a4975c18bd3cdc7cfab33f5160ac2e Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Fri, 24 Mar 2017 05:45:39 +0000 Subject: [PATCH] Implement P0298R3: 'std::byte'. Reviewed as https://reviews.llvm.org/D31022 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@298689 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/cstddef | 29 ++++++++++++++ include/type_traits | 31 ++++++++++++++ .../support.types/byte.pass.cpp | 30 ++++++++++++++ .../support.types/byteops/and.assign.pass.cpp | 39 ++++++++++++++++++ .../support.types/byteops/and.pass.cpp | 31 ++++++++++++++ .../byteops/lshift.assign.fail.cpp | 28 +++++++++++++ .../byteops/lshift.assign.pass.cpp | 36 +++++++++++++++++ .../support.types/byteops/lshift.fail.cpp | 23 +++++++++++ .../support.types/byteops/lshift.pass.cpp | 30 ++++++++++++++ .../support.types/byteops/not.pass.cpp | 27 +++++++++++++ .../support.types/byteops/or.assign.pass.cpp | 40 +++++++++++++++++++ .../support.types/byteops/or.pass.cpp | 31 ++++++++++++++ .../byteops/rshift.assign.fail.cpp | 28 +++++++++++++ .../byteops/rshift.assign.pass.cpp | 35 ++++++++++++++++ .../support.types/byteops/rshift.fail.cpp | 23 +++++++++++ .../support.types/byteops/rshift.pass.cpp | 37 +++++++++++++++++ .../support.types/byteops/to_integer.fail.cpp | 23 +++++++++++ .../support.types/byteops/to_integer.pass.cpp | 31 ++++++++++++++ .../support.types/byteops/xor.assign.pass.cpp | 39 ++++++++++++++++++ .../support.types/byteops/xor.pass.cpp | 31 ++++++++++++++ www/cxx1z_status.html | 2 +- 21 files changed, 623 insertions(+), 1 deletion(-) create mode 100644 test/std/language.support/support.types/byte.pass.cpp create mode 100644 test/std/language.support/support.types/byteops/and.assign.pass.cpp create mode 100644 test/std/language.support/support.types/byteops/and.pass.cpp create mode 100644 test/std/language.support/support.types/byteops/lshift.assign.fail.cpp create mode 100644 test/std/language.support/support.types/byteops/lshift.assign.pass.cpp create mode 100644 test/std/language.support/support.types/byteops/lshift.fail.cpp create mode 100644 test/std/language.support/support.types/byteops/lshift.pass.cpp create mode 100644 test/std/language.support/support.types/byteops/not.pass.cpp create mode 100644 test/std/language.support/support.types/byteops/or.assign.pass.cpp create mode 100644 test/std/language.support/support.types/byteops/or.pass.cpp create mode 100644 test/std/language.support/support.types/byteops/rshift.assign.fail.cpp create mode 100644 test/std/language.support/support.types/byteops/rshift.assign.pass.cpp create mode 100644 test/std/language.support/support.types/byteops/rshift.fail.cpp create mode 100644 test/std/language.support/support.types/byteops/rshift.pass.cpp create mode 100644 test/std/language.support/support.types/byteops/to_integer.fail.cpp create mode 100644 test/std/language.support/support.types/byteops/to_integer.pass.cpp create mode 100644 test/std/language.support/support.types/byteops/xor.assign.pass.cpp create mode 100644 test/std/language.support/support.types/byteops/xor.pass.cpp diff --git a/include/cstddef b/include/cstddef index 103898b7d..62584494d 100644 --- a/include/cstddef +++ b/include/cstddef @@ -28,6 +28,7 @@ Types: size_t max_align_t nullptr_t + byte // C++17 } // std @@ -58,4 +59,32 @@ typedef long double max_align_t; _LIBCPP_END_NAMESPACE_STD +#if _LIBCPP_STD_VER > 14 +namespace std // purposefully not versioned +{ +enum class byte : unsigned char {}; + +constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = byte(static_cast(__lhs) | static_cast(__rhs)); } +constexpr byte operator| (byte __lhs, byte __rhs) noexcept +{ return byte(static_cast(__lhs) | static_cast(__rhs)); } + +constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = byte(static_cast(__lhs) & static_cast(__rhs)); } +constexpr byte operator& (byte __lhs, byte __rhs) noexcept +{ return byte(static_cast(__lhs) & static_cast(__rhs)); } + +constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = byte(static_cast(__lhs) ^ static_cast(__rhs)); } +constexpr byte operator^ (byte __lhs, byte __rhs) noexcept +{ return byte(static_cast(__lhs) ^ static_cast(__rhs)); } + +constexpr byte operator~ (byte __b) noexcept +{ return byte(~static_cast(__b)); } + +} + +#include // rest of byte +#endif + #endif // _LIBCPP_CSTDDEF diff --git a/include/type_traits b/include/type_traits index f9f1a8c0d..277a9fb07 100644 --- a/include/type_traits +++ b/include/type_traits @@ -4714,4 +4714,35 @@ struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy> _LIBCPP_END_NAMESPACE_STD +#if _LIBCPP_STD_VER > 14 +// std::byte +namespace std // purposefully not versioned +{ +template + constexpr typename enable_if, byte>::type & + operator<<=(byte& __lhs, _Integer __shift) noexcept + { return __lhs = byte(static_cast(__lhs) << __shift); } + +template + constexpr typename enable_if, byte>::type + operator<< (byte __lhs, _Integer __shift) noexcept + { return byte(static_cast(__lhs) << __shift); } + +template + constexpr typename enable_if, byte>::type & + operator>>=(byte& __lhs, _Integer __shift) noexcept + { return __lhs = byte(static_cast(__lhs) >> __shift); } + +template + constexpr typename enable_if, byte>::type + operator>> (byte __lhs, _Integer __shift) noexcept + { return byte(static_cast(__lhs) >> __shift); } + +template + constexpr typename enable_if, _Integer>::type + to_integer(byte __b) noexcept { return _Integer(__b); } + +} +#endif + #endif // _LIBCPP_TYPE_TRAITS diff --git a/test/std/language.support/support.types/byte.pass.cpp b/test/std/language.support/support.types/byte.pass.cpp new file mode 100644 index 000000000..aed44f912 --- /dev/null +++ b/test/std/language.support/support.types/byte.pass.cpp @@ -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 +#include +#include + +// 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::value, "" ); +static_assert(!std::is_arithmetic::value, "" ); +static_assert(!std::is_integral::value, "" ); + +static_assert(!std::is_same::value, "" ); +static_assert(!std::is_same::value, "" ); +static_assert(!std::is_same::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 () {} diff --git a/test/std/language.support/support.types/byteops/and.assign.pass.cpp b/test/std/language.support/support.types/byteops/and.assign.pass.cpp new file mode 100644 index 000000000..4f884e35c --- /dev/null +++ b/test/std/language.support/support.types/byteops/and.assign.pass.cpp @@ -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 +#include + +// 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(test(b1, b8)) == 0, ""); + static_assert(std::to_integer(test(b1, b9)) == 1, ""); + static_assert(std::to_integer(test(b8, b9)) == 8, ""); + + static_assert(std::to_integer(test(b8, b1)) == 0, ""); + static_assert(std::to_integer(test(b9, b1)) == 1, ""); + static_assert(std::to_integer(test(b9, b8)) == 8, ""); +} diff --git a/test/std/language.support/support.types/byteops/and.pass.cpp b/test/std/language.support/support.types/byteops/and.pass.cpp new file mode 100644 index 000000000..4b6d1caf2 --- /dev/null +++ b/test/std/language.support/support.types/byteops/and.pass.cpp @@ -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 +#include + +// 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(b1 & b8) == 0, ""); + static_assert(std::to_integer(b1 & b9) == 1, ""); + static_assert(std::to_integer(b8 & b9) == 8, ""); + + static_assert(std::to_integer(b8 & b1) == 0, ""); + static_assert(std::to_integer(b9 & b1) == 1, ""); + static_assert(std::to_integer(b9 & b8) == 8, ""); +} diff --git a/test/std/language.support/support.types/byteops/lshift.assign.fail.cpp b/test/std/language.support/support.types/byteops/lshift.assign.fail.cpp new file mode 100644 index 000000000..818a6b000 --- /dev/null +++ b/test/std/language.support/support.types/byteops/lshift.assign.fail.cpp @@ -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 +#include + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// template +// constexpr byte& operator<<=(byte& b, IntegerType shift) noexcept; +// This function shall not participate in overload resolution unless +// is_integral_v is true. + + +constexpr std::byte test(std::byte b) { + return b <<= 2.0; + } + + +int main () { + constexpr std::byte b1 = test(std::byte{1}); +} diff --git a/test/std/language.support/support.types/byteops/lshift.assign.pass.cpp b/test/std/language.support/support.types/byteops/lshift.assign.pass.cpp new file mode 100644 index 000000000..55e839530 --- /dev/null +++ b/test/std/language.support/support.types/byteops/lshift.assign.pass.cpp @@ -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 +#include + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// template +// constexpr byte& operator<<=(byte& b, IntegerType shift) noexcept; +// This function shall not participate in overload resolution unless +// is_integral_v 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(test(b2)) == 8, "" ); + static_assert(std::to_integer(test(b3)) == 12, "" ); + +} diff --git a/test/std/language.support/support.types/byteops/lshift.fail.cpp b/test/std/language.support/support.types/byteops/lshift.fail.cpp new file mode 100644 index 000000000..742f26c28 --- /dev/null +++ b/test/std/language.support/support.types/byteops/lshift.fail.cpp @@ -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 +#include + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// template +// constexpr byte operator <<(byte b, IntegerType shift) noexcept; +// These functions shall not participate in overload resolution unless +// is_integral_v is true. + +int main () { + constexpr std::byte b1{1}; + constexpr std::byte b2 = b1 << 2.0f; +} diff --git a/test/std/language.support/support.types/byteops/lshift.pass.cpp b/test/std/language.support/support.types/byteops/lshift.pass.cpp new file mode 100644 index 000000000..a8469b3c9 --- /dev/null +++ b/test/std/language.support/support.types/byteops/lshift.pass.cpp @@ -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 +#include + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// template +// constexpr byte operator <<(byte b, IntegerType shift) noexcept; +// These functions shall not participate in overload resolution unless +// is_integral_v is true. + +int main () { + constexpr std::byte b1{1}; + constexpr std::byte b3{3}; + + static_assert(noexcept(b3 << 2), "" ); + + static_assert(std::to_integer(b1 << 1) == 2, ""); + static_assert(std::to_integer(b1 << 2) == 4, ""); + static_assert(std::to_integer(b3 << 4) == 48, ""); + static_assert(std::to_integer(b3 << 6) == 192, ""); +} diff --git a/test/std/language.support/support.types/byteops/not.pass.cpp b/test/std/language.support/support.types/byteops/not.pass.cpp new file mode 100644 index 000000000..112eabd1a --- /dev/null +++ b/test/std/language.support/support.types/byteops/not.pass.cpp @@ -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 +#include + +// 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(~b1) == 254, ""); + static_assert(std::to_integer(~b2) == 253, ""); + static_assert(std::to_integer(~b8) == 247, ""); +} diff --git a/test/std/language.support/support.types/byteops/or.assign.pass.cpp b/test/std/language.support/support.types/byteops/or.assign.pass.cpp new file mode 100644 index 000000000..48bede50c --- /dev/null +++ b/test/std/language.support/support.types/byteops/or.assign.pass.cpp @@ -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 +#include + +// 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(test(b1, b2)) == 3, ""); + static_assert(std::to_integer(test(b1, b8)) == 9, ""); + static_assert(std::to_integer(test(b2, b8)) == 10, ""); + + static_assert(std::to_integer(test(b2, b1)) == 3, ""); + static_assert(std::to_integer(test(b8, b1)) == 9, ""); + static_assert(std::to_integer(test(b8, b2)) == 10, ""); + +} diff --git a/test/std/language.support/support.types/byteops/or.pass.cpp b/test/std/language.support/support.types/byteops/or.pass.cpp new file mode 100644 index 000000000..76e5c4f5c --- /dev/null +++ b/test/std/language.support/support.types/byteops/or.pass.cpp @@ -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 +#include + +// 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 b2{2}; + constexpr std::byte b8{8}; + + static_assert(noexcept(b1 | b2), "" ); + + static_assert(std::to_integer(b1 | b2) == 3, ""); + static_assert(std::to_integer(b1 | b8) == 9, ""); + static_assert(std::to_integer(b2 | b8) == 10, ""); + + static_assert(std::to_integer(b2 | b1) == 3, ""); + static_assert(std::to_integer(b8 | b1) == 9, ""); + static_assert(std::to_integer(b8 | b2) == 10, ""); +} diff --git a/test/std/language.support/support.types/byteops/rshift.assign.fail.cpp b/test/std/language.support/support.types/byteops/rshift.assign.fail.cpp new file mode 100644 index 000000000..9fec3fb1a --- /dev/null +++ b/test/std/language.support/support.types/byteops/rshift.assign.fail.cpp @@ -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 +#include + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// template +// constexpr byte operator>>(byte& b, IntegerType shift) noexcept; +// This function shall not participate in overload resolution unless +// is_integral_v is true. + + +constexpr std::byte test(std::byte b) { + return b >>= 2.0; + } + + +int main () { + constexpr std::byte b1 = test(std::byte{1}); +} diff --git a/test/std/language.support/support.types/byteops/rshift.assign.pass.cpp b/test/std/language.support/support.types/byteops/rshift.assign.pass.cpp new file mode 100644 index 000000000..e45948088 --- /dev/null +++ b/test/std/language.support/support.types/byteops/rshift.assign.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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 +#include + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// template +// constexpr byte& operator>>=(byte& b, IntegerType shift) noexcept; +// This function shall not participate in overload resolution unless +// is_integral_v 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 b16{16}; + constexpr std::byte b192{192}; + + static_assert(noexcept(b >>= 2), "" ); + + static_assert(std::to_integer(test(b16)) == 4, "" ); + static_assert(std::to_integer(test(b192)) == 48, "" ); +} diff --git a/test/std/language.support/support.types/byteops/rshift.fail.cpp b/test/std/language.support/support.types/byteops/rshift.fail.cpp new file mode 100644 index 000000000..2f94f0df8 --- /dev/null +++ b/test/std/language.support/support.types/byteops/rshift.fail.cpp @@ -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 +#include + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// template +// constexpr byte operator >>(byte b, IntegerType shift) noexcept; +// These functions shall not participate in overload resolution unless +// is_integral_v is true. + +int main () { + constexpr std::byte b1{1}; + constexpr std::byte b2 = b1 >> 2.0f; +} diff --git a/test/std/language.support/support.types/byteops/rshift.pass.cpp b/test/std/language.support/support.types/byteops/rshift.pass.cpp new file mode 100644 index 000000000..dad59512f --- /dev/null +++ b/test/std/language.support/support.types/byteops/rshift.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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 +#include + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// template +// constexpr byte operator <<(byte b, IntegerType shift) noexcept; +// These functions shall not participate in overload resolution unless +// is_integral_v is true. + + +constexpr std::byte test(std::byte b) { + return b <<= 2; + } + + +int main () { + constexpr std::byte b100{100}; + constexpr std::byte b115{115}; + + static_assert(noexcept(b100 << 2), "" ); + + static_assert(std::to_integer(b100 >> 1) == 50, ""); + static_assert(std::to_integer(b100 >> 2) == 25, ""); + static_assert(std::to_integer(b115 >> 3) == 14, ""); + static_assert(std::to_integer(b115 >> 6) == 1, ""); + +} diff --git a/test/std/language.support/support.types/byteops/to_integer.fail.cpp b/test/std/language.support/support.types/byteops/to_integer.fail.cpp new file mode 100644 index 000000000..4c76049ca --- /dev/null +++ b/test/std/language.support/support.types/byteops/to_integer.fail.cpp @@ -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 +#include + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// template +// constexpr IntegerType to_integer(byte b) noexcept; +// This function shall not participate in overload resolution unless +// is_integral_v is true. + +int main () { + constexpr std::byte b1{1}; + auto f = std::to_integer(b1); +} diff --git a/test/std/language.support/support.types/byteops/to_integer.pass.cpp b/test/std/language.support/support.types/byteops/to_integer.pass.cpp new file mode 100644 index 000000000..1ea74b401 --- /dev/null +++ b/test/std/language.support/support.types/byteops/to_integer.pass.cpp @@ -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 +#include + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// template +// constexpr IntegerType to_integer(byte b) noexcept; +// This function shall not participate in overload resolution unless +// is_integral_v is true. + +int main () { + constexpr std::byte b1{1}; + constexpr std::byte b3{3}; + + static_assert(noexcept(std::to_integer(b1)), "" ); + static_assert(std::is_same(b1))>::value, "" ); + static_assert(std::is_same(b1))>::value, "" ); + static_assert(std::is_same(b1))>::value, "" ); + + static_assert(std::to_integer(b1) == 1, ""); + static_assert(std::to_integer(b3) == 3, ""); +} diff --git a/test/std/language.support/support.types/byteops/xor.assign.pass.cpp b/test/std/language.support/support.types/byteops/xor.assign.pass.cpp new file mode 100644 index 000000000..b16cb7dbf --- /dev/null +++ b/test/std/language.support/support.types/byteops/xor.assign.pass.cpp @@ -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 +#include + +// 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(test(b1, b8)) == 9, ""); + static_assert(std::to_integer(test(b1, b9)) == 8, ""); + static_assert(std::to_integer(test(b8, b9)) == 1, ""); + + static_assert(std::to_integer(test(b8, b1)) == 9, ""); + static_assert(std::to_integer(test(b9, b1)) == 8, ""); + static_assert(std::to_integer(test(b9, b8)) == 1, ""); +} diff --git a/test/std/language.support/support.types/byteops/xor.pass.cpp b/test/std/language.support/support.types/byteops/xor.pass.cpp new file mode 100644 index 000000000..eb45ca63d --- /dev/null +++ b/test/std/language.support/support.types/byteops/xor.pass.cpp @@ -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 +#include + +// 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(b1 ^ b8) == 9, ""); + static_assert(std::to_integer(b1 ^ b9) == 8, ""); + static_assert(std::to_integer(b8 ^ b9) == 1, ""); + + static_assert(std::to_integer(b8 ^ b1) == 9, ""); + static_assert(std::to_integer(b9 ^ b1) == 8, ""); + static_assert(std::to_integer(b9 ^ b8) == 1, ""); +} diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html index 2354eb72c..6b832d6a4 100644 --- a/www/cxx1z_status.html +++ b/www/cxx1z_status.html @@ -144,7 +144,7 @@ P0156R2LWGVariadic Lock guard(rev 5)KonaComplete5.0 P0270R3CWGRemoving C dependencies from signal handler wordingKona - P0298R3CWGA byte type definitionKona + P0298R3CWGA byte type definitionKonaComplete5.0 P0317R1LWGDirectory Entry Caching for FilesystemKona P0430R2LWGFile system library on non-POSIX-like operating systemsKona P0433R2LWGToward a resolution of US7 and US14: Integrating template deduction for class templates into the standard libraryKona