D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8944 - Loosing const from shared const type when unqualifying in foreach over tuple
Summary: Loosing const from shared const type when unqualifying in foreach over tuple
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks: 2573
  Show dependency treegraph
 
Reported: 2012-11-02 10:34 UTC by Denis Shelomovskii
Modified: 2019-08-18 23:17 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 Denis Shelomovskii 2012-11-02 10:34:54 UTC
---
template TypeTuple(TList...)
{ alias TList TypeTuple; }

void main()
{
    foreach(T; TypeTuple!(shared void*, const shared void*))
    {
        static      if (is(T U == shared const U)) alias U TU;
        else static if (is(T U == shared       U)) alias U TU;
        else static assert(0);

        pragma(msg, "T:  ", T, "\nTU: ", TU, "\n");

        static if(is(T P == P*))
        static if(is(TU PU == PU*))
            static assert(is(P == PU)); // fails on second iteration

        T t;
        bool b = is(typeof(cast(TU*) &t = null)); // comment to hide a bug
    }
}
---

Output:
---
T:  shared(void*)
TU: shared(void)*

T:  shared(const(void*))
TU: shared(void)*

main.d(16): Error: static assert  (is(shared(const(void)) == shared(void))) is false
---
Second `TU` should be `shared(const(void))*`.

As always, such (unexpected) template bugs are hard to figure out.
Comment 1 ag0aep6g 2019-08-18 23:17:34 UTC
Works for me since DMD 2.065.

The assert doesn't fail anymore, and the second `TU` is `shared(const(void))*` now.