3 ms·
I found years ago that (at least with older versions) VC++ implemented templates essentially as internally generated macros. All the non-standard behaviour they
by TwoBit 8y ago
I found years ago that (at least with older versions) VC++ implemented templates essentially as internally generated macros. All the non-standard behaviour they had could be explainined by considering how they would act if they were macros. This bug strikes me as being consistent with that. T is leaking across structs because it is internally #defined and seen by another struct.
I think Microsoft has managed to prop up this massive template-as-macro hack all the way through VS 2017.
- ksherlock 8y agoI think as of 15.7, mentioned in TFA and released earlier this month, they do templates properly.
- TwoBit 8y agoI just found this statement from Microsoft: https://blogs.msdn.microsoft.com/vcblog/2017/09/11/two-phase-name-lookup-support-comes-to-msvc/ https://blogs.msdn.microsoft.com/vcblog/2017/09/11/two-phase... "MSVC previously recorded the body of the template as a stream of tokens and stored that stream away to be replayed at instantiation time. The behavior of MSVC’s template substitution from a recorded token stream somewhat resembled the behavior of macro substitution in that limited analysis was done of a template’s body."
- userbinator 8y agoAs someone who is admittedly not an expert in template metaprogramming by any means, thinking of templates as an extension of macros feels like the intuitive and simpler way compared to the more complex two-phase algorithm, so it's no surprise that MSVC did it too... then again, I prefer simpler languages (like C) and see the difficulty of implementing the standard as a sign that its complexity may be too high.
- TwoBit 8y agoThere's a reason why templates work like this. If they didn't work like this then template specializations that you write can break somebody else's code which is dependent on the template behaving a certain way.