Hacker News new | ask | show | jobs
by kevingadd 3879 days ago
The comment about C++ templates is baffling and I wish the author would elaborate. The behavior he describes that clang doesn't support is... how templates are specified to work. They're near-useless without that property.

Most of these had to do with templates that expected the code inside them not to be compiled until they were instantiated. The Microsoft compiler has that behavior, while clang does not.

2 comments

He's talking about two-phase name lookup, which VS doesn't implement (yet?), but clang does (as it should, striving to be a standard-compliant compiler). Here's a nice article about it: http://blog.llvm.org/2009/12/dreaded-two-phase-name-lookup.h...

TL;DR: If a type, variable... depends on template parameters, code using it is checked when the template is instantiated with concrete template arguments. Otherwise it is checked when the template is defined.

I don't quite understand why you call templates near-useless, if two-phase name lookup didn't exist?

Microsoft's C++ compiler treats templates more like macros: http://blogs.msdn.com/b/vcblog/archive/2015/09/25/rejuvenati...