Does gcc (or any other compiler) have an option to warn me global namespace pollutions?
I tried to compile a sample application suite, but it turned out quite a few of header files of that samples are stricken with global namespace pollutions (using namespace
in header files), so that Mac OS X global struct Rect becomes ambiguous.
I also tried to change the order of #include to resolve the system's Rect symbol before the minefield of using namespace
, but that caused some symbols end up not resolved.
My earlier search using Google failed, bad premonition though, if that kind of warning option exists, please give me info.
Technically, namespace pollution is simply leaving your symbols in a namespace where they shouldn't really be. This doesn't necessarily lead to clashes but it makes it more likely. both of those functions are made available to the linker.
Namespace pollution is a lot like pollution in general. It means that something is misplaced. In programming that means that code that should really live in separate namespaces is added to a common namespace (in some cases the global namespace).
I don't know about gcc, but CLang has it:
def warn_using_directive_in_header : Warning<
"using namespace directive in global context in header">,
InGroup<HeaderHygiene>, DefaultIgnore;
You can activate it directly using -Wusing-directive-in-header
or via the group -Wheader-hygiene
(it is, for now, the sole member of the group).
It's been thoroughly reviewed on the mailing list and normally does not warn about regular cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With