digitalmars.D.learn - DMD Source Guidance: Unused Return Values of Strictly Pure Function
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (7/7) Feb 27 2014 Does anybody know where in the DMD source I can figure out if the
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (3/10) Feb 27 2014 The return type of course also must be non-void in order for the
- bearophile (5/12) Feb 27 2014 See:
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (5/8) Feb 27 2014 Did you set this as WONTFIX because of too many warnings from
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (34/34) Feb 28 2014 I believe I found a good solution to Issue 3882:
- bearophile (6/8) Feb 28 2014 It's a "RESOLVED LATER". I think it was not me to tag it like
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (4/12) Feb 28 2014 My tested application is massive I got not "false positives".
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (2/4) Feb 28 2014 Were those warnings emitted also by non-void return functions?
- Timon Gehr (18/20) Feb 27 2014 I'm not familiar with the DMD source code, but a good way to proceed is
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?
Feb 27 2014
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.
Feb 27 2014
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
Feb 27 2014
https://d.puremagic.com/issues/show_bug.cgi?id=3882 Bye, bearophileDid 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?
Feb 27 2014
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
Feb 28 2014
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
Feb 28 2014
On Friday, 28 February 2014 at 10:40:04 UTC, bearophile wrote:Nordlöw:My tested application is massive I got not "false positives". I can do some more tests... /PerDid 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
Feb 28 2014
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
Feb 28 2014
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.
Feb 27 2014