Skip to content

Commit 9a8073a

Browse files
committed
Compute type of bitwise NOT operators
Signed-off-by: Roberto Raggi <[email protected]>
1 parent 53a12dc commit 9a8073a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/parser/cxx/parser.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,6 +2970,19 @@ auto Parser::parse_unop_expression(ExpressionAST*& yyast,
29702970
break;
29712971
}
29722972

2973+
case TokenKind::T_TILDE: {
2974+
ExpressionAST* expr = ast->expression;
2975+
ensure_prvalue(expr);
2976+
auto ty = control_->remove_cvref(expr->type);
2977+
if (control_->is_integral_or_unscoped_enum(ty)) {
2978+
(void)integral_promotion(expr);
2979+
ast->expression = expr;
2980+
ast->type = expr->type;
2981+
ast->valueCategory = ValueCategory::kPrValue;
2982+
}
2983+
break;
2984+
}
2985+
29732986
default:
29742987
break;
29752988
} // switch
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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(~1l), long));
7+
static_assert(__is_same(decltype(~1ll), long long));
8+
static_assert(__is_same(decltype(~1ul), unsigned long));
9+
static_assert(__is_same(decltype(~1ull), unsigned long long));
10+
11+
short x{};
12+
static_assert(__is_same(decltype(~x), int));
13+
14+
short& y = x;
15+
static_assert(__is_same(decltype(~y), int));
16+
17+
return 0;
18+
}

0 commit comments

Comments
 (0)