jeudi 26 mars 2015

Compiler Warning for Unnecessary Namespaces

I have a lot of code that is functionally like this:



namespace Foo { namespace Bar { namespace Baz {

class MyType {};

Foo::Bar::Baz::MyType func(Foo::Bar::Baz::MyType const& param);

}}}


Since there aren't any conflicting definitions of MyType, this could be easily simplified like so:



namespace Foo { namespace Bar { namespace Baz {

class MyType {};

MyType func(MyType const& param);

}}}


We've saved (an embarrassing amount) of text space by beginning to delete these sorts of occurrences in our large, expansive codebase. However, it's slow going and error-prone, since we're doing it by vgrep.


Ideally, there would be a compiler warning. Our codebase supports three different compilers (MSVC, g++, and Clang) on three different platforms (Windows, Linux, and Mac), mostly respectively.


I couldn't find a warning to enable that would help us, and it's difficult to Google since people make the class A { void A::method(void) {} }; error a lot (and g++ catches this, since it's not standard-compliant). Our problem is overqualification by namespace, not by type.


So, what warning should I enable in (at least) one of the above compilers? Are there other solutions?


Aucun commentaire:

Enregistrer un commentaire