In a previous post we talked about the clang-modernize tool to identify where new C++11 features could be used to modernize your C++ source code. But how can we easily detect where the new C++ features are used in a project?
Facebook and Google use C++11 extensively in their source code. Folly from Facebook, as we discovered in a previous post, uses almost all of the C++11 features, and I was curious to know whether Microsoft also used the new C++11 standard in its open source code.
The Microsoft open source projects can be found in their GitHub repository. Some are forks of other projects that Microsoft has adapted to its needs, like LLVM, Clang and OpenCV, and others are developed by Microsoft. Let’s take a look at one of these projects and see whether it uses C++11. The best choice could be one of their latest open source C/C++ projects: WinObjC.
Windows Bridge for iOS (also referred to as WinObjC) is a Microsoft open source project that provides an Objective-C development environment for Visual Studio/Windows. In addition, WinObjC provides support for iOS API compatibility.
One way to check where C++11 is used is to explore each source file, which could take hours or even days, depending on the size of the project. Another solution is to use Clang.
Clang and its powerful diagnostic engine to the rescue.
The Clang team aims to provide error messages that are as clear and expressive as possible. They try to make it as user-friendly as possible for a command-line compiler. To do this, Clang pinpoints exactly what is wrong in the code. This is done through a diagnostics engine that turns error information into user-friendly messages.
Clang emits many kinds of diagnostics, and for our needs the most interesting ones have descriptions like this: “XXX incompatible with C++98”.
But how can we get the Clang diagnostics for a Visual Studio solution?
The first alternative is to compile your projects using Clang; however, this is not an easy task. Indeed, you have to modify your build process to use Clang instead of the Microsoft compiler.
The second alternative is to analyze your Visual Studio projects using CppDepend, which uses Clang as its front-end parser and reports all its diagnostics. CppDepend is free for the open source community.
Here are all the Clang diagnostics for the WinObjC solution:

But in our case we only need diagnostics of the type “incompatible with C++98”. You can easily filter the previous query to get only these diagnostics:

As we can observe, the nullptr and auto language features are used in many places in the source code, but unlike the Facebook and Google projects, C++11 features are not widely used. Also, when exploring the C++ source files of WinObjC, we can see that C++/CX extensions are used more extensively.
Summary:
Sometimes it is useful to know whether a C++ project uses features from newer standards and where those features are used. Clang is a powerful tool for gathering this information.
