Skip to content

Commit 8812065

Browse files
authored
fix dlang#20960 i = i && 1; fails at runtime (dlang#20961)
1 parent 4c4b9ae commit 8812065

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

compiler/src/dmd/cparse.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,8 +1445,10 @@ final class CParser(AST) : Parser!AST
14451445
auto e = cparseOrExp();
14461446
while (token.value == TOK.andAnd)
14471447
{
1448+
e = new AST.CastExp(loc, e, AST.Type.tbool);
14481449
nextToken();
14491450
auto e2 = cparseOrExp();
1451+
e2 = new AST.CastExp(loc, e2, AST.Type.tbool);
14501452
e = new AST.LogicalExp(loc, EXP.andAnd, e, e2);
14511453
}
14521454
return e;
@@ -1465,8 +1467,10 @@ final class CParser(AST) : Parser!AST
14651467
auto e = cparseAndAndExp();
14661468
while (token.value == TOK.orOr)
14671469
{
1470+
e = new AST.CastExp(loc, e, AST.Type.tbool);
14681471
nextToken();
14691472
auto e2 = cparseAndAndExp();
1473+
e2 = new AST.CastExp(loc, e2, AST.Type.tbool);
14701474
e = new AST.LogicalExp(loc, EXP.orOr, e, e2);
14711475
}
14721476
return e;

compiler/test/runnable/exe1.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ int testcppcomment()
2828

2929
void elemi()
3030
{
31-
#if 0 // TODO ImportC
3231
int i;
3332

3433
i = 47;
@@ -81,12 +80,10 @@ void elemi()
8180
assert(i == 1);
8281
i = ((i = 1),(!(i & 5))) && (i == 6);
8382
assert(i == 0);
84-
#endif
8583
}
8684

8785
void elems()
8886
{
89-
#if 0 // TODO ImportC
9087
short i;
9188

9289
i = 47;
@@ -139,13 +136,11 @@ void elems()
139136
assert(i == 1);
140137
i = ((i = 1),(!(i & 5))) && (i == 6);
141138
assert(i == 0);
142-
#endif
143139
}
144140

145141
void eleml()
146142
{ long l;
147143

148-
#if 0 // TODO ImportC
149144
l = 47;
150145
l = l && 0;
151146
assert(l == 0);
@@ -196,13 +191,11 @@ void eleml()
196191
assert(l == 1);
197192
l = ((l = 1),(!(l & 5))) && (l == 6);
198193
assert(l == 0);
199-
#endif
200194
}
201195

202196
void elemc()
203197
{ char c;
204198

205-
#if 0 // TODO ImportC
206199
c = 47;
207200
c = c && 0;
208201
assert(c == 0);
@@ -253,7 +246,6 @@ void elemc()
253246
assert(c == 1);
254247
c = ((c = 1),(!(c & 5))) && (c == 6);
255248
assert(c == 0);
256-
#endif
257249
}
258250

259251
void align() /* test alignment */

0 commit comments

Comments
 (0)