Skip to content

Commit 462da06

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

20 files changed

Lines changed: 69 additions & 44 deletions
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 can't 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 can't be used");
62766276
Expression e0;
62776277
exp.e2 = Expression.extractLast(exp.e2, &e0);
62786278
Expression e = Expression.combine(e0, exp);

test/compilable/interpret3.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// PERMUTE_ARGS: -inline
1+
// PERMUTE_ARGS: -inline
22

33
template compiles(int T)
44
{
@@ -6288,7 +6288,7 @@ static assert(ctfe7784());
62886288
7781
62896289
**************************************************/
62906290

6291-
static assert(({ return; }(), true));
6291+
static assert(({ return true; }()));
62926292

62936293
/**************************************************
62946294
7785

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 can't be used
5+
fail_compilation/commaexp.d(36): Error: The result of a comma expression can't be used
6+
fail_compilation/commaexp.d(37): Error: The result of a comma expression can't be used
7+
fail_compilation/commaexp.d(38): Error: The result of a comma expression can't be used
8+
fail_compilation/commaexp.d(39): Error: The result of a comma expression can't be used
9+
fail_compilation/commaexp.d(41): Error: The result of a comma expression can't be used
10+
fail_compilation/commaexp.d(42): Error: The result of a comma expression can't 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 can't 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/fail13902.d

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ struct S1 { int v; }
44
struct S2 { int* p; }
55
class C { int v; }
66

7+
#line 6
78
/*
89
TEST_OUTPUT:
910
---
11+
fail_compilation/fail13902.d(45): Error: The result of a comma expression can't be used
1012
fail_compilation/fail13902.d(32): Error: returning `& x` escapes a reference to local variable `x`
1113
fail_compilation/fail13902.d(33): Error: returning `&s1.v` escapes a reference to local variable `s1`
1214
fail_compilation/fail13902.d(38): Error: returning `& sa1` escapes a reference to local variable `sa1`
@@ -47,9 +49,11 @@ int* testEscape1()
4749
return null; // ok
4850
}
4951

52+
#line 49
5053
/*
5154
TEST_OUTPUT:
5255
---
56+
fail_compilation/fail13902.d(88): Error: The result of a comma expression can't be used
5357
fail_compilation/fail13902.d(75): Error: returning `& x` escapes a reference to parameter `x`, perhaps annotate with `return`
5458
fail_compilation/fail13902.d(76): Error: returning `&s1.v` escapes a reference to parameter `s1`, perhaps annotate with `return`
5559
fail_compilation/fail13902.d(81): Error: returning `& sa1` escapes a reference to parameter `sa1`, perhaps annotate with `return`
@@ -90,9 +94,11 @@ int* testEscape2(
9094
return null; // ok
9195
}
9296

97+
#line 92
9398
/*
9499
TEST_OUTPUT:
95100
---
101+
fail_compilation/fail13902.d(123): Error: The result of a comma expression can't be used
96102
---
97103
*/
98104
int* testEscape3(

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 can't 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/aliasthis.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,15 +551,15 @@ void test2781()
551551
}
552552

553553
eval = 0;
554-
foreach (i, e; tup(tup((eval++, 10), 3.14), tup("str", [1,2])))
554+
foreach (i, e; tup(tup((){eval++; return 10;}(), 3.14), tup("str", [1,2])))
555555
{
556556
static if (i == 0) assert(e == tup(10, 3.14));
557557
static if (i == 1) assert(e == tup("str", [1,2]));
558558
}
559559
assert(eval == 1);
560560

561561
eval = 0;
562-
foreach (i, e; tup((eval++,10), tup(3.14, tup("str", tup([1,2])))))
562+
foreach (i, e; tup((){eval++; return 10;}(), tup(3.14, tup("str", tup([1,2])))))
563563
{
564564
static if (i == 0) assert(e == 10);
565565
static if (i == 1) assert(e == tup(3.14, tup("str", tup([1,2]))));
@@ -836,7 +836,7 @@ void test6369c()
836836
void test6369d()
837837
{
838838
int eval = 0;
839-
Seq!(int, string) t = tup((++eval, 10), "str");
839+
Seq!(int, string) t = tup((){++eval; return 10;}(), "str");
840840
assert(eval == 1);
841841
assert(t[0] == 10);
842842
assert(t[1] == "str");

test/runnable/constfold.d

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,8 @@ void test13977()
559559
Object.init && check();
560560
assert(x == 0);
561561

562-
(check(2), false) && check();
562+
check(2);
563+
false && check();
563564
assert(x == 2); x = 0;
564565
}
565566

@@ -588,7 +589,8 @@ void test13978()
588589
Object.init || check();
589590
assert(x == 1); x = 0;
590591

591-
(check(2), true) || check();
592+
check(2);
593+
true || check();
592594
assert(x == 2); x = 0;
593595
}
594596

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

0 commit comments

Comments
 (0)