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
4 changes: 4 additions & 0 deletions src/parser/cxx/literals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,10 @@ auto FloatLiteral::Components::from(std::string_view text,
const auto firstChar = literalText.data();
components.value = strtod(firstChar, nullptr);

components.isFloat = components.suffix == FloatingPointSuffix::kF;
components.isLongDouble = components.suffix == FloatingPointSuffix::kL;
components.isDouble = !components.isFloat && !components.isLongDouble;

return components;
}

Expand Down
16 changes: 16 additions & 0 deletions src/parser/cxx/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2930,6 +2930,22 @@ auto Parser::parse_unop_expression(ExpressionAST*& yyast,
break;
}

case cxx::TokenKind::T_PLUS: {
ExpressionAST* expr = ast->expression;
ensure_prvalue(expr);
auto ty = control_->remove_cvref(expr->type);
if (control_->is_arithmetic_or_unscoped_enum(ty) ||
control_->is_pointer(ty)) {
if (control_->is_integral_or_unscoped_enum(ty)) {
(void)integral_promotion(expr);
}
ast->expression = expr;
ast->type = expr->type;
ast->valueCategory = ValueCategory::kPrValue;
}
break;
}

default:
break;
} // switch
Expand Down
25 changes: 25 additions & 0 deletions tests/unit_tests/sema/unary_plus_01.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %cxx -verify -fcheck %s

auto main() -> int {
static_assert(__is_same(decltype(+'a'), int));
static_assert(__is_same(decltype(+1), int));
static_assert(__is_same(decltype(+1.0f), float));
static_assert(__is_same(decltype(+1.0), double));

short x{};
static_assert(__is_same(decltype(+x), int));

short& y = x;
static_assert(__is_same(decltype(+y), int));

int a[2];
static_assert(__is_same(decltype(+a), int*));

void (*f)() = nullptr;
static_assert(__is_same(decltype(+f), void (*)()));

const void* p = nullptr;
static_assert(__is_same(decltype(+p), const void*));

return 0;
}