digitalmars.D.bugs - [Issue 5363] New: const + alias this = wrong code
- d-bugmail puremagic.com (40/40) Dec 21 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5363
- d-bugmail puremagic.com (26/26) Jun 21 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5363
- d-bugmail puremagic.com (10/10) Jul 14 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5363
- d-bugmail puremagic.com (11/11) Apr 22 2012 http://d.puremagic.com/issues/show_bug.cgi?id=5363
- d-bugmail puremagic.com (45/45) Nov 13 2012 http://d.puremagic.com/issues/show_bug.cgi?id=5363
http://d.puremagic.com/issues/show_bug.cgi?id=5363
Summary: const + alias this = wrong code
Product: D
Version: D2
Platform: Other
OS/Version: Windows
Status: NEW
Keywords: wrong-code
Severity: critical
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: dsimcha yahoo.com
Happens on at least 2.050, 2.051.
import core.stdc.stdio; // Pollutes asm less than std.stdio.
struct Foo {
uint dummy = 0;
uint k = 0;
alias dummy this; // Yes, this line is necessary for reproducing the bug.
// This needs to be a function to reproduce the bug. Setting k directly
// doesn't cut it.
void put(uint element) {
k += element;
}
// rhs must be const to reproduce the bug.
void put(const Foo rhs) {
k += rhs.k;
}
}
void main() {
Foo foo1, foo2;
foo1.put(10);
foo2.put(42);
foo1.put(foo2);
printf("%d\n", foo1.k); // 10, should be 52
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 21 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5363
Kenji Hara <k.hara.pg gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |k.hara.pg gmail.com
More simple case:
----
struct S
{
int dummy;
alias dummy this;
}
int foo(int){ return 1; }
int foo(const(S)){ return 2; }
void main()
{
S s;
assert(foo(s) == 2);
}
----
It is the reason of this problem that the type matching levels through normal
and alias this have same basis.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 21 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5363
Kenji Hara <k.hara.pg gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
https://github.com/D-Programming-Language/dmd/pull/173
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 14 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5363
SomeDude <lovelydear mailmetrash.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lovelydear mailmetrash.com
PDT ---
Bug still here in 2.059.
Kenji, what happened to your pull ?
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 22 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5363
jens.k.mueller gmx.de changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jens.k.mueller gmx.de
OS/Version|Windows |All
Severity|critical |blocker
Today I ran into this bug. Unfortunately it tooks quite some time until I had a
minimal example that exemplified the problem. Then I could search the database
to find this report here.
I leave my minimal example here for reference.
struct A
{
B b;
alias b this;
}
struct B
{
static struct Value
{
}
Value value;
B[] bs;
alias value this;
bool opEquals(ref const B rhs) const // remove const in front of B and it
works
{
return this.bs == rhs.bs;
}
}
unittest
{
A a;
a.bs ~= B.init;
B b;
b.bs ~= B.init;
assert(b.opEquals(a)); // fails
}
This is Linux and dmd2.060.
This issue is a blocker for me because I can't use const and alias this
anymore. I have to remove the const which makes my code error-prone.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 13 2012









d-bugmail puremagic.com 