D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20608 - [REG2.087] Cannot pass tuple.expand to auto ref T... template argument pack
Summary: [REG2.087] Cannot pass tuple.expand to auto ref T... template argument pack
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: industry, pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2020-02-25 18:30 UTC by johanengelen
Modified: 2020-09-25 09:46 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 johanengelen 2020-02-25 18:30:03 UTC
Testcase:
```
void foo(T...)(auto ref T args) {}

void main() {
    import std.typecons;
    enum tup = tuple(1,"jojo");
    foo(tup.expand); // line 6
}
```

This errors with DMD >= 2.087 with:
onlineapp.d(6): Error: cannot modify constant expression `Tuple(1, "jojo").__expand_field_0`
Comment 1 moonlightsentinel 2020-06-05 14:35:40 UTC
Digger:

commit e268d8301979b2f1f83b4565a20ef1387ba34396
Author: The Dlang Bot <code+dlang-bot@dawg.eu>
Date:   Sun Jul 7 10:14:29 2019 +0200

dmd: Merge pull request #10115 from Basile-z/issue-20011-17828

https://github.com/dlang/dmd/pull/10115

fix issue 20011, 17828 - crash or accept write operation on members of manifest constant structs
merged-on-behalf-of: Walter Bright <WalterBright@users.noreply.github.com>
Comment 2 moonlightsentinel 2020-06-05 15:13:45 UTC
Digger:

commit e268d8301979b2f1f83b4565a20ef1387ba34396
Author: The Dlang Bot <code+dlang-bot@dawg.eu>
Date:   Sun Jul 7 10:14:29 2019 +0200

dmd: Merge pull request #10115 from Basile-z/issue-20011-17828

https://github.com/dlang/dmd/pull/10115

fix issue 20011, 17828 - crash or accept write operation on members of manifest constant structs
merged-on-behalf-of: Walter Bright <WalterBright@users.noreply.github.com>
Comment 3 moonlightsentinel 2020-06-05 15:14:30 UTC
Reduced example:

void foo(T...)(auto ref T args) {}

void main()
{
  enum tup = Tuple();
  foo(tup.expand); // line 6
}

struct Tuple
{
  int expand;
}

foo should probably infer non-ref for enums.
Comment 4 Dlang Bot 2020-09-02 21:50:57 UTC
@kinke updated dlang/dmd pull request #10124 "Fix Issue 19754 - Re-apply #9505 and fix it, making isLvalue() logic more restrictive wrt. literals" fixing this issue:

- Fix Issue 20608 - Revert (obsolete and problematic) #10115
  
  Which just patched over some cracks wrt. accessing fields of struct
  literals. Not a full revert, as the (useful) test cases are kept.

https://github.com/dlang/dmd/pull/10124
Comment 5 Dlang Bot 2020-09-25 09:46:16 UTC
dlang/dmd pull request #10124 "Fix Issue 19754 - Re-apply #9505 and fix it, making isLvalue() logic more restrictive wrt. literals" was merged into master:

- eddb064ba44d2aeed527396184b40ea37169e80d by Martin Kinkelin:
  Fix Issue 20608 - Revert (obsolete and problematic) #10115
  
  Which just patched over some cracks wrt. accessing fields of struct
  literals. Not a full revert, as the (useful) test cases are kept.

https://github.com/dlang/dmd/pull/10124