D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15490 - [REG 2.067] Error variable __nrvoretval cannot be modified at compile time when using -inline
Summary: [REG 2.067] Error variable __nrvoretval cannot be modified at compile time wh...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-31 19:16 UTC by Iain Buclaw
Modified: 2016-02-23 10:04 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Iain Buclaw 2015-12-31 19:16:13 UTC
Code:
---
void main()
{
    import std.regex;
    Regex!(char) pattern;
    pattern = regex("");
    import vibe.core.net;
    void metricReceiver(TCPConnection) { }
    listenTCP(1, conn => metricReceiver(conn), "2");
}

---

Command line (sorry haven't reduced beyond own project):
---
dmd -c -inline -version=VibeUseNativeDriverType -version=VibeLibasyncDriver -I../../../.dub/packages/vibe-d-0.7.26/source/ -I../../../.dub/packages/libasync-0.7.5/source/ -I../../../.dub/packages/memutils-0.4.3/source/
---

Output:
---
Using Linux EPOLL for events
Error: variable __nrvoretval4587 cannot be modified at compile time
/usr/include/dmd/phobos/std/regex/package.d(333):        called from here: regex("^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}$", "")
/usr/include/dmd/phobos/std/regex/package.d(355): Error: template instance std.regex.ctRegexImpl!("^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}$", "") error instantiating
../../../.dub/packages/vibe-d-0.7.26/source/vibe/core/drivers/libasync.d(197):        instantiated from here: ctRegex!("^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}$", "")
Error: variable __nrvoretval4587 cannot be modified at compile time
/usr/include/dmd/phobos/std/regex/package.d(333):        called from here: regex("^([0-9A-Fa-f]{0,4}:){2,7}([0-9A-Fa-f]{1,4}$|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4})$", "")
/usr/include/dmd/phobos/std/regex/package.d(355): Error: template instance std.regex.ctRegexImpl!("^([0-9A-Fa-f]{0,4}:){2,7}([0-9A-Fa-f]{1,4}$|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4})$", "") error instantiating
../../../.dub/packages/vibe-d-0.7.26/source/vibe/core/drivers/libasync.d(198):        instantiated from here: ctRegex!("^([0-9A-Fa-f]{0,4}:){2,7}([0-9A-Fa-f]{1,4}$|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4})$", "")
---

Workaround:
---
Remove -inline flag
---
Comment 1 Iain Buclaw 2015-12-31 19:25:59 UTC
Doesn't happen if I switch from 2.069 to 2.068
Comment 2 ag0aep6g 2016-01-01 13:23:31 UTC
Reduced:

main.d:
----
module main;

import imp1;
import imp2;

void main()
{
    regex();
    listenTCP();
}
----

imp1.d:
----
module imp1;

import imp2;

void listenTCP()
{
    enum r = regex();
}
----

imp2.d:
----
module imp2;

int regex()
{
    return regexImpl();
}

auto regexImpl()
{
    int r = 0;
    return r;
}
----

`dmd -c main.d` works. `dmd -c -inline main.d` gives:
----
Error: variable __nrvoretval51 cannot be modified at compile time
imp1.d(7):        called from here: regex()
----

This reduction fails with 2.068 and 2.067, too. But it compiles with 2.066.
Comment 3 Iain Buclaw 2016-01-03 21:07:10 UTC
(In reply to ag0aep6g from comment #2)
> Reduced:
> 
> This reduction fails with 2.068 and 2.067, too. But it compiles with 2.066.

Thanks alot!

Yes, I have been seeing the error occur in 2.068 too after splitting components of the project into packages.

I have an idea what was the bad commit, will give it a bisect.
Comment 4 Iain Buclaw 2016-01-03 21:39:51 UTC
First bad commit: https://github.com/D-Programming-Language/dmd/pull/4353
Comment 5 github-bugzilla 2016-02-07 00:25:25 UTC
Commits pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b56fa1d1b02c93151f0a25d868f4459cac8d6a4d
fix Issue 15490 - Error variable __nrvoretval cannot be modified at compile time when using -inline

CTFE interpretr can recognize a form `CommaExp(DeclaraationExp(v), VarExp(v))` as
a CTFEable variable declaration when `v._init` is `null`. In other cases, for
examle a sole `DeclarationExp` should have v._init for CTFE-ability.

Supply `VoidInitializer` to allow inlining the temporary for NRVO.

https://github.com/D-Programming-Language/dmd/commit/31232a9c64e799c439af5e3501b20cf9b7e7372b
Merge pull request #5415 from 9rnsr/fix15490

[REG 2.067] Issue 15490 - Error variable __nrvoretval cannot be modified at compile time when using -inline
Comment 6 github-bugzilla 2016-02-23 10:04:29 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b56fa1d1b02c93151f0a25d868f4459cac8d6a4d
fix Issue 15490 - Error variable __nrvoretval cannot be modified at compile time when using -inline

https://github.com/D-Programming-Language/dmd/commit/31232a9c64e799c439af5e3501b20cf9b7e7372b
Merge pull request #5415 from 9rnsr/fix15490