Skip to content

Commit ad42672

Browse files
committed
End the deprecation period of using the result of a comma expression.
1 parent c048abb commit ad42672

11 files changed

Lines changed: 41 additions & 27 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The deprecation period of using the result of comma expression has ended
2+
3+
Comma expressions have proven to be a frequent source of confusion, and bugs.
4+
Using their result will now trigger an error message.

src/dmd/expressionsem.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5844,7 +5844,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
58445844

58455845
e.type = e.e2.type;
58465846
if (e.type !is Type.tvoid && !e.allowCommaExp && !e.isGenerated)
5847-
e.deprecation("Using the result of a comma expression is deprecated");
5847+
e.error("The result of a comma expression cant be used");
58485848
result = e;
58495849
}
58505850

@@ -6272,7 +6272,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
62726272
/* Rewrite to get rid of the comma from rvalue
62736273
*/
62746274
if (!(cast(CommaExp)exp.e2).isGenerated)
6275-
exp.deprecation("Using the result of a comma expression is deprecated");
6275+
exp.error("The result of a comma expression cant be used");
62766276
Expression e0;
62776277
exp.e2 = Expression.extractLast(exp.e2, &e0);
62786278
Expression e = Expression.combine(e0, exp);

test/fail_compilation/commaexp.d

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/* REQUIRED_ARGS: -o- -de
1+
/* REQUIRED_ARGS: -o-
22
TEST_OUTPUT:
33
---
4-
fail_compilation/commaexp.d(24): Deprecation: Using the result of a comma expression is deprecated
5-
fail_compilation/commaexp.d(36): Deprecation: Using the result of a comma expression is deprecated
6-
fail_compilation/commaexp.d(37): Deprecation: Using the result of a comma expression is deprecated
7-
fail_compilation/commaexp.d(38): Deprecation: Using the result of a comma expression is deprecated
8-
fail_compilation/commaexp.d(39): Deprecation: Using the result of a comma expression is deprecated
9-
fail_compilation/commaexp.d(41): Deprecation: Using the result of a comma expression is deprecated
10-
fail_compilation/commaexp.d(42): Deprecation: Using the result of a comma expression is deprecated
4+
fail_compilation/commaexp.d(24): Error: The result of a comma expression cant be used
5+
fail_compilation/commaexp.d(36): Error: The result of a comma expression cant be used
6+
fail_compilation/commaexp.d(37): Error: The result of a comma expression cant be used
7+
fail_compilation/commaexp.d(38): Error: The result of a comma expression cant be used
8+
fail_compilation/commaexp.d(39): Error: The result of a comma expression cant be used
9+
fail_compilation/commaexp.d(41): Error: The result of a comma expression cant be used
10+
fail_compilation/commaexp.d(42): Error: The result of a comma expression cant be used
1111
---
1212
*/
1313

test/fail_compilation/diag10862.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fail_compilation/diag10862.d(77): Error: assignment cannot be used as a conditio
5757
fail_compilation/diag10862.d-mixin-80(80): Error: assignment cannot be used as a condition, perhaps `==` was meant?
5858
fail_compilation/diag10862.d-mixin-81(81): Error: assignment cannot be used as a condition, perhaps `==` was meant?
5959
fail_compilation/diag10862.d-mixin-82(82): Error: assignment cannot be used as a condition, perhaps `==` was meant?
60-
fail_compilation/diag10862.d-mixin-83(83): Deprecation: Using the result of a comma expression is deprecated
60+
fail_compilation/diag10862.d-mixin-83(83): Error: The result of a comma expression cant be used
6161
fail_compilation/diag10862.d-mixin-83(83): Error: assignment cannot be used as a condition, perhaps `==` was meant?
6262
fail_compilation/diag10862.d-mixin-86(86): Error: `a + b` is not an lvalue
6363
fail_compilation/diag10862.d-mixin-87(87): Error: undefined identifier `c`

test/fail_compilation/ice10949.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
TEST_OUTPUT:
33
---
4-
fail_compilation/ice10949.d(12): Deprecation: Using the result of a comma expression is deprecated
4+
fail_compilation/ice10949.d(12): Error: the result of a comma expression cant be used
55
fail_compilation/ice10949.d(12): Error: array index 3 is out of bounds `[5, 5][0 .. 2]`
66
fail_compilation/ice10949.d(12): Error: array index 17 is out of bounds `[2, 3][0 .. 2]`
77
fail_compilation/ice10949.d(12): while evaluating: `static assert((((([5, 5][3] + global - global) * global / global % global >> global & global | global) ^ global) == 9 , [2, 3][17]) || [3, 3, 3][9] is 4 && [[1, 2, 3]][4].length)`

