forked from wangliu-iscas/gcc-patch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c++: Implement __is_function built-in trait
This patch implements built-in trait for std::is_function. gcc/cp/ChangeLog: * cp-trait.def: Define __is_function. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_FUNCTION. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_function. * g++.dg/ext/is_function.C: New test. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
- Loading branch information
1 parent
81ab984
commit 902e46e
Showing
5 changed files
with
69 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// { dg-do compile { target c++11 } } | ||
|
||
#include <testsuite_tr1.h> | ||
|
||
using namespace __gnu_test; | ||
|
||
#define SA(X) static_assert((X),#X) | ||
#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ | ||
SA(TRAIT(TYPE) == EXPECT); \ | ||
SA(TRAIT(const TYPE) == EXPECT); \ | ||
SA(TRAIT(volatile TYPE) == EXPECT); \ | ||
SA(TRAIT(const volatile TYPE) == EXPECT) | ||
|
||
struct A | ||
{ void fn(); }; | ||
|
||
template<typename> | ||
struct AHolder { }; | ||
|
||
template<class T, class U> | ||
struct AHolder<U T::*> | ||
{ using type = U; }; | ||
|
||
// Positive tests. | ||
SA(__is_function(int (int))); | ||
SA(__is_function(ClassType (ClassType))); | ||
SA(__is_function(float (int, float, int[], int&))); | ||
SA(__is_function(int (int, ...))); | ||
SA(__is_function(bool (ClassType) const)); | ||
SA(__is_function(AHolder<decltype(&A::fn)>::type)); | ||
|
||
void fn(); | ||
SA(__is_function(decltype(fn))); | ||
|
||
// Negative tests. | ||
SA_TEST_CATEGORY(__is_function, int, false); | ||
SA_TEST_CATEGORY(__is_function, int*, false); | ||
SA_TEST_CATEGORY(__is_function, int&, false); | ||
SA_TEST_CATEGORY(__is_function, void, false); | ||
SA_TEST_CATEGORY(__is_function, void*, false); | ||
SA_TEST_CATEGORY(__is_function, void**, false); | ||
SA_TEST_CATEGORY(__is_function, std::nullptr_t, false); | ||
|
||
SA_TEST_CATEGORY(__is_function, AbstractClass, false); | ||
SA(!__is_function(int(&)(int))); | ||
SA(!__is_function(int(*)(int))); | ||
|
||
SA_TEST_CATEGORY(__is_function, A, false); | ||
SA_TEST_CATEGORY(__is_function, decltype(&A::fn), false); | ||
|
||
struct FnCallOverload | ||
{ void operator()(); }; | ||
SA_TEST_CATEGORY(__is_function, FnCallOverload, false); | ||
|
||
// Sanity check. | ||
SA_TEST_CATEGORY(__is_function, ClassType, false); | ||
SA_TEST_CATEGORY(__is_function, IncompleteClass, false); | ||
SA_TEST_CATEGORY(__is_function, IncompleteUnion, false); |