Clang-tidy check for fixing over-qualification of namespaces in C++ (original) (raw)

September 18, 2024, 7:52pm 1

Looking for a specific thing that I believe clang-tidy can be successful at - fixing namespace over-qualifications in C++.

Consider this code:

namespace foo::bar {

class ::foo::bar::Baz {
 public:
  void do(bar::Baz arg);
};

}

This is all correct and valid C++, but it includes a good amount of namespace over-qualifications, whilst in this specific case they are completely not necessary.

The “fixed” version of this would be:

namespace foo::bar {

class Baz {
 public:
  void do(Baz arg);
};

}

What I am looking for is:

Reminds me of the clang warning -Wextra-qualification.

I wonder if this would even need to be in a clang-tidy check, or if clang itself should just gain this functionality

nlutsenko September 19, 2024, 3:18pm 3

Good pointer, thank you!

That’s right. extra-qualification though (seemingly, based on quick code search and read) only takes care of member function declarations, whilst what I am talking about here is all types and function use.