Skip to content

Commit

Permalink
Fix Bugzilla 24706 - Missing errors for first operand of comma expres…
Browse files Browse the repository at this point in the history
…sion (#16787)
  • Loading branch information
ntrel authored Aug 17, 2024
1 parent 1d2e15e commit c5496ff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
13 changes: 8 additions & 5 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -9824,13 +9824,16 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
if (sc.inCfile)
return;

if (e.type is Type.tvoid)
if (!e.isGenerated)
{
checkMustUse(e.e1, sc);
discardValue(e.e1);
if (e.allowCommaExp)
{
checkMustUse(e.e1, sc);
discardValue(e.e1);
}
else
error(e.loc, "using the result of a comma expression is not allowed");
}
else if (!e.allowCommaExp && !e.isGenerated)
error(e.loc, "using the result of a comma expression is not allowed");
}

override void visit(IntervalExp e)
Expand Down
17 changes: 10 additions & 7 deletions compiler/test/fail_compilation/misc1.d
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
TEST_OUTPUT:
---
fail_compilation/misc1.d(108): Error: `5` has no effect
fail_compilation/misc1.d(109): Error: `1 + 2` has no effect
fail_compilation/misc1.d(115): Deprecation: `1 * 1` has no effect
fail_compilation/misc1.d(116): Deprecation: `__lambda3` has no effect
fail_compilation/misc1.d(122): Deprecation: `false` has no effect
fail_compilation/misc1.d(125): Deprecation: `*sp++` has no effect
fail_compilation/misc1.d(126): Deprecation: `j` has no effect
fail_compilation/misc1.d(109): Error: `5` has no effect
fail_compilation/misc1.d(110): Error: `1 + 2` has no effect
fail_compilation/misc1.d(111): Error: `x` has no effect
fail_compilation/misc1.d(117): Deprecation: `1 * 1` has no effect
fail_compilation/misc1.d(118): Deprecation: `__lambda3` has no effect
fail_compilation/misc1.d(124): Deprecation: `false` has no effect
fail_compilation/misc1.d(127): Deprecation: `*sp++` has no effect
fail_compilation/misc1.d(128): Deprecation: `j` has no effect
---
*/

Expand All @@ -20,8 +21,10 @@ void hasSideEffect12490(){}

void issue12490()
{
int x;
5, hasSideEffect12490();
1 + 2, hasSideEffect12490();
x, x++;
}

void issue23480()
Expand Down
7 changes: 5 additions & 2 deletions compiler/test/fail_compilation/must_use.d
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
/+
TEST_OUTPUT:
---
fail_compilation/must_use.d(15): Error: ignored value of `@mustuse` type `must_use.S`; prepend a `cast(void)` if intentional
fail_compilation/must_use.d(17): Error: ignored value of `@mustuse` type `must_use.S`; prepend a `cast(void)` if intentional
fail_compilation/must_use.d(18): Error: ignored value of `@mustuse` type `must_use.S`; prepend a `cast(void)` if intentional
---
+/
import core.attribute;

@mustuse struct S {}

S fun() { return S(); }
S fun();

void test()
{
int x;
fun();
fun(), x++;
}

0 comments on commit c5496ff

Please sign in to comment.