Is there any tools for detecting files and lines that is using c++17 features?
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.
For ease to list up, I asked above question!
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!
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
.