diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index cf3670b6..908715a3 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -187,6 +187,65 @@ struct Parser::TypeTraits { constexpr auto operator()(auto) const -> bool { return false; } } is_void; + struct { + constexpr auto operator()(const BoolType*) const -> bool { return true; } + + constexpr auto operator()(const SignedCharType*) const -> bool { + return true; + } + + constexpr auto operator()(const ShortIntType*) const -> bool { + return true; + } + + constexpr auto operator()(const IntType*) const -> bool { return true; } + + constexpr auto operator()(const LongIntType*) const -> bool { return true; } + + constexpr auto operator()(const LongLongIntType*) const -> bool { + return true; + } + + constexpr auto operator()(const UnsignedCharType*) const -> bool { + return true; + } + + constexpr auto operator()(const UnsignedShortIntType*) const -> bool { + return true; + } + + constexpr auto operator()(const UnsignedIntType*) const -> bool { + return true; + } + + constexpr auto operator()(const UnsignedLongIntType*) const -> bool { + return true; + } + + constexpr auto operator()(const UnsignedLongLongIntType*) const -> bool { + return true; + } + + constexpr auto operator()(const CharType*) const -> bool { return true; } + + constexpr auto operator()(const Char8Type*) const -> bool { return true; } + + constexpr auto operator()(const Char16Type*) const -> bool { return true; } + + constexpr auto operator()(const Char32Type*) const -> bool { return true; } + + constexpr auto operator()(const WideCharType*) const -> bool { + return true; + } + + constexpr auto operator()(const QualType* type) const -> bool { + return visit(*this, type->elementType()); + } + + constexpr auto operator()(auto) const -> bool { return false; } + + } is_integral; + struct { constexpr auto operator()(const QualType* type) const -> bool { return type->isConst(); @@ -2507,6 +2566,11 @@ auto Parser::parse_builtin_call_expression(ExpressionAST*& yyast) -> bool { break; } + case TokenKind::T___IS_INTEGRAL: { + ast->constValue = visit(TypeTraits{*this}.is_integral, firstType); + break; + } + case TokenKind::T___IS_CONST: { ast->constValue = visit(TypeTraits{*this}.is_const, firstType); break; diff --git a/tests/unit_tests/sema/type_traits_01.cc b/tests/unit_tests/sema/type_traits_01.cc index 490d60d8..9b33dbd3 100644 --- a/tests/unit_tests/sema/type_traits_01.cc +++ b/tests/unit_tests/sema/type_traits_01.cc @@ -15,6 +15,42 @@ static_assert(__is_void(int)); // expected-error@1 {{static assert failed}} static_assert(__is_void(void*)); +// +// is_integral trait +// + +static_assert(__is_integral(bool)); +static_assert(__is_integral(char)); +static_assert(__is_integral(signed char)); +static_assert(__is_integral(unsigned char)); +static_assert(__is_integral(char8_t)); +static_assert(__is_integral(char16_t)); +static_assert(__is_integral(char32_t)); +static_assert(__is_integral(wchar_t)); +static_assert(__is_integral(short)); +static_assert(__is_integral(unsigned short)); +static_assert(__is_integral(int)); +static_assert(__is_integral(unsigned int)); +static_assert(__is_integral(long)); +static_assert(__is_integral(unsigned long)); +static_assert(__is_integral(long long)); +static_assert(__is_integral(unsigned long long)); + +// expected-error@1 {{static assert failed}} +static_assert(__is_integral(float)); + +// expected-error@1 {{static assert failed}} +static_assert(__is_integral(double)); + +// expected-error@1 {{static assert failed}} +static_assert(__is_integral(long double)); + +// expected-error@1 {{static assert failed}} +static_assert(__is_integral(void)); + +// expected-error@1 {{static assert failed}} +static_assert(__is_integral(void*)); + // // is_const trait //