Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there any tools for detecting files and lines that is using c++17 features?

Question

Is there any tools for detecting files and lines that is using c++17 features?

Background

I’m developing some software with c++17.
Recentlty a customer requested us to list files and lines that is using c++17 features.
The reason is that they have to applicate deviation permits for using c++17 feature because their internal coding conventions is standarized by c++14.

It may be possible to detect them using a compiler, but the compiler stops every time it detects an error, making it time-consuming to detect all errors.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

For ease to list up, I asked above question!

What we tried

I tried to use cpplint/clang-format.
But these tools didn’t detect c++17 feature despite c++14 option. The code I tested is below.

#include <iostream>

// C++17 feature
namespace aaa::bbb::ccc
{
  void f()
  { std::cout << "a new nested namespace definition is worked!\n"; }
}

namespace aaa
{
  namespace bbb
  {
    namespace ccc
    {
      void g()
      { std::cout << "a legacy nested namespace definition is workded.\n"; }
    }
  }
}

int main()
{
  aaa::bbb::ccc::f();
  aaa::bbb::ccc::g();
}

 

Thank you!

>Solution :

If you compile with Clang, the -Wpre-c++17-compat diagnostic flag warns about the case from your example:

<source>:4:14: warning: nested namespace definition is incompatible with C++ standards before C++17 [-Wpre-c++17-compat]
namespace aaa::bbb::ccc
             ^
1 warning generated.

It will also warn on if/switch initialization statements, pack fold expressions, decomposition declarations and a bunch of other common C++17 features that aren’t in earlier versions.

The full list of cases is included in the reference of all diagnostic flags, here:

https://clang.llvm.org/docs/DiagnosticsReference.html#wpre-c-17-compat

By default, Clang will warn, then carry on compiling. If your build uses -Werror, you may want to disable that for this warning with -Wno-error=pre-c++17-compat.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading