Bug 5832 – Template alias parameters are never successfully pattern matched
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-04-10T16:01:00Z
Last change time
2012-11-10T10:24:06Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
code
Comments
Comment #0 by code — 2011-04-10T16:01:57Z
The following snippet compiles with latest DMD 2 (0219a5f), but does not behave as expected:
---
struct Bar(alias v) {}
template isBar(T) {
static if (is(T _ : Bar!(v), alias v)) {
enum isBar = true;
} else {
enum isBar = false;
}
}
pragma(msg, isBar!(Bar!1234)); // prints false
---
According to the spec, the second parameter to the is() expression is a TemplateParameterList, and indeed using a TemplateAliasParameter compiles, but the type is never matched, i.e. the expression always yields false.
The same phenomenon also occurs when trying to use a specialized template:
---
struct Bar(alias v) {}
template isBar(T) {
enum isBar = false;
}
template isBar(T : Bar!(v), alias v) {
enum isBar = true;
}
pragma(msg, isBar!(Bar!1234)); // prints false
---