Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/parser/cxx/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2919,6 +2919,21 @@ auto Parser::parse_unop_expression(ExpressionAST*& yyast,
ast->op = unit->tokenKind(opLoc);
ast->expression = expression;

switch (ast->op) {
case TokenKind::T_STAR: {
auto pointerType = type_cast<PointerType>(expression->type);
if (pointerType) {
ensure_prvalue(ast->expression);
ast->type = pointerType->elementType();
ast->valueCategory = ValueCategory::kLValue;
}
break;
}

default:
break;
} // switch

return true;
}

Expand Down Expand Up @@ -6365,6 +6380,23 @@ auto Parser::qualification_conversion(ExpressionAST*& expr,
return false;
}

void Parser::ensure_prvalue(ExpressionAST*& expr) {
if (lvalue_to_rvalue_conversion(expr)) {
expr->valueCategory = ValueCategory::kPrValue;
return;
}

if (array_to_pointer_conversion(expr)) {
expr->valueCategory = ValueCategory::kPrValue;
return;
}

if (function_to_pointer_conversion(expr)) {
expr->valueCategory = ValueCategory::kPrValue;
return;
}
}

auto Parser::implicit_conversion(ExpressionAST*& expr,
const Type* destinationType) -> bool {
if (!expr || !expr->type) return false;
Expand Down
2 changes: 2 additions & 0 deletions src/parser/cxx/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,8 @@ class Parser final {
const Type* destinationType)
-> bool;

void ensure_prvalue(ExpressionAST*& expr);

[[nodiscard]] auto implicit_conversion(ExpressionAST*& expr,
const Type* destinationType) -> bool;

Expand Down
8 changes: 5 additions & 3 deletions tests/unit_tests/ast/asm_declaration_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ end:;
// CHECK-NEXT: constraint-literal: "+rm"
// CHECK-NEXT: expression: unary-expression
// CHECK-NEXT: op: *
// CHECK-NEXT: expression: id-expression
// CHECK-NEXT: unqualified-id: name-id
// CHECK-NEXT: identifier: p
// CHECK-NEXT: expression: implicit-cast-expression
// CHECK-NEXT: cast-kind: lvalue-to-rvalue-conversion
// CHECK-NEXT: expression: id-expression
// CHECK-NEXT: unqualified-id: name-id
// CHECK-NEXT: identifier: p
// CHECK-NEXT: function-definition
// CHECK-NEXT: decl-specifier-list
// CHECK-NEXT: void-type-specifier
Expand Down
40 changes: 34 additions & 6 deletions tests/unit_tests/sema/class_01.cc
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
// RUN: %cxx -verify -fcheck %s

struct X {
void f() { static_assert(__is_same(decltype(this), X*)); }
void f() {
static_assert(__is_same(decltype(this), X*));
static_assert(__is_same(decltype(*this), X&));
}

void f() const { static_assert(__is_same(decltype(this), const X*)); }
void f() const {
static_assert(__is_same(decltype(this), const X*));
static_assert(__is_same(decltype(*this), const X&));
}

void f() volatile { static_assert(__is_same(decltype(this), volatile X*)); }
void f() volatile {
static_assert(__is_same(decltype(this), volatile X*));
static_assert(__is_same(decltype(*this), volatile X&));
}

void f() const volatile {
static_assert(__is_same(decltype(this), const volatile X*));
static_assert(__is_same(decltype(*this), const volatile X&));
}

void g();
Expand All @@ -17,12 +27,30 @@ struct X {
void g() const volatile;
};

void X::g() { static_assert(__is_same(decltype(this), X*)); }
void X::g() {
static_assert(__is_same(decltype(this), X*));
static_assert(__is_same(decltype(*this), X&));

X* self = this;
static_assert(__is_same(decltype(self), X*));
static_assert(__is_same(decltype(*self), X&));

void X::g() const { static_assert(__is_same(decltype(this), const X*)); }
X*& x = self;
static_assert(__is_same(decltype(x), X*&));
static_assert(__is_same(decltype(*x), X&));
}

void X::g() const {
static_assert(__is_same(decltype(this), const X*));
static_assert(__is_same(decltype(*this), const X&));
}

void X::g() volatile { static_assert(__is_same(decltype(this), volatile X*)); }
void X::g() volatile {
static_assert(__is_same(decltype(this), volatile X*));
static_assert(__is_same(decltype(*this), volatile X&));
}

void X::g() const volatile {
static_assert(__is_same(decltype(this), const volatile X*));
static_assert(__is_same(decltype(*this), const volatile X&));
}