www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Phobos unit tests, unreadable code

reply Jacob Carlborg <doob me.com> writes:
I'm merging the orange (std.serialization) unit tests with the test of 
Phobos. I hit a problem. I'm getting a warning about unreadable code but 
it's clear the code is reachable in some cases because there's a 
static-if involved. The unit tests won't run if there's a warning. How 
can we solve this?

-- 
/Jacob Carlborg
Jun 12 2013
parent reply "monarch_dodra" <monarchdodra gmail.com> writes:
On Wednesday, 12 June 2013 at 08:49:36 UTC, Jacob Carlborg wrote:
 I'm merging the orange (std.serialization) unit tests with the 
 test of Phobos. I hit a problem. I'm getting a warning about 
 unreadable code but it's clear the code is reachable in some 
 cases because there's a static-if involved. The unit tests 
 won't run if there's a warning. How can we solve this?
The problem is that there must be a static if branch that is shortcicuiting the code, right? Eg: unittest { static if (somecondition) return; unreachable_code } The compiler error (AFAIK) for "unreachable code" is not generic to the code, but only appears for the specific types that makes the unreachable_code actually unreachable. I've hit this a couple of times in algorithm's unittests. The workaround is usally to use static else and/or assert(0), and to make sure that regardless of types, there is never any code inserted that could be un-used. Do you have a link to the actual problem?
Jun 12 2013
parent Jacob Carlborg <doob me.com> writes:
On 2013-06-12 10:55, monarch_dodra wrote:

 Do you have a link to the actual problem?
This, for example: https://github.com/jacob-carlborg/orange/blob/master/orange/serialization/Serializer.d#L1217 I could probably add an else. -- /Jacob Carlborg
Jun 12 2013