D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3138 - Const bug
Summary: Const bug
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2009-07-05 22:10 UTC by Walter Bright
Modified: 2015-06-09 05:14 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 Walter Bright 2009-07-05 22:10:33 UTC
This code crashes the compiler:

class E(uint N) { }

class Boom
{
   typedef E!(5) ET;
public:
   ET foo() const  // Badness here!
   { return x[3]; }

   ET[int] x;
}

void main()
{
   auto b = new Boom();
   b.foo();
}

Technically, it's invalid, because I'm returning a mutable member reference from a const member function.  However, the error message is to crash the compiler.  Note that if you replace ET with a builtin or a non-template class, it correctly emits the expected error.  Not sure why the template type blows it up, but it does.

Dave
Comment 1 Don 2009-07-06 00:46:47 UTC
I cannot reproduce this. Works for me DMD2.031 Windows. (crashes at runtime with a range error).
What compiler version are you using?
Comment 2 Don 2009-09-22 06:04:13 UTC
This was crashing in 2.026, but fixed by 2.030.
Comment 3 Stewart Gordon 2009-12-29 13:44:03 UTC
It may've been fixed now, but still, how is this accepts-invalid?