D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1969 - ICE(cod1.c) using undefined operator with one const operand
Summary: ICE(cod1.c) using undefined operator with one const operand
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P3 normal
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2008-04-02 09:42 UTC by Neil Vice
Modified: 2015-06-09 01: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 Neil Vice 2008-04-02 09:42:08 UTC
The following code results in an Internal error in DMD 2.012:

////////

struct Foo { }

struct Bar
{
  public Foo opSub(Bar other)
  {
    return Foo();
  }
}

void main()
{
  // Removing the following const eliminates the error
  const Foo test = Foo();

  // Causes the error as (Foo + Foo) is undefined
  auto result = test + (Bar() - Bar());

  auto ok1 = test + test;  // No error
  auto ok2 = test + Foo(); // No error
}

////////
Comment 1 Don 2009-05-19 01:01:53 UTC
Simplified test case

struct Bar{ }

const(Bar) baz() { return Bar(); }

void foo() {
  Bar result = Bar() + baz();
}
Comment 2 Don 2009-07-13 04:53:56 UTC
/* Root cause: BinExp::typeCombine() is checking for an _exact_ match, but
typeMerge() will return success.

PATCH: cast.c BinExp::typeCombine().
Compare the immutable versions of the types, instead of the types themselves.

    if (op == TOKmin || op == TOKadd)
    {
	if (t1->ito == t2->ito && (t1->ty == Tstruct || t1->ty == Tclass))
	 goto Lerror;
	 }
*/
Comment 3 Walter Bright 2009-09-03 13:33:04 UTC
Fixed dmd 2.032