Thread overview
[Issue 5801] New: Using typeof() in function header breaks ITFI and default template arguments.
Mar 30, 2011
klickverbot
Apr 10, 2011
klickverbot
Dec 21, 2011
Kenji Hara
March 30, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5801

           Summary: Using typeof() in function header breaks ITFI and
                    default template arguments.
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Keywords: rejects-valid
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: code@klickverbot.at


--- Comment #0 from klickverbot <code@klickverbot.at> 2011-03-30 15:55:34 PDT ---
The following program compiles (bar uses a default type for T, baz relies on
IFTI):
---
void bar(T = double)(int i) {}
void baz(T)(int i, T t) {}
void main() {
    bar(2);
    baz(3, "baz");
}
---

But if typeof() is used instead of explicitly specifying int, neither calls to bar and baz work any longer:
---
int a;
void bar(T = double)(typeof(a) i) {}
void baz(T)(typeof(a) i, T t) {}
void main() {
    bar(2);  // Does not compile.
    baz(3, "baz"); // Does not compile.
}
---

The respective error messages are:
Error: template test.bar(T = double) does not match any function template
declaration
Error: template test.bar(T = double) cannot deduce template function from
argument types !()(int)
and
Error: template test.baz(T) does not match any function template declaration
Error: template test.baz(T) cannot deduce template function from argument types
!()(int,string).

If the template parameter is specified explicitly, however, both of the examples work again:
---
int a;
void bar(T = double)(typeof(a) i) {}
void baz(T)(typeof(a) i, T t) {}
void main() {
    bar!double(2);
    baz!string(3, "baz");
}
---

DMD from Git master at b7133502.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 30, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5801


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #1 from bearophile_hugs@eml.cc 2011-03-30 16:31:00 PDT ---
Take a look at bug 4413 to see if this is a dupe.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 10, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5801



--- Comment #2 from klickverbot <code@klickverbot.at> 2011-04-10 14:08:36 PDT ---
(In reply to comment #1)
> Take a look at bug 4413 to see if this is a dupe.

I'm not sure – it's certainly not a direct duplicate, but the root cause might be the same.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 21, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5801


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2011-12-21 05:55:25 PST ---
*** This issue has been marked as a duplicate of issue 4413 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------