Bug 10080 – Attributes lost when passing value to a templated function
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-14T00:34:00Z
Last change time
2013-05-14T00:48:06Z
Assigned to
nobody
Creator
simendsjo
Comments
Comment #0 by simendsjo — 2013-05-14T00:34:37Z
Using dmd 2.062 on GNU/Linux, this prints:
main: tuple(1)
f: tuple()
g: tuple(1)
void f(T)(T o) {
pragma(msg, "f: ", __traits(getAttributes, o));
}
void g(alias T)() {
pragma(msg, "g: ", __traits(getAttributes, T));
}
void main() {
@(1) int i;
pragma(msg, "main: ", __traits(getAttributes, i));
f(i);
g!i;
}
Is this intended behavior?
Comment #1 by k.hara.pg — 2013-05-14T00:48:06Z
(In reply to comment #0)
> Using dmd 2.062 on GNU/Linux, this prints:
> main: tuple(1)
> f: tuple()
> g: tuple(1)
>
> void f(T)(T o) {
> pragma(msg, "f: ", __traits(getAttributes, o));
> }
>
> void g(alias T)() {
> pragma(msg, "g: ", __traits(getAttributes, T));
> }
>
> void main() {
> @(1) int i;
> pragma(msg, "main: ", __traits(getAttributes, i));
> f(i);
> g!i;
> }
>
> Is this intended behavior?
It's intended behavior, because UDA is always associated with symbols.
In template function f, `o` is a function parameter, and it is different symbol from the local variable i in main function.