Blog 3 min read

C++11/C++14/C++17 Features in WinObjC: A Case Study

Share this article
C++11/C++14/C++17 Features in WinObjC: A Case Study

In a previous post we talked about the clang-tidy tool to detect where you can use some new C++11/C++14/C++17 features 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 make extensive use of C++11 in their source code. Folly from Facebook, as we discovered in a previous post, uses almost all the C++11 features, and I was curious to see whether Microsoft also uses the new C++11 standard in its open-source code.

Microsoft’s open source projects can be found in their GitHub repository; some of them are only forks of other projects adapted to their needs, like LLVM, Clang and OpenCV, and others are developed by them. Let’s take a look at one of these projects and see whether C++11 has been adopted. A good choice is one of Microsoft’s 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 individually, 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 informative as possible. They strive to make them as user-friendly as possible for a command-line compiler. To do so, Clang pinpoints exactly what is wrong in the code. This is done through a diagnostics engine that processes the error information into a user-friendly message.

Clang emits many kinds of diagnostics, and for our needs the most interesting ones have a description like this: “XXX incompatible with C++98″

But how can we get the Clang diagnostics for a Visual Studio solution?

The first option is to compile your projects using Clang; however, it’s not an easy task — indeed, you have to modify your build process to use Clang instead of the Microsoft compiler.

The second option 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.

win1

In our case, however, we only need diagnostics of the type “incompatible with C++98″; you can easily filter the previous query to get only these diagnostics:

win2

As we can see, the nullptr and auto features are used in many places in the source code. However, unlike in Facebook and Google projects, C++11 features are not widely used. When exploring WinObjC’s C++ source files, we can also see that the project makes greater use of C++/CX extensions.

Summary:

The new C++ standards are becoming more widely used these days thanks to the great work of the C++ community. Many of these new features are easy to use, and modernizing your C++ code can make it easier to read and maintain.

Share this article