Skip to content

Commit 53a12dc

Browse files
committed
Compute type of logical negation operators
Signed-off-by: Roberto Raggi <[email protected]>
1 parent e51b617 commit 53a12dc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/parser/cxx/parser.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,6 +2963,13 @@ auto Parser::parse_unop_expression(ExpressionAST*& yyast,
29632963
break;
29642964
}
29652965

2966+
case TokenKind::T_EXCLAIM: {
2967+
(void)implicit_conversion(ast->expression, control_->getBoolType());
2968+
ast->type = control_->getBoolType();
2969+
ast->valueCategory = ValueCategory::kPrValue;
2970+
break;
2971+
}
2972+
29662973
default:
29672974
break;
29682975
} // switch
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %cxx -verify -fcheck %s
2+
3+
auto main() -> int {
4+
static_assert(__is_same(decltype(!true), bool));
5+
static_assert(__is_same(decltype(!!true), bool));
6+
7+
static_assert(__is_same(decltype(!1), bool));
8+
static_assert(__is_same(decltype(!1.0), bool));
9+
10+
const void* p = nullptr;
11+
static_assert(__is_same(decltype(!p), bool));
12+
13+
static_assert(__is_same(decltype(!main), bool));
14+
15+
const int a[2] = {1, 2};
16+
static_assert(__is_same(decltype(!a), bool));
17+
18+
int x{}, &y = x;
19+
20+
static_assert(__is_same(decltype(!x), bool));
21+
static_assert(__is_same(decltype(!y), bool));
22+
23+
return 0;
24+
}

0 commit comments

Comments
 (0)