-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] [C++2b] [P1048] Add is_scoped_enum and is_scoped_enum_v.
* https://wg21.link/p1048 Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D94409
- Loading branch information
Showing
8 changed files
with
155 additions
and
26 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
"Paper #","Group","Paper Name","Meeting","Status","First released version" | ||
"`P0881R7 <https://wg21.link/P0881R7>`__","LWG","A Proposal to add stacktrace library","Autumn 2020","","" | ||
"`P0943R6 <https://wg21.link/P0943R6>`__","LWG","Support C atomics in C++","Autumn 2020","","" | ||
"`P1048R1 <https://wg21.link/P1048R1>`__","LWG","A proposal for a type trait to detect scoped enumerations","Autumn 2020","","" | ||
"`P1048R1 <https://wg21.link/P1048R1>`__","LWG","A proposal for a type trait to detect scoped enumerations","Autumn 2020","|Complete|","12.0" | ||
"`P1679R3 <https://wg21.link/P1679R3>`__","LWG","string contains function","Autumn 2020","","" | ||
"","","","","","" |
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
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
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
120 changes: 120 additions & 0 deletions
120
libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_scoped_enum.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,120 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2a | ||
|
||
// type_traits | ||
|
||
// is_scoped_enum // C++2b | ||
|
||
#include <type_traits> | ||
#include <cstddef> // for std::nullptr_t | ||
#include "test_macros.h" | ||
|
||
template <class T> | ||
void test_positive() { | ||
static_assert(std::is_scoped_enum<T>::value); | ||
static_assert(std::is_scoped_enum<const T>::value); | ||
static_assert(std::is_scoped_enum<volatile T>::value); | ||
static_assert(std::is_scoped_enum<const volatile T>::value); | ||
|
||
static_assert(std::is_scoped_enum_v<T>); | ||
static_assert(std::is_scoped_enum_v<const T>); | ||
static_assert(std::is_scoped_enum_v<volatile T>); | ||
static_assert(std::is_scoped_enum_v<const volatile T>); | ||
} | ||
|
||
template <class T> | ||
void test_negative() { | ||
static_assert(!std::is_scoped_enum<T>::value); | ||
static_assert(!std::is_scoped_enum<const T>::value); | ||
static_assert(!std::is_scoped_enum<volatile T>::value); | ||
static_assert(!std::is_scoped_enum<const volatile T>::value); | ||
|
||
static_assert(!std::is_scoped_enum_v<T>); | ||
static_assert(!std::is_scoped_enum_v<const T>); | ||
static_assert(!std::is_scoped_enum_v<volatile T>); | ||
static_assert(!std::is_scoped_enum_v<const volatile T>); | ||
} | ||
|
||
class Empty {}; | ||
|
||
class NotEmpty { | ||
virtual ~NotEmpty(); | ||
}; | ||
|
||
union Union {}; | ||
|
||
struct bit_zero { | ||
int : 0; | ||
}; | ||
|
||
class Abstract { | ||
virtual ~Abstract() = 0; | ||
}; | ||
|
||
enum Enum { zero, one }; | ||
enum class CEnum1 { zero, one }; | ||
enum class CEnum2; | ||
enum class CEnum3 : short; | ||
struct incomplete_type; | ||
|
||
using FunctionPtr = void (*)(); | ||
using FunctionType = void(); | ||
|
||
struct TestMembers { | ||
static int static_method(int) { return 0; } | ||
int method() { return 0; } | ||
|
||
enum E1 { m_zero, m_one }; | ||
enum class CE1; | ||
}; | ||
|
||
void func1(); | ||
int func2(int); | ||
|
||
int main(int, char**) { | ||
test_positive<CEnum1>(); | ||
test_positive<CEnum2>(); | ||
test_positive<CEnum3>(); | ||
test_positive<TestMembers::CE1>(); | ||
|
||
test_negative<Enum>(); | ||
test_negative<TestMembers::E1>(); | ||
|
||
test_negative<std::nullptr_t>(); | ||
test_negative<void>(); | ||
test_negative<int>(); | ||
test_negative<int&>(); | ||
test_negative<int&&>(); | ||
test_negative<int*>(); | ||
test_negative<double>(); | ||
test_negative<const int*>(); | ||
test_negative<char[3]>(); | ||
test_negative<char[]>(); | ||
test_negative<Union>(); | ||
test_negative<Empty>(); | ||
test_negative<bit_zero>(); | ||
test_negative<NotEmpty>(); | ||
test_negative<Abstract>(); | ||
test_negative<FunctionPtr>(); | ||
test_negative<FunctionType>(); | ||
test_negative<incomplete_type>(); | ||
test_negative<int TestMembers::*>(); | ||
test_negative<void (TestMembers::*)()>(); | ||
|
||
test_negative<decltype(func1)>(); | ||
test_negative<decltype(&func1)>(); | ||
test_negative<decltype(func2)>(); | ||
test_negative<decltype(&func2)>(); | ||
test_negative<decltype(TestMembers::static_method)>(); | ||
test_negative<decltype(&TestMembers::static_method)>(); | ||
test_negative<decltype(&TestMembers::method)>(); | ||
|
||
return 0; | ||
} |
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