Fix Bugzilla 24706 - Missing errors for first operand of comma expression (#16787)

This commit is contained in:
Nick Treleaven 2024-08-17 10:05:52 +01:00 committed by GitHub
parent 1d2e15ef18
commit c5496ff4e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 14 deletions

View file

@ -9824,14 +9824,17 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
if (sc.inCfile)
return;
if (e.type is Type.tvoid)
if (!e.isGenerated)
{
if (e.allowCommaExp)
{
checkMustUse(e.e1, sc);
discardValue(e.e1);
}
else if (!e.allowCommaExp && !e.isGenerated)
else
error(e.loc, "using the result of a comma expression is not allowed");
}
}
override void visit(IntervalExp e)
{

View file

@ -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
---
*/
@ -20,8 +21,10 @@ void hasSideEffect12490(){}
void issue12490()
{
int x;
5, hasSideEffect12490();
1 + 2, hasSideEffect12490();
x, x++;
}
void issue23480()

View file

@ -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++;
}