Re: DMD Source Guidance: Unused Return Values of Strictly Pure Function Calls

2014-02-28 Thread bearophile

Nordlöw:

Did you set this as WONTFIX because of too many warnings from 
functions that may throw or just do asserts such as unittests?


It's a RESOLVED LATER. I think it was not me to tag it like 
that. And it was tagged like that because of too many warnings in 
templated functions.


Bye,
bearophile


Re: DMD Source Guidance: Unused Return Values of Strictly Pure Function Calls

2014-02-28 Thread Nordlöw

I believe I found a good solution to Issue 3882:
https://d.puremagic.com/issues/show_bug.cgi?id=3882

It works as expected and I found two bugs in my code with it.

My current solution is to add the following at line 147 in 
dmd/src/sideeffect.c:


  case TOKcall:
/* Issue 3882: Don't complain about calling functions 
with no effect,
 * because purity and nothrow are inferred, and 
because some of the
 * runtime library depends on it. Needs more 
investigation.

 */
if (global.params.warnings  !global.gag)
{
if (e-type-ty == Tvoid)
{
/* TODO: Restrict this message to call 
hierarchies that
 * never call assert (and or not called from 
inside

 * unittest blocks) */
// e-warning(Call %s with void return has 
no effect, e-toChars());

}
else
{
e-warning(Call %s with no effect discards 
return value, e-toChars());

}
}
return;

Does it suffice to just do a pull request referring to Issue 3882.

/Per


Re: DMD Source Guidance: Unused Return Values of Strictly Pure Function Calls

2014-02-28 Thread Nordlöw

On Friday, 28 February 2014 at 10:40:04 UTC, bearophile wrote:

Nordlöw:

Did you set this as WONTFIX because of too many warnings from 
functions that may throw or just do asserts such as unittests?


It's a RESOLVED LATER. I think it was not me to tag it like 
that. And it was tagged like that because of too many warnings 
in templated functions.


Bye,
bearophile


My tested application is massive I got not false positives.

I can do some more tests...

/Per


Re: DMD Source Guidance: Unused Return Values of Strictly Pure Function Calls

2014-02-28 Thread Nordlöw
that. And it was tagged like that because of too many warnings 
in templated functions.


Were those warnings emitted also by non-void return functions?

/Per


Re: DMD Source Guidance: Unused Return Values of Strictly Pure Function Calls

2014-02-27 Thread Nordlöw

On Thursday, 27 February 2014 at 23:38:34 UTC, Nordlöw wrote:
Does anybody know where in the DMD source I can figure out if 
the return value of a function call is used or not?


I'm trying to figure out how to implement automatic detection 
of unused return values from calls to strictly pure functions.


The closest I have come is the function functionParameters() in 
expression.c


Ideas anyone?


The return type of course also must be non-void in order for the 
warning to printed.


DMD Source Guidance: Unused Return Values of Strictly Pure Function Calls

2014-02-27 Thread Nordlöw
Does anybody know where in the DMD source I can figure out if the 
return value of a function call is used or not?


I'm trying to figure out how to implement automatic detection of 
unused return values from calls to strictly pure functions.


The closest I have come is the function functionParameters() in 
expression.c


Ideas anyone?


Re: DMD Source Guidance: Unused Return Values of Strictly Pure Function Calls

2014-02-27 Thread bearophile

Nordlöw:

Does anybody know where in the DMD source I can figure out if 
the return value of a function call is used or not?


I'm trying to figure out how to implement automatic detection 
of unused return values from calls to strictly pure functions.


The closest I have come is the function functionParameters() in 
expression.c


Ideas anyone?


See:

https://d.puremagic.com/issues/show_bug.cgi?id=3882

Bye,
bearophile


Re: DMD Source Guidance: Unused Return Values of Strictly Pure Function Calls

2014-02-27 Thread Timon Gehr

On 02/28/2014 12:38 AM, Nordlöw wrote:

Does anybody know where in the DMD source I can figure out if the return
value of a function call is used or not?


I'm not familiar with the DMD source code, but a good way to proceed is 
usually to grep for existing error messages that are somehow related. In 
this case, DMD already complains about some cases of unused values:


$ grep no effect *.c
declaration.c:   error(storage class 'auto' has no effect if type 
is not inferred, did you mean 'scope'?);
expression.c:e = new CastExp(loc, e, Type::tvoid);   // 
avoid has no effect error

mtype.c:// substitution has no effect on function pointer type.
sideeffect.c: * Don't complain about an expression 
with no effect if it was cast to void
sideeffect.c:/* Don't complain about calling functions 
with no effect,

sideeffect.c:error(%s has no effect, toChars());
sideeffect.c:error(%s has no effect in expression (%s),

This leads directly to sideeffect.c: Expression::discardValue(), which 
seems to be the place where you want to insert your detection code.


Re: DMD Source Guidance: Unused Return Values of Strictly Pure Function Calls

2014-02-27 Thread Nordlöw

https://d.puremagic.com/issues/show_bug.cgi?id=3882

Bye,
bearophile


Did you set this as WONTFIX because of too many warnings from 
functions that may throw or just do asserts such as unittests?


If so does anyone see any way to restrict warnings even further 
for example by checking if a function will call assert or nothrow 
or do a debug print?