Skip to content

Commit

Permalink
fix: Implemented __is_lvalue_reference and __is_rvalue_reference type…
Browse files Browse the repository at this point in the history
… traits
  • Loading branch information
robertoraggi committed Oct 29, 2023
1 parent 7f94af4 commit 845f336
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/parser/cxx/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,34 @@ struct Parser::TypeTraits {
constexpr auto operator()(auto) const -> bool { return false; }
} is_volatile;

struct {
constexpr auto operator()(const LvalueReferenceType*) const -> bool {
return true;
}

constexpr auto operator()(auto) const -> bool { return false; }
} is_lvalue_reference;

struct {
constexpr auto operator()(const RvalueReferenceType*) const -> bool {
return true;
}

constexpr auto operator()(auto) const -> bool { return false; }
} is_rvalue_reference;

struct {
constexpr auto operator()(const LvalueReferenceType*) const -> bool {
return true;
}

constexpr auto operator()(const RvalueReferenceType*) const -> bool {
return true;
}

constexpr auto operator()(auto) const -> bool { return false; }
} is_reference;

struct {
constexpr auto operator()(const LvalueReferenceType* type) const
-> const Type* {
Expand Down Expand Up @@ -2489,6 +2517,23 @@ auto Parser::parse_builtin_call_expression(ExpressionAST*& yyast) -> bool {
break;
}

case TokenKind::T___IS_LVALUE_REFERENCE: {
ast->constValue =
visit(TypeTraits{*this}.is_lvalue_reference, firstType);
break;
}

case TokenKind::T___IS_RVALUE_REFERENCE: {
ast->constValue =
visit(TypeTraits{*this}.is_rvalue_reference, firstType);
break;
}

case TokenKind::T___IS_REFERENCE: {
ast->constValue = visit(TypeTraits{*this}.is_reference, firstType);
break;
}

default:;
} // switch
}
Expand Down
32 changes: 32 additions & 0 deletions tests/unit_tests/sema/type_traits_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,35 @@ static_assert(__is_volatile(volatile void*));

// expected-error@1 {{static assert failed}}
static_assert(__is_volatile(int));

//
// is_lvalue_reference trait
//

static_assert(__is_lvalue_reference(int&));
static_assert(__is_lvalue_reference(const int&));

// expected-error@1 {{static assert failed}}
static_assert(__is_lvalue_reference(int&&));

//
// is_rvalue_reference trait
//

static_assert(__is_rvalue_reference(int&&));
static_assert(__is_rvalue_reference(const int&&));

// expected-error@1 {{static assert failed}}
static_assert(__is_rvalue_reference(int&));

//
// is_reference trait
//

static_assert(__is_reference(int&));
static_assert(__is_reference(const int&));
static_assert(__is_reference(int&&));
static_assert(__is_reference(const int&&));

// expected-error@1 {{static assert failed}}
static_assert(__is_reference(int));

0 comments on commit 845f336

Please sign in to comment.