Skip to content

Commit

Permalink
Parser: allow ~ operator for complex conjugation
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas authored and Vexu committed Feb 7, 2024
1 parent b0016f4 commit b504b35
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/aro/Diagnostics/messages.def
Original file line number Diff line number Diff line change
Expand Up @@ -2456,3 +2456,9 @@ too_big_shift_count
.opt = W("shift-count-overflow")
.kind = .warning
.all = true

complex_conj
.msg = "ISO C does not support '~' for complex conjugation of '{s}'"
.opt = W("pedantic")
.extra = .str
.kind = .off
2 changes: 2 additions & 0 deletions src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6977,6 +6977,8 @@ fn unExpr(p: *Parser) Error!Result {
if (operand.val.is(.int, p.comp)) {
operand.val = try operand.val.bitNot(operand.ty, p.comp);
}
} else if (operand.ty.isComplex()) {
try p.errStr(.complex_conj, tok, try p.typeStr(operand.ty));
} else {
try p.errStr(.invalid_argument_un, tok, try p.typeStr(operand.ty));
operand.val = .{};
Expand Down
2 changes: 2 additions & 0 deletions test/cases/complex numbers clang.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void foo(int x, float y) {
z = __builtin_complex(2.0, 3);
z = __builtin_complex(2.0, 3.0f);
z = __builtin_complex(2.0, 3.0);
z = ~z;
}

#define EXPECTED_ERRORS "complex numbers clang.c:5:20: error: static_assert expression is not an integral constant expression" \
Expand All @@ -21,4 +22,5 @@ void foo(int x, float y) {
"complex numbers clang.c:10:6: warning: ISO C does not support '++'/'--' on complex type '_Complex double' [-Wpedantic]" \
"complex numbers clang.c:12:32: error: argument type 'int' is not a real floating point type" \
"complex numbers clang.c:13:32: error: arguments are of different types ('double' vs 'float')" \
"complex numbers clang.c:15:9: warning: ISO C does not support '~' for complex conjugation of '_Complex double' [-Wpedantic]" \

0 comments on commit b504b35

Please sign in to comment.