[PATCH] - modularize - going once - #includes within extern "C" {} and namespace blocks

Thompson, John John_Thompson at playstation.sony.com
Tue Sep 17 07:59:13 PDT 2013


I'm having trouble getting a review for this patch, so if you have an interest in modules, perhaps you could take a look and either give some feedback or a thumbs up?

It's a potential problem for modules (and headers in general) if '#include' directives occur inside 'extern "C/C++" {}' or 'namespace (name) {}' blocks, because that can produce different underlying definitions if other sources include the header outside of such blocks.  This patch to modularize checks for these cases, treating them as errors, and produces error message referencing both the offending '#include' and the enclosing 'extern "C/C++" {}' or 'namespace (name) {}' block.

This is something I hit several times in using modularize on a set of some platform standard headers.  I got a whole bunch of errors from modularize, but it took me a while to figure out it was because some headers were including other headers inside extern "C" {} blocks, which of course changes the underlying definitions.  I think there were also some cases where #includes were inside a namespace std {} block (because of the macro wrappers for this, i.e. _STD_BEGIN, it probably wasn't obvious to the developer).  This enhancement points out these potential problems directly.

There are legitimate cases where this will give errors, i.e. such as if you repeatedly include the same header to facilitate groups of similar definitions:

namespace foo {

#define FOO int

#include "usefoo.h"

#undef FOO

#define FOO float

#include "usefoo.h"

#undef FOO


But I think you can just either ignore the errors, or move the namespace inside foo.h.

Here's the Phabricator page for reviewing the changes:













-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130917/2ad86e4c/attachment.html>

More information about the cfe-commits mailing list