Hi,
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:
http://llvm-reviews.chandlerc.com/D1648
Files:
test/modularize/Inputs/Empty.h
test/modularize/Inputs/IncludeInExtern.h
test/modularize/Inputs/IncludeInNamespace.h
test/modularize/ProblemsExternC.modularize
test/modularize/ProblemsNamespace.modularize
modularize/PreprocessorTracker.cpp
modularize/PreprocessorTracker.h
modularize/Modularize.cpp
Thanks.
-John
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits