[Issue 5784] New: Template instantiation with enum constant as parameter, missing implicit cast
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Mar 24 22:46:03 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5784
Summary: Template instantiation with enum constant as
parameter, missing implicit cast
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: pszturmaj at tlen.pl
--- Comment #0 from Piotr Szturmaj <pszturmaj at tlen.pl> 2011-03-24 22:42:41 PDT ---
When template is instantiated for the first time, using integral literal,
everything is ok. But if the same template is instantiated for the first time,
using enum constant as its parameter then instantiation can't be matched using
is expression.
struct A(int n)
{
bool[n] nBooleans;
}
template isA(T)
{
static if (is(T X == A!N, int N))
enum isA = true;
else
enum isA = false;
}
enum int boolCount = 5;
Now, when first instantiation is using integer literal, it works ok:
alias A!5 fromLiteral;
alias A!boolCount fromEnum;
static assert(isA!(A!5)); // pass
static assert(isA!(A!boolCount)); // pass
static assert(is(A!5 == A!boolCount)); // pass
But, when first instantiation is using enum constant, the is expression fails:
alias A!boolCount fromEnum;
alias A!5 fromLiteral;
static assert(isA!(A!5)); // fail
static assert(isA!(A!boolCount)); // fail
static assert(is(A!5 == A!boolCount)); // pass
Note that only difference is order of alias declarations.
The cause of this bug is enum constant which is not implicitly casted to its
base type (int). With explicit casting everything is ok:
alias A!(cast(int)boolCount) fromEnum;
alias A!5 fromLiteral;
static assert(isA!(A!5)); // pass
static assert(isA!(A!boolCount)); // pass
static assert(is(A!5 == A!boolCount)); // pass
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list