[cfe-dev] questions on the LLVM coding standards

Zhanyong Wan (λx.x x) wan at google.com
Mon Nov 15 17:25:04 PST 2010


Hi Chris,

While reading the LLVM coding standards
(http://llvm.org/docs/CodingStandards.html), I have some questions:

1. It says "you shouldn't assume much about the host compiler,
including its support for "high tech" features like partial
specialization of templates."  Is this still the case?  I'm a bit
surprised that we need to worry about compilers that don't understand
partial specialization.

2. It advises to #include as little as possible.  In particular,
"Don't do it unless you have to, especially in header files."  And
later it says "you can include them either directly or indirectly
(through another header file)."  I'm worried that this may lead
dependencies on other headers' implementation details.  For example,
if foo.cpp needs b.h, I would think it should #include b.h itself,
instead of relying on some other .h file that happens to include b.h
(unless it's the other .h file's intention to "re-export" b.h).  What
are your thoughts on this?

3. It says "For example, all of the code in the LLVM project
implements code that lives in the 'llvm' namespace. As such, it is ok,
and actually clearer, for the .cpp files to have a 'using namespace
llvm' directive at their top, after the #includes. The general form of
this rule is that any .cpp file that implements code in any namespace
may use that namespace (and its parents'), but should not use any
others."

I don't understand why this is necessary.  Since the .cpp is
implementing code in the llvm namespace, why not enclosing its entire
body in namespace llvm?  In that case, there's no need for 'using
namespace llvm'.

Thanks,
-- 
Zhanyong



More information about the cfe-dev mailing list