[Issue 8850] Nested struct creation by a template

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 7 04:50:05 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8850



--- Comment #4 from Kenji Hara <k.hara.pg at gmail.com> 2012-11-07 04:50:03 PST ---
(In reply to comment #0)
> T fun(T)() if(is(T == struct)) {
>     T s;    // [a]
>     return s;
> }
> void main() {
>     struct R {
>         void f() { }
>     }
>     auto m = fun!R();
> }

In this case, R in main is a nested struct, and fun!T cannot access main's
frame pointer to construct R at the point [a], then the code correctly fail to
compile.
This behavior is introduced by fixing bug 8339, so it is intended behavior.

> However removing the function from the struct definition (include other values
if desired) then it will compile. I'd think we'd want templates to have the
ability to create a nested struct.

If you remove member function f() from R, R is implicitly treated as static,
because no code would access to the frame of main. Then, the need to access
frame of main from fun!R is eliminated, and the compilation will succeed.

-- 
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