Bug 2221 – Bug with typeof(*this) in template struct

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2008-07-12T07:29:00Z
Last change time
2014-03-01T00:36:31Z
Keywords
rejects-valid
Assigned to
nobody
Creator
wbaxter

Comments

Comment #0 by wbaxter — 2008-07-12T07:29:01Z
Here's the code: ----- struct Struct(T) { static if (is(typeof(T.nan))) { static const is_fptype = true; } else { static const is_fptype = false; } static if(typeof(*this).is_fptype) //static if((typeof(*this)).is_fptype) //<- fixes it { pragma(msg, "T is " ~ T.stringof); pragma(msg, typeof(*this).stringof ~ " is fp type"); } else { pragma(msg, "T is " ~ T.stringof); pragma(msg, typeof(*this).stringof ~ " is NOT fp type"); } } alias Struct!(float) Sf; alias Struct!(int) Si; ------- From compiling that I get the output: """ T is float Struct!(float) is fp type T is int Struct!(float) is fp type """ The output expected is: """ T is float Struct!(float) is fp type T is int Struct!(int) is NOT fp type """ And that is the output you get if you stick extra parentheses around (typeof(*this)). This was tested on D1.033. Possibly related to: * http://d.puremagic.com/issues/show_bug.cgi?id=2219 * http://d.puremagic.com/issues/show_bug.cgi?id=2154
Comment #1 by braddr — 2008-07-12T12:33:12Z
Added 1.033 to the list of versions and updated the bug to reference it.
Comment #2 by korslund — 2008-11-04T03:30:45Z
Also possibly related to: http://d.puremagic.com/issues/show_bug.cgi?id=2359 The various typeof(this) bugs seems appear in 1.032 and onward, and not be present in 1.031 and earlier. The changelog for 1.032 lists several items relating to typeof, so it's reasonable to assume that one of the fixes introduced this bug.
Comment #3 by clugdbug — 2009-09-04T03:07:29Z
This was fixed in 1.039/2.023, but not listed in the changelog. (it's the same root cause as bug 2527).