mclow.lists created this revision. Implement `std::byte` from the paper http://wg21.link/P0298R3.
Split the implementation across two files; putting the stuff that needs `enable_if` into <type_traits> and the rest in <cstddef>, where it belongs. Sadly, this means that <cstddef> now includes <type_traits> (at the end). https://reviews.llvm.org/D31022 Files: include/cstddef include/type_traits test/std/language.support/support.types/byte.pass.cpp test/std/language.support/support.types/byteops/and.assign.pass.cpp test/std/language.support/support.types/byteops/and.pass.cpp test/std/language.support/support.types/byteops/lshift.assign.fail.cpp test/std/language.support/support.types/byteops/lshift.assign.pass.cpp test/std/language.support/support.types/byteops/lshift.fail.cpp test/std/language.support/support.types/byteops/lshift.pass.cpp test/std/language.support/support.types/byteops/not.pass.cpp test/std/language.support/support.types/byteops/or.assign.pass.cpp test/std/language.support/support.types/byteops/or.pass.cpp test/std/language.support/support.types/byteops/rshift.assign.fail.cpp test/std/language.support/support.types/byteops/rshift.assign.pass.cpp test/std/language.support/support.types/byteops/rshift.fail.cpp test/std/language.support/support.types/byteops/rshift.pass.cpp test/std/language.support/support.types/byteops/to_integer.fail.cpp test/std/language.support/support.types/byteops/to_integer.pass.cpp test/std/language.support/support.types/byteops/xor.assign.pass.cpp test/std/language.support/support.types/byteops/xor.pass.cpp www/cxx1z_status.html
Index: www/cxx1z_status.html =================================================================== --- www/cxx1z_status.html +++ www/cxx1z_status.html @@ -142,23 +142,25 @@ <tr><td><a href="http://wg21.link/P0517R0">P0517R0</a></td><td>LWG</td><td>Make future_error Constructible</td><td>Issaquah</td><td>Complete</td><td>4.0</td></tr> <tr><td><a href="http://wg21.link/P0521R0">P0521R0</a></td><td>LWG</td><td>Proposed Resolution for CA 14 (shared_ptr use_count/unique)</td><td>Issaquah</td><td><i>Nothing to do</i></td><td>n/a</td></tr> <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr> + <tr><td><a href="http://wg21.link/P0156R2">P0156R2</a></td><td>LWG</td><td>Variadic Lock guard</td><td>Kona</td><td></td><td></td></tr> + <tr><td><a href="http://wg21.link/P0270R3">P0270R3</a></td><td>CWG</td><td>Removing C dependencies from signal handler wording</td><td>Kona</td><td></td><td></td></tr> + <tr><td><a href="http://wg21.link/P0298R3">P0298R3</a></td><td>CWG</td><td>A byte type definition</td><td>Kona</td><td>Complete</td><td>5.0</td></tr> <tr><td><a href="http://wg21.link/P0317R1">P0317R1</a></td><td>LWG</td><td>Directory Entry Caching for Filesystem</td><td>Kona</td><td></td><td></td></tr> - <tr><td><a href="http://wg21.link/P0492R2">P0492R2</a></td><td>LWG</td><td>Proposed Resolution of C++17 National Body Comments for Filesystems</td><td>Kona</td><td></td><td></td></tr> <tr><td><a href="http://wg21.link/P0430R2">P0430R2</a></td><td>LWG</td><td>File system library on non-POSIX-like operating systems</td><td>Kona</td><td></td><td></td></tr> + <tr><td><a href="http://wg21.link/P0433R2">P0433R2</a></td><td>LWG</td><td>Toward a resolution of US7 and US14: Integrating template deduction for class templates into the standard library</td><td>Kona</td><td></td><td></td></tr> <tr><td><a href="http://wg21.link/P0452R1">P0452R1</a></td><td>LWG</td><td>Unifying <numeric> Parallel Algorithms</td><td>Kona</td><td></td><td></td></tr> + <tr><td><a href="http://wg21.link/P0467R2">P0467R2</a></td><td>LWG</td><td>Iterator Concerns for Parallel Algorithms</td><td>Kona</td><td></td><td></td></tr> + <tr><td><a href="http://wg21.link/P0492R2">P0492R2</a></td><td>LWG</td><td>Proposed Resolution of C++17 National Body Comments for Filesystems</td><td>Kona</td><td></td><td></td></tr> <tr><td><a href="http://wg21.link/P0518R1">P0518R1</a></td><td>LWG</td><td>Allowing copies as arguments to function objects given to parallel algorithms in response to CH11</td><td>Kona</td><td></td><td></td></tr> <tr><td><a href="http://wg21.link/P0523R1">P0523R1</a></td><td>LWG</td><td>Wording for CH 10: Complexity of parallel algorithms</td><td>Kona</td><td></td><td></td></tr> + <tr><td><a href="http://wg21.link/P0548R1">P0548R1</a></td><td>LWG</td><td>common_type and duration</td><td>Kona</td><td></td><td></td></tr> + <tr><td><a href="http://wg21.link/P0558R1">P0558R1</a></td><td>LWG</td><td>Resolving atomic<T> named base class inconsistencies</td><td>Kona</td><td></td><td></td></tr> <tr><td><a href="http://wg21.link/P0574R1">P0574R1</a></td><td>LWG</td><td>Algorithm Complexity Constraints and Parallel Overloads</td><td>Kona</td><td></td><td></td></tr> - <tr><td><a href="http://wg21.link/P0467R2">P0467R2</a></td><td>LWG</td><td>Iterator Concerns for Parallel Algorithms</td><td>Kona</td><td></td><td></td></tr> - <tr><td><a href="http://wg21.link/P0623R0">P0623R0</a></td><td>LWG</td><td>Final C++17 Parallel Algorithms Fixes</td><td>Kona</td><td></td><td></td></tr> + <tr><td><a href="http://wg21.link/P0599R1">P0599R1</a></td><td>LWG</td><td>noexcept for hash functions</td><td>Kona</td><td></td><td></td></tr> <tr><td><a href="http://wg21.link/P0604R0">P0604R0</a></td><td>LWG</td><td>Resolving GB 55, US 84, US 85, US 86</td><td>Kona</td><td></td><td></td></tr> <tr><td><a href="http://wg21.link/P0607R0">P0607R0</a></td><td>LWG</td><td>Inline Variables for the Standard Library</td><td>Kona</td><td></td><td></td></tr> <tr><td><a href="http://wg21.link/P0618R0">P0618R0</a></td><td>LWG</td><td>Deprecating <codecvt></td><td>Kona</td><td></td><td></td></tr> - <tr><td><a href="http://wg21.link/P0156R2">P0156R2</a></td><td>LWG</td><td>Variadic Lock guard</td><td>Kona</td><td></td><td></td></tr> - <tr><td><a href="http://wg21.link/P0599R1">P0599R1</a></td><td>LWG</td><td>noexcept for hash functions</td><td>Kona</td><td></td><td></td></tr> - <tr><td><a href="http://wg21.link/P0433R2">P0433R2</a></td><td>LWG</td><td>Toward a resolution of US7 and US14: Integrating template deduction for class templates into the standard library</td><td>Kona</td><td></td><td></td></tr> - <tr><td><a href="http://wg21.link/P0558R1">P0558R1</a></td><td>LWG</td><td>Resolving atomic<T> named base class inconsistencies</td><td>Kona</td><td></td><td></td></tr> - <tr><td><a href="http://wg21.link/P0548R1">P0548R1</a></td><td>LWG</td><td>common_type and duration</td><td>Kona</td><td></td><td></td></tr> + <tr><td><a href="http://wg21.link/P0623R0">P0623R0</a></td><td>LWG</td><td>Final C++17 Parallel Algorithms Fixes</td><td>Kona</td><td></td><td></td></tr> <!-- <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr> --> </table> Index: test/std/language.support/support.types/byteops/xor.pass.cpp =================================================================== --- test/std/language.support/support.types/byteops/xor.pass.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// XFAIL: 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) == 9, ""); + static_assert(std::to_integer<int>(b1 ^ b9) == 8, ""); + static_assert(std::to_integer<int>(b8 ^ b9) == 1, ""); + + static_assert(std::to_integer<int>(b8 ^ b1) == 9, ""); + static_assert(std::to_integer<int>(b9 ^ b1) == 8, ""); + static_assert(std::to_integer<int>(b9 ^ b8) == 1, ""); +} Index: test/std/language.support/support.types/byteops/xor.assign.pass.cpp =================================================================== --- test/std/language.support/support.types/byteops/xor.assign.pass.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// XFAIL: 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)) == 9, ""); + static_assert(std::to_integer<int>(test(b1, b9)) == 8, ""); + static_assert(std::to_integer<int>(test(b8, b9)) == 1, ""); + + static_assert(std::to_integer<int>(test(b8, b1)) == 9, ""); + static_assert(std::to_integer<int>(test(b9, b1)) == 8, ""); + static_assert(std::to_integer<int>(test(b9, b8)) == 1, ""); +} Index: test/std/language.support/support.types/byteops/to_integer.pass.cpp =================================================================== --- test/std/language.support/support.types/byteops/to_integer.pass.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// XFAIL: c++98, c++03, c++11, c++14 + +// template <class IntegerType> +// constexpr IntegerType to_integer(byte b) noexcept; +// This function 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(std::to_integer<int>(b1)), "" ); + static_assert(std::is_same<int, decltype(std::to_integer<int>(b1))>::value, "" ); + static_assert(std::is_same<long, decltype(std::to_integer<long>(b1))>::value, "" ); + static_assert(std::is_same<unsigned short, decltype(std::to_integer<unsigned short>(b1))>::value, "" ); + + static_assert(std::to_integer<int>(b1) == 1, ""); + static_assert(std::to_integer<int>(b3) == 3, ""); +} Index: test/std/language.support/support.types/byteops/to_integer.fail.cpp =================================================================== --- test/std/language.support/support.types/byteops/to_integer.fail.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// template <class IntegerType> +// constexpr IntegerType to_integer(byte b) noexcept; +// This function shall not participate in overload resolution unless +// is_integral_v<IntegerType> is true. + +int main () { + constexpr std::byte b1{1}; + auto f = std::to_integer<float>(b1); +} Index: test/std/language.support/support.types/byteops/rshift.pass.cpp =================================================================== --- test/std/language.support/support.types/byteops/rshift.pass.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// XFAIL: 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. + + +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<int>(b100 >> 1) == 50, ""); + static_assert(std::to_integer<int>(b100 >> 2) == 25, ""); + static_assert(std::to_integer<int>(b115 >> 3) == 14, ""); + static_assert(std::to_integer<int>(b115 >> 6) == 1, ""); + +} Index: test/std/language.support/support.types/byteops/rshift.fail.cpp =================================================================== --- test/std/language.support/support.types/byteops/rshift.fail.cpp +++ 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 <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; +} Index: test/std/language.support/support.types/byteops/rshift.assign.pass.cpp =================================================================== --- test/std/language.support/support.types/byteops/rshift.assign.pass.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// XFAIL: 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 b16{16}; + constexpr std::byte b192{192}; + + static_assert(noexcept(b >>= 2), "" ); + + static_assert(std::to_integer<int>(test(b16)) == 4, "" ); + static_assert(std::to_integer<int>(test(b192)) == 48, "" ); +} Index: test/std/language.support/support.types/byteops/rshift.assign.fail.cpp =================================================================== --- test/std/language.support/support.types/byteops/rshift.assign.fail.cpp +++ 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 <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}); +} Index: test/std/language.support/support.types/byteops/or.pass.cpp =================================================================== --- test/std/language.support/support.types/byteops/or.pass.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// XFAIL: 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<int>(b1 | b2) == 3, ""); + static_assert(std::to_integer<int>(b1 | b8) == 9, ""); + static_assert(std::to_integer<int>(b2 | b8) == 10, ""); + + static_assert(std::to_integer<int>(b2 | b1) == 3, ""); + static_assert(std::to_integer<int>(b8 | b1) == 9, ""); + static_assert(std::to_integer<int>(b8 | b2) == 10, ""); +} Index: test/std/language.support/support.types/byteops/or.assign.pass.cpp =================================================================== --- test/std/language.support/support.types/byteops/or.assign.pass.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// XFAIL: 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, ""); + +} Index: test/std/language.support/support.types/byteops/not.pass.cpp =================================================================== --- test/std/language.support/support.types/byteops/not.pass.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// XFAIL: 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, ""); +} Index: test/std/language.support/support.types/byteops/lshift.pass.cpp =================================================================== --- test/std/language.support/support.types/byteops/lshift.pass.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// XFAIL: 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, ""); +} Index: test/std/language.support/support.types/byteops/lshift.fail.cpp =================================================================== --- test/std/language.support/support.types/byteops/lshift.fail.cpp +++ 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 <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; +} Index: test/std/language.support/support.types/byteops/lshift.assign.pass.cpp =================================================================== --- test/std/language.support/support.types/byteops/lshift.assign.pass.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// XFAIL: 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, "" ); + +} Index: test/std/language.support/support.types/byteops/lshift.assign.fail.cpp =================================================================== --- test/std/language.support/support.types/byteops/lshift.assign.fail.cpp +++ 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 <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}); +} Index: test/std/language.support/support.types/byteops/and.pass.cpp =================================================================== --- test/std/language.support/support.types/byteops/and.pass.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// XFAIL: 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, ""); +} Index: test/std/language.support/support.types/byteops/and.assign.pass.cpp =================================================================== --- test/std/language.support/support.types/byteops/and.assign.pass.cpp +++ 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 <cstddef> +#include <test_macros.h> + +// XFAIL: 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, ""); +} Index: test/std/language.support/support.types/byte.pass.cpp =================================================================== --- test/std/language.support/support.types/byte.pass.cpp +++ 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 <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 () {} Index: include/type_traits =================================================================== --- include/type_traits +++ include/type_traits @@ -4705,6 +4705,33 @@ #endif +#if _LIBCPP_STD_VER > 14 +// std::byte +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, byte>::type & + operator<<=(byte& __lhs, _Integer __shift) noexcept + { return __lhs = byte(static_cast<unsigned char>(__lhs) << __shift); } + +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, byte>::type + operator<< (byte __lhs, _Integer __shift) noexcept + { return byte(static_cast<unsigned char>(__lhs) << __shift); } + +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, byte>::type & + operator>>=(byte& __lhs, _Integer __shift) noexcept + { return __lhs = byte(static_cast<unsigned char>(__lhs) >> __shift); } + +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, byte>::type + operator>> (byte __lhs, _Integer __shift) noexcept + { return byte(static_cast<unsigned char>(__lhs) >> __shift); } + +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, _Integer>::type + to_integer(byte __b) noexcept { return _Integer(__b); } +#endif + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_TYPE_TRAITS Index: include/cstddef =================================================================== --- include/cstddef +++ include/cstddef @@ -28,7 +28,7 @@ size_t max_align_t nullptr_t - + byte // C++17 } // std */ @@ -56,6 +56,29 @@ typedef long double max_align_t; #endif +#if _LIBCPP_STD_VER > 14 +enum class byte : unsigned char {}; + +constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = byte(static_cast<unsigned char>(__lhs) | static_cast<unsigned char>(__rhs)); } +constexpr byte operator| (byte __lhs, byte __rhs) noexcept +{ return byte(static_cast<unsigned char>(__lhs) | static_cast<unsigned char>(__rhs)); } + +constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = byte(static_cast<unsigned char>(__lhs) & static_cast<unsigned char>(__rhs)); } +constexpr byte operator& (byte __lhs, byte __rhs) noexcept +{ return byte(static_cast<unsigned char>(__lhs) & static_cast<unsigned char>(__rhs)); } + +constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = byte(static_cast<unsigned char>(__lhs) ^ static_cast<unsigned char>(__rhs)); } +constexpr byte operator^ (byte __lhs, byte __rhs) noexcept +{ return byte(static_cast<unsigned char>(__lhs) ^ static_cast<unsigned char>(__rhs)); } + +constexpr byte operator~ (byte __b) noexcept +{ return byte(~static_cast<unsigned char>(__b)); } +#endif + _LIBCPP_END_NAMESPACE_STD +#include <type_traits> // rest of byte #endif // _LIBCPP_CSTDDEF
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits