CAC++ Library

What is CAC++?

The automatic correction of programming practices facilitates learning and evaluation in subjects where programming skills are taught. The static analysis is a plausible option to this end. This technique analyzes the source code implemented by students to check whether the code satisfies some conditions in each specific practice.

CAC++ is a library implementing a set of verifications for the static analysis of programming practices in C++, mainly related to the object-oriented paradigm. By using this library, the teacher can use the verifications included in it in a simple way, since the library abstracts away implementation details of these verifications. Clang is the underlying compiler that allows analyzing the code and handling low-level details.

The library has been developed with the aim to offer an intuitive but flexible method for its practical use. The teacher can use this library to generate a static analysis program tailored to each practice. Instead of executing all the verifications in each practice, the teacher can set the verifications to apply and personalize in which cases they are applied.

There are different verifications related to (among others):
  • Classes.
  • Methods.
  • Variables.
  • Functions.
  • Construction/destruction.

Any teacher can also add new verifications to the library!

As a teacher, why do I need the CAC++ library?

Sometimes, checking that the students comply with the established conditions in the practice is not possible by simply runnig a set of test cases. Without the aid of technology, the teacher has to manually review the code of all the students to check that their solutions meet those conditions.

Implementing static analysis programs for the practices can help detect when a student is using (or not using) a particular feature of the language. Therefore, CAC++ can save the teacher time and effort. Likewise, CAC++ can provide useful feedback to the student when implementing the practice.

Whether it is convenient to provide the programs to the students to help them complete the practice or use these programs for the evaluation of the practices, we leave it to the teacher to decide!


CAC++ has been developed and tested using:
  • Ubuntu 16.04 / 64 bits.
  • LLVM/Clang compiler 3.9 for 64 bits.
  • Libraries of GCC 5.4.0.


  1. Download LLVM/Clang libraries:
    sudo apt-get install clang-3.9 libclang-3.9-dev

    Since the name of the binary files installed will contain the version, it is recommended that you create a simbolic link to use the binaries without the version as follows:
    sudo ln -s /usr/bin/clang-3.9 /usr/bin/clang
    sudo ln -s /usr/bin/clang++-3.9 /usr/bin/clang++
    sudo ln -s /usr/bin/llvm-config-3.9 /usr/bin/llvm-config
  2. Download the file "cac++.tar" (see section "Downloads" at the end of this page) and unzip the file:
    cd download_directory
    tar xvf cac++.tar
  3. Create the static analysis program associated with the practice using the extracted files, including the header "caclibrary.h" in the main file. It is the moment to add verifications from the library. It's all that the teacher needs to do to create the program.

Example program

The file "example.tar" contains:
  1. The main file "example.cpp", which makes use of CAC++ and runs the verifications.
  2. The file “student.cpp”, which simulates the code implemented by a student.
  3. “Makefile” with the following rules:
    • check: compile and execute the program.
    • clean: clean previous files.

Extract the files and place the folder "Example" in the same directory as the extracted files of the library CAC++. Then execute "make check".

cd Example
make check

The program has been implemented to check that:
  • There is a class with the name Example. To that end, the verification findClass is used.
  • In that case, there is a default constructor defined for that class. To that end, the verification defaultConstructor is used.
  • There is also a method with the name referencedMethod or referredMethod being invoked within the method mainMethod(int). To that end, the verification methodWithReferencedMethod is used.
  • A wildcard can be used (?) to indicate that we do not want that a particular parameter in the verification is taken into account, especially for those cases when the inforamtion is not known or is unimportant. For instance, it is not relevant whether the involved methods are const or not.
  • A regular expression can be used when there are different alternatives for the name of a declaration. For instance, in the case of referencedMethod or referredMethod, we use refer.*edMethod.

The result of the execution should be:

Verifications for the class Example
Reuse is not being carried out as indicated in the practice.
Review the messages related to the class Example.

The third verification is not being met by the current code in "student.cpp" since mainMethod is not calling referencedMethod. Open the file "student.cpp" and replace mainMethod by:

void mainMethod(int p){
          a = referencedMethod() + p;

If you compile and execute again with "make check", the result should be:

Verifications for the class Example

Class Example correct.


Report errors or ask for further information to Pedro Delgado Pérez


CAC++ has been legally registered in the "Registro Territorial de la Propiedad Intelectual de la Junta de Andalucía" with the code: CA-93-17

example.tar - Example of use (6.5 KB) Pedro Delgado Pérez, 10/09/2017 01:57 PM

cac++.tar - CAC++ library (178 KB) Pedro Delgado Pérez, 10/09/2017 01:57 PM