Main Content

File does not compile

File has a compilation error

Since R2021a

Description

This defect occurs when Polyspace cannot analyze a file because of compilation errors. The defect is located on the first line and column of the file, and indicates that the file has one or more compilation errors.

To find the actual compilation errors, see the analysis log. For information on how to investigate further in:

Use this checker to find out at a glance whether you have files with compilation issues in an integration analysis (Polyspace Bug Finder or Polyspace Bug Finder Server) or whether the current file being analyzed does not compile yet (Polyspace as You Code). Using this checker saves you from opening the analysis log each time to find out if there are compilation issues. You can determine from your analysis results if a file did not compile.

Risk

Typically, your compiler can also find the issues that this defect checker finds.

If your file compiles with your compiler but the compilation phase of a Polyspace analysis fails, it means that your analysis configuration does not emulate your compiler accurately. For instance, if the analysis fails because a standard library function appears to be undefined, you might have to explicitly specify the folders containing your compiler headers, use the polyspace-configure command to extract the paths, or otherwise improve your configuration.

Fix

Identify all compilation errors from the analysis log and fix them.

Examples

expand all

int nthFib (int n) {
    int i=0, sum=1;
    for (int iter = 0; iter < n; iter++) {
      int t = i;
      i = sum;
      sum += t;
    }
    return iter;
}

In this example, the variable iter is defined only in the for loop. But the return statement outside the loop refers to the variable, causing an undefined identifier error. (The compilation error here also indicates a logical error since the intent was to return the variable sum.)

#include <cstdio>
#include <cstdlib>

void func() {
   char* message = (char*)malloc (strlen ("Hello, World\n")+1);
   strcpy (message, "Hello, World\n");
   printf ("%s", message);
   free (message);
}

In this example, the string functions strlen and strcpy are used but the header file cstring is not included. This leads to the functions appearing as undefined.

Result Information

Group: Good Practice
Language: C | C++
Default: Off in Polyspace Bug Finder, on in Polyspace as You Code
Command-Line Syntax: FILE_DOES_NOT_COMPILE
Impact: Low

Version History

Introduced in R2021a

expand all