D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12202 - SortedRange + alias this + foreach => Segmentation fault
Summary: SortedRange + alias this + foreach => Segmentation fault
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 critical
Assignee: No Owner
URL:
Keywords: ice
Depends on:
Blocks:
 
Reported: 2014-02-19 05:27 UTC by Tobias Pankrath
Modified: 2017-01-09 17:40 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 Tobias Pankrath 2014-02-19 05:27:07 UTC
--
 struct S(T)
  4 {
  5    import std.range;
  6    
  7    T[] data;
  8    
  9    auto sortedRange() { return assumeSorted(data); }
 10    alias sortedRange this; 
 11    
 12 }  
 13 unittest
 14 {
 15    auto a1 = S!int([1, 3,3,3, 4, 4]);
 16    foreach(i, e; a1)
 17    {  
 18    
 19    }  
 20 }                       
--
$ dmd -unittest -main test.d
zsh: segmentation fault (core dumped)  dmd -unittest -main test.d

Both in 2.064 and ~master.
Comment 1 hsteoh 2014-09-11 19:30:59 UTC
Reduced test case:
------
struct S(T)
{
   import std.range;
}
unittest
{
   auto a1 = S!int();
   foreach(i, e; a1)
   {
   }
}
------

Seems this has nothing to do with sortedRange, it's a compiler bug.
Comment 2 hsteoh 2014-09-11 20:54:26 UTC
OK, managed to cut it down to an almost bare-minimal test case:

----range.d----
@property front()() { }
---------------

----test.d----
struct S
{
    import range;
}
unittest
{
    S a1;
    foreach(i, e; a1)
    {
    }
}
---------------

Compiler command: dmd -main -unittest test.d
Comment 3 Martin Krejcirik 2017-01-09 17:40:08 UTC
All examples produce an error message since 2.071