Kamen Kitanov - 2026-01-13

This is reproduced on Windows with cppcheck 2.19.0

D:\a.cpp:

#line 1 "D:/sub/a.cpp"
// This includes D:/sub/a instead of D:/a.h.
#include "a.h"

D:\sub\a.h:

#error "This file should not be included"

Output:

Checking a.cpp ...
D:\sub\a.h:1:2: error: #error "This file should not be included" [preprocessorErrorDirective]
#error "This file should not be included"

If you use a relative path for #line instead, it looks like the working directory of cppcheck and the relative path in the line directive will affect the include path for the file.

Expected behaviour: The #line directive should not affect the include path - it should only change the reported file and line for errors and warnings.

 

Last edit: Kamen Kitanov 2026-01-13