D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2221 - Bug with typeof(*this) in template struct
Summary: Bug with typeof(*this) in template struct
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2008-07-12 07:29 UTC by Bill Baxter
Modified: 2014-03-01 00:36 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 Bill Baxter 2008-07-12 07:29:01 UTC
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 Brad Roberts 2008-07-12 12:33:12 UTC
Added 1.033 to the list of versions and updated the bug to reference it.
Comment 2 Nicolay Korslund 2008-11-04 03:30:45 UTC
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 Don 2009-09-04 03:07:29 UTC
This was fixed in 1.039/2.023, but not listed in the changelog. (it's the same root cause as bug 2527).