Skip to content

Commit d919941

Browse files
committed
Compute types of unary plus operators
Signed-off-by: Roberto Raggi <[email protected]>
1 parent 755ba01 commit d919941

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/parser/cxx/literals.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,10 @@ auto FloatLiteral::Components::from(std::string_view text,
729729
const auto firstChar = literalText.data();
730730
components.value = strtod(firstChar, nullptr);
731731

732+
components.isFloat = components.suffix == FloatingPointSuffix::kF;
733+
components.isLongDouble = components.suffix == FloatingPointSuffix::kL;
734+
components.isDouble = !components.isFloat && !components.isLongDouble;
735+
732736
return components;
733737
}
734738

src/parser/cxx/parser.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,22 @@ auto Parser::parse_unop_expression(ExpressionAST*& yyast,
29302930
break;
29312931
}
29322932

2933+
case cxx::TokenKind::T_PLUS: {
2934+
ExpressionAST* expr = ast->expression;
2935+
ensure_prvalue(expr);
2936+
auto ty = control_->remove_cvref(expr->type);
2937+
if (control_->is_arithmetic_or_unscoped_enum(ty) ||
2938+
control_->is_pointer(ty)) {
2939+
if (control_->is_integral_or_unscoped_enum(ty)) {
2940+
(void)integral_promotion(expr);
2941+
}
2942+
ast->expression = expr;
2943+
ast->type = expr->type;
2944+
ast->valueCategory = ValueCategory::kPrValue;
2945+
}
2946+
break;
2947+
}
2948+
29332949
default:
29342950
break;
29352951
} // switch
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %cxx -verify -fcheck %s
2+
3+
auto main() -> int {
4+
static_assert(__is_same(decltype(+'a'), int));
5+
static_assert(__is_same(decltype(+1), int));
6+
static_assert(__is_same(decltype(+1.0f), float));
7+
static_assert(__is_same(decltype(+1.0), double));
8+
9+
short x{};
10+
static_assert(__is_same(decltype(+x), int));
11+
12+
short& y = x;
13+
static_assert(__is_same(decltype(+y), int));
14+
15+
int a[2];
16+
static_assert(__is_same(decltype(+a), int*));
17+
18+
void (*f)() = nullptr;
19+
static_assert(__is_same(decltype(+f), void (*)()));
20+
21+
const void* p = nullptr;
22+
static_assert(__is_same(decltype(+p), const void*));
23+
24+
return 0;
25+
}

0 commit comments

Comments
 (0)