D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6488 - DMD compiler bug
Summary: DMD compiler bug
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
: 6502 (view as issue list)
Depends on:
Blocks:
 
Reported: 2011-08-12 19:01 UTC by soarowl
Modified: 2011-10-18 10:18 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description soarowl 2011-08-12 19:01:38 UTC
When I compile tools\rdmd.d with following options:

dmd -inline -J. -noboundscheck -nofloat -O -release rdmd.d

Compiler has this error:

Error: template core.time.TickDuration.to(string units,T) if ((units == "seconds" || units == "msecs" || units == "usecs" || units == "hnsecs" || units == "nsecs") && (__traits(isIntegral,T) && T.sizeof >= 4)) cannot deduce template function from argument types !("seconds",long)()

But if I compile rdmd.d with those options, all fine:

dmd -inline -J. -nofloat -O -release rdmd.d
dmd -J. -noboundscheck -nofloat -O -release rdmd.d
dmd -inline -J. -noboundscheck -nofloat -O rdmd.d
Comment 1 Rainer Schuetze 2011-10-02 02:56:57 UTC
A similar error happens if you try to compile time.di directly:

>dmd -c -o- c:\l\dmd-2.055\src\druntime\import\core\time.di

c:\l\dmd-2.055\src\druntime\import\core\time.di(253): Error: template core.time.
TickDuration.to(string units,T) if ((units == "seconds" || units == "msecs" || u
nits == "usecs" || units == "hnsecs" || units == "nsecs") && (__traits(isIntegra
l,T) && T.sizeof >= 4)) does not match any function template declaration
c:\l\dmd-2.055\src\druntime\import\core\time.di(253): Error: template core.time.
TickDuration.to(string units,T) if ((units == "seconds" || units == "msecs" || u
nits == "usecs" || units == "hnsecs" || units == "nsecs") && (__traits(isIntegra
l,T) && T.sizeof >= 4)) cannot deduce template function from argument types !("s
econds",long)()

In time.di, the to template functions have been converted to eponymous templates, which seems to trigger the error in combination with qualifiers. Here is a reduced test case:

struct TickDuration
{
	template to(T) if (__traits(isIntegral,T))
	{
		const T to()
		{
			return 1;
		}
	}

	template to(T) if (__traits(isFloating,T))
	{
		const T to()
		{
			return 0;
		}
	}

	const long seconds() // line 21
	{
		return to!(long)();
	}
	
}

void main()
{
	TickDuration d;
	d.seconds();
}

>dmd test.d

test.d(21): Error: template test.TickDuration.to(T) if (__traits(isIntegral,T))
does not match any function template declaration
test.d(21): Error: template test.TickDuration.to(T) if (__traits(isIntegral,T))
cannot deduce template function from argument types !(long)()

The error disappears if you remove the const qualifier from seconds() or if you remove the second template.
Comment 3 Walter Bright 2011-10-18 10:18:19 UTC
*** Issue 6502 has been marked as a duplicate of this issue. ***