test/runnable/ctorpowtests.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ static assert(bazra(14)==64);
136136

137137
void moreCommaTests()
138138
{
139-
auto k = (containsAsm(), containsAsm());
139+
(containsAsm(), containsAsm());
140+
auto k = containsAsm();
140141
for (int i=0; i< k^^2; i+=StructWithCtor(1).n) {}
141142
}
142143

test/runnable/lazy.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void test1()
7474
);
7575

7676
whiler( x < 100,
77-
(printf("%d\n", x), x *= 2)
77+
(){ printf("%d\n", x); x *= 2; }()
7878
);
7979
}
8080

test/runnable/sdtor.d

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,9 @@ void test34()
879879
X34[2] xs;
880880
// xs[0][0] = X34();
881881
printf("foreach\n");
882-
for (int j = 0; j < xs.length; j++) { auto x = (j++,j--,xs[j]);
882+
for (int j = 0; j < xs.length; j++) {
883+
j++,j--;
884+
auto x = xs[j];
883885
//foreach(x; xs) {
884886
//printf("foreach x.i = %d\n", x[0].i);
885887
//assert(x[0].i == 1);
@@ -1395,22 +1397,22 @@ void test54()
13951397
assert(S54.t == "c");
13961398

13971399
{ S54.t = null;
1398-
int b = 1 && (bar54(S54(1)), 1);
1400+
int b = 1 && (){ bar54(S54(1)); return 1;}();
13991401
}
14001402
assert(S54.t == "ac");
14011403

14021404
{ S54.t = null;
1403-
int b = 0 && (bar54(S54(1)), 1);
1405+
int b = 0 && (){ bar54(S54(1)); return 1;}();
14041406
}
14051407
assert(S54.t == "");
14061408

14071409
{ S54.t = null;
1408-
int b = 0 || (bar54(S54(1)), 1);
1410+
int b = 0 || (){ bar54(S54(1)); return 1;}();
14091411
}
14101412
assert(S54.t == "ac");
14111413

14121414
{ S54.t = null;
1413-
int b = 1 || (bar54(S54(1)), 1);
1415+
int b = 1 || (){ bar54(S54(1)); return 1;}();
14141416
}
14151417
assert(S54.t == "");
14161418

@@ -1529,7 +1531,8 @@ void test57()
15291531

15301532
printf("----\n"); //+
15311533
dtor_cnt = 0;
1532-
if (auto s = (S57(1), S57(2), S57(10)))
1534+
S57(1), S57(2);
1535+
if (auto s = S57(10))
15331536
{
15341537
assert(dtor_cnt == 2);
15351538
printf("ifbody\n");
@@ -1562,7 +1565,8 @@ void test57()
15621565

15631566
printf("----\n"); //+
15641567
dtor_cnt = 0;
1565-
if (auto s = (f(1), f(2), f(10)))
1568+
f(1), f(2);
1569+
if (auto s = f(10))
15661570
{
15671571
assert(dtor_cnt == 2);
15681572
printf("ifbody\n");
@@ -1596,7 +1600,8 @@ void test57()
15961600

15971601
printf("----\n");
15981602
dtor_cnt = 0;
1599-
if ((S57(1), S57(2), S57(10)))
1603+
S57(1), S57(2);
1604+
if (S57(10))
16001605
{
16011606
assert(dtor_cnt == 3);
16021607
printf("ifbody\n");
@@ -1628,7 +1633,8 @@ void test57()
16281633

16291634
printf("----\n");
16301635
dtor_cnt = 0;
1631-
if ((f(1), f(2), f(10)))
1636+
f(1), f(2);
1637+
if (f(10))
16321638
{
16331639
assert(dtor_cnt == 3);
16341640
printf("ifbody\n");
@@ -4431,7 +4437,8 @@ struct S64
44314437

44324438
S64 foo64()
44334439
{
4434-
return S64((X64(), 1));
4440+
X64();
4441+
return S64(1);
44354442
}
44364443

44374444
void test64()

test/runnable/test16115.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ auto call()
2525
else // assert error
2626
{
2727
//return n = tagx, null;
28-
return n = Test.tag, null;
28+
return n = Test.tag;
2929
//return n = Test.tag;
3030
}
3131
}

test/runnable/test22.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ class B9
201201
{
202202
A9 test1 = new A9(1, 2, 3);
203203
A9 test2 = new A9(1, 2, 3, 4);
204-
int[3] arg; A9 test3 = new A9((arg[0]=1, arg[1]=2, arg[2]=3, arg));
204+
int[3] arg;
205+
arg[0]=1, arg[1]=2, arg[2]=3;
206+
A9 test3 = new A9(arg);
205207
}
206208
}
207209

0 commit comments

Comments
 (0)