Skip to content

Commit

Permalink
fix Issue 12619 - Invalid warning for unused return value of debug me…
Browse files Browse the repository at this point in the history
…mcpy
  • Loading branch information
9rnsr committed Apr 30, 2014
1 parent 1672505 commit 384e23a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
31 changes: 20 additions & 11 deletions src/sideeffect.c
Expand Up @@ -90,12 +90,12 @@ bool lambdaHasSideEffect(Expression *e)
if (ce->e1->type)
{
Type *t = ce->e1->type->toBasetype();
if ((t->ty == Tfunction && ((TypeFunction *)t)->purity > PUREweak &&
((TypeFunction *)t)->isnothrow)
||
(t->ty == Tdelegate && ((TypeFunction *)((TypeDelegate *)t)->next)->purity > PUREweak &&
((TypeFunction *)((TypeDelegate *)t)->next)->isnothrow)
)
if (t->ty == Tdelegate)
t = ((TypeDelegate *)t)->next;
if (t->ty == Tfunction)
((TypeFunction *)t)->purityLevel();
if (t->ty == Tfunction && ((TypeFunction *)t)->purity > PUREweak &&
((TypeFunction *)t)->isnothrow)
{
}
else
Expand Down Expand Up @@ -152,6 +152,7 @@ void discardValue(Expression *e)
/* Issue 3882: */
if (global.params.warnings && !global.gag)
{
CallExp *ce = (CallExp *)e;
if (e->type->ty == Tvoid)
{
/* Don't complain about calling void-returning functions with no side-effect,
Expand All @@ -162,12 +163,20 @@ void discardValue(Expression *e)
* never call assert (and or not called from inside unittest blocks)
*/
}
else
else if (ce->e1->type)
{
CallExp *ce = (CallExp *)e;
e->warning("Call to function %s without side effects discards return value of type %s, prepend a cast(void) if intentional",
ce->f->toPrettyChars(),
e->type->toChars());
Type *t = ce->e1->type->toBasetype();
if (t->ty == Tdelegate)
t = ((TypeDelegate *)t)->next;
if (t->ty == Tfunction)
((TypeFunction *)t)->purityLevel();
if (t->ty == Tfunction && ((TypeFunction *)t)->purity > PUREweak &&
((TypeFunction *)t)->isnothrow)
{
e->warning("Call to function %s without side effects discards return value of type %s, prepend a cast(void) if intentional",
ce->f->toPrettyChars(),
e->type->toChars());
}
}
}
return;
Expand Down
18 changes: 16 additions & 2 deletions test/fail_compilation/fail3882.d
@@ -1,8 +1,9 @@
// REQUIRED_ARGS: -w
// PERMUTE_ARGS: -debug
/*
TEST_OUTPUT:
---
fail_compilation/fail3882.d(26): Warning: Call to function fail3882.strictlyPure!int.strictlyPure without side effects discards return value of type int, prepend a cast(void) if intentional
fail_compilation/fail3882.d(28): Warning: Call to function fail3882.strictlyPure!int.strictlyPure without side effects discards return value of type int, prepend a cast(void) if intentional
---
*/

Expand All @@ -19,9 +20,22 @@ fail_compilation/fail3882.d(26): Warning: Call to function fail3882.strictlyPure
return x*x;
}

void main(string args[]) {
void main()
{
int x = 3;
strictVoidReturn(x);
nonstrictVoidReturn(x);
strictlyPure(x);
}

/******************************************/
// 12619

extern (C) @system nothrow pure void* memcpy(void* s1, in void* s2, size_t n);
// -> weakly pure

void test12619() pure
{
ubyte[10] a, b;
debug memcpy(a.ptr, b.ptr, 5); // memcpy call should have side effect
}

0 comments on commit 384e23a

Please sign in to comment.