Miscellaneous-FileUsageInconsistencyΒΆ

Do not use a file as primary file and included file

Required inputs: IR

A compilation unit's primary file should not be used as an #include target elsewhere. And a file included with the user-include syntax ("") should not be included with the system-include syntax (<>) elsewhere. Use "" to include user headers, and <> to include system headers.
Bad code (primary file used in include directive):
// file: foo.c
void foo() {}

// file: main.c
#include "foo.c" // ERROR: primary file is used in include directive

int main() {
    foo();
}
Bad code (mixed use of user and system includes):
// file: foo.h
void foo();

// file: foo.c
#include "foo.h" // ERROR: file is included here as user include

// file: main.c
#include <foo.h> // ERROR: file is included here as system include
Good code:
// file: foo.h
void foo();

// file: foo.c
#include "foo.h" // OK: file is always included as user include
void foo() {}

// file: main.c
#include "foo.h" // OK: file is always included as user include

Possible Messages

Key

Text

Severity

Disabled

primary_file_system_include

Primary file also treated as system include.

None

False

primary_file_user_include

Primary file also treated as user include.

None

False

user_system_include_mismatch

File is used both as user include and system include.

None

False

Options