V1049. The 'foo' include guard is already defined in the 'bar1.h' header. The 'bar2.h' header will be excluded from compilation.
The analyzer has found that the same include guard is declared in different header files included into one translation unit. As a result, the contents of only one file – the one included first – will be added to the resulting file.
This diagnostic rule applies to projects written in C.
The following example uses a header file called header1.h:
// header1.h
#ifndef _HEADER_H_
#define _HEADER_H_
....
#endif
And a header file called header2.h:
// header2.h
#ifndef _HEADER_H_
#define _HEADER_H_ // <=
....
#endif
The second header file was created by copying the contents of the first one, with the name of the '_HEADER_H_' macro left unchanged.
As a consequence, when compiling the following snippet, the code from header2.h will not be included into the resulting file:
....
#include "header1.h"
#include "header2.h"
...
This might not seem a problem because you would normally expect compilation errors to occur. In reality, however, the file can still compile without errors.
The C language allows you to call functions without declaring them. It is implied that the arguments and the return value of such functions are of type 'int'. If the header file containing function declarations was not included at compilation, the project may still build successfully, but the program will not be working correctly when executed. One such example is described in the article "A nice 64-bit error in C".
To avoid the bug, the include guards used in header files must have unique names.
Also see a related diagnostic: V1031. Function is not declared. The passing of data to or from this function may be affected.