www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4018] New: Line Number not set at instatiation point

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4018

           Summary: Line Number not set at instatiation point
           Product: D
           Version: 2.041
          Platform: Other
               URL: http://digitalmars.com/d/2.0/template.html#TemplateVal
                    ueParameter
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: Jesse.K.Phillips+D gmail.com
                CC: Jesse.K.Phillips+D gmail.com


--- Comment #0 from Jesse Phillips <Jesse.K.Phillips+D gmail.com> 2010-03-27
09:30:37 PDT ---
The specification states that:

The __FILE__ and __LINE__ expand to the source file name and line number at the
point of instantiation.

This is not the case for the code below:

-------------------
import std.stdio;

void ODSfd(alias n)() {
      writefln("%s:%s | %s = %d", __FILE__, __LINE__, n.stringof, n);
}
void ODSfs(alias n)() {
      writefln("%s:%s | %s = %s", __FILE__, __LINE__, n.stringof, n);
}
void ODSfx(alias n)() {
      writefln("%s:%s | %s = 0x%08x", __FILE__, __LINE__, n.stringof, n);
}

void main() {
   int zbar = 5;
   string foo = "hi";

   ODSfd!(zbar);
   ODSfs!(foo);
   ODSfx!(zbar);
}
-------------------

Expected output:
file.d:17 | zbar = 5
file.d:18 | foo = hi
file.d:19 | zbar = 0x00000005


Actual output:
file.d:4 | zbar = 5
file.d:7 | foo = hi
file.d:10 | zbar = 0x00000005

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 27 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4018


Justin Spahr-Summers <Justin.SpahrSummers gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Justin.SpahrSummers gmail.c
                   |                            |om


--- Comment #1 from Justin Spahr-Summers <Justin.SpahrSummers gmail.com>
2010-03-27 11:44:50 CDT ---
(In reply to comment #0)


Note that the docs say that referring to template value parameters. The code
you posted is intended behavior; you would have to add a couple value
parameters to each one that default to __FILE__ and __LINE__ and print those
out.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 27 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4018


Jesse Phillips <Jesse.K.Phillips+D gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|Linux                       |All


--- Comment #2 from Jesse Phillips <Jesse.K.Phillips+D gmail.com> 2010-03-27
09:55:31 PDT ---
In that case, the below has the same result.

------------
import std.stdio;

void ODSfd(alias n, string file = __FILE__, int line = __LINE__)() {
      writefln("%s:%s | %s = %d", file, line, n.stringof, n);
}
void ODSfs(alias n, string file = __FILE__, int line = __LINE__)() {
      writefln("%s:%s | %s = %s", file, line, n.stringof, n);
}
void ODSfx(alias n, string file = __FILE__, int line = __LINE__)() {
      writefln("%s:%s | %s = 0x%08x", file, line, n.stringof, n);
}

void main() {
   int zbar = 5;
   string foo = "hi";

   ODSfd!(zbar);
   ODSfs!(foo);
   ODSfx!(zbar);
}
-----------------

Expected Output:
linefile.d:17 | zbar = 5
linefile.d:18 | foo = hi
linefile.d:19 | zbar = 0x00000005

Actual Output:
linefile.d:3 | zbar = 5
linefile.d:6 | foo = hi
linefile.d:9 | zbar = 0x00000005

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 27 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4018


dawg dawgfoto.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |changlon gmail.com


--- Comment #3 from dawg dawgfoto.de 2012-03-20 22:10:46 PDT ---
*** Issue 5686 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4018


dawg dawgfoto.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dawg dawgfoto.de


--- Comment #4 from dawg dawgfoto.de 2012-03-20 22:29:35 PDT ---
This only happens with explicit instantiations foo!(targs)(args).
In that case semantic is run in a different scope.
A workaround for functions is to split the parameters into explicit
and default parameters.

template foo(T)
{
    void foo(size_t line = __LINE__)()
    {
        pragma(msg, line);
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4018


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
           Platform|Other                       |All
            Version|2.041                       |D2


--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2013-10-02 08:16:14 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2617

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 02 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4018



--- Comment #6 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-10-02
19:07:11 PDT ---
*** Issue 11158 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 02 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4018



--- Comment #7 from github-bugzilla puremagic.com 2013-10-03 07:08:17 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7c4ef3310168fd6f30f704e005845c197df9cc7f
fix Issue 4018 - __FILE__ and __LINE__ as default template parameters not set
to instantiation point per spec

Also fixes __MODULE__, __FUNCITON__, and __PRETTY_FUNCTION__

https://github.com/D-Programming-Language/dmd/commit/6c8f9ffe16a19a1ba81eef0b645b1d755329f1d9
Merge pull request #2617 from 9rnsr/fix4018

Issue 4018 - __FILE__ and __LINE__ as default template parameters not set to
instantiation point per spec

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 03 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4018


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 03 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4018



--- Comment #8 from Martin Nowak <code dawg.eu> 2013-10-03 08:32:42 PDT ---
(In reply to comment #6)
 *** Issue 11158 has been marked as a duplicate of this issue. ***
Oh, I thought this one was already fixed. Now it is, thanks a lot Kenji. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 03 2013