Improve your C++ skills by exploring the Clang test suite.

Many resources exist talking about the better way to learn a programming language, we can enumerate:

  • Reading a book or a magazine.
  • Resources from web sites.
  • From a collegue.
  • Doing a training.
  • Explore open source projects.

However it’s difficult to find resources that explains easily the  advanced C++ techniques using mini samples and if you are interested to improve your C++ skills, it’s recommended to explore the standards which is a very difficult task, few developers could read a big pdf with more than 1500 pages.

Another alternative way is to study some mini samples delivered with the compiler source code. Indeed some  open source C++ compilers implement the standrads like GCC and Clang . The good news is that Clang provides a battery of tests to validate the conformance of the compiler with the standards. These samples are well implemented, easy to understand and well commented, they cover many C++ features.

You can explore these mini samples to understand better some C++ capabilities. Many test cases are available here $LLVMPATH$\tools\clang\test, they concern many compiler aspects:

clangtest

And for the C++ syntax you can explore the mini samples from the SemaCXX directory which is contains many interesting test cases that cover almost all the C++ features, even the C++11/C++14 ones.

clangtest2

Let’s take as example the C style casts from the cstyle-cast.cpp file:

clangtest3

This test is very well commented and explain all the possible casting cases, a developer could learn many interesting cases when exploring it.

Summary:

Exploring the Clang test suite could help any C++ developer to improve its programming skills, even the C++ experts could learn new things when exploring these mini samples.