D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16340 - case where version(unittest) results in an invalid warning about a dangling else
Summary: case where version(unittest) results in an invalid warning about a dangling else
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: Mathias Lang
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2016-07-30 19:09 UTC by Jonathan M Davis
Modified: 2016-10-01 11:48 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2016-07-30 19:09:53 UTC
This is a reduced version of some code that I've been working on:


void main()
{
}

version(unittest) template symsToStrs(fields...)
{
    static if(fields.length == 0)
        enum symsToStrs = ["hello"];
    else
        enum symsToStrs = ["world"];
}


Note that if you compile it with warnings enabled, you get something like

q.d(9): Warning: else is dangling, add { } after condition at q.d(5)

However, if you remove the version(unittest) from in front of the template, then the warning goes away. Whether the code is compiled with -unittest doesn't matter. But regardless, there is no dangling else here. So, the warning is incorrect.

This issue looks similar to issue# 15326, but the code in that one doesn't have this problem anymore, so it doesn't look like this is a regression of that bug, though its cause may be similar.
Comment 1 Mathias Lang 2016-09-09 17:37:18 UTC
Pull: https://github.com/dlang/dmd/pull/6118
Comment 2 github-bugzilla 2016-09-10 10:05:06 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/183114aca570878105cda76290f87340f925ccf6
Fix issue 16340 - Invalid dangling else warning triggered within template

Using `parseBlock` when parsing the template body is DRY-er and remove this invalid warning.

https://github.com/dlang/dmd/commit/19479267a6bfac89d270ae13a5c8ae1daf09a5b4
Merge pull request #6118 from mathias-lang-sociomantic/fix-16340

Fix issue 16340 - Invalid dangling else warning triggered within template
Comment 3 github-bugzilla 2016-10-01 11:48:43 UTC
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/183114aca570878105cda76290f87340f925ccf6
Fix issue 16340 - Invalid dangling else warning triggered within template

https://github.com/dlang/dmd/commit/19479267a6bfac89d270ae13a5c8ae1daf09a5b4
Merge pull request #6118 from mathias-lang-sociomantic/fix-16340