Skip to content

Add a warning for using the same include guard in 2 different files #29221

@llvmbot

Description

@llvmbot
Bugzilla Link 28851
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor
CC @seanm

Extended Description

Imagine the following scenario:

// foo.cpp
#include "foo.h"

// foo.h
#ifndef FOO_H
#define FOO_H

#include "bar.h"

#endif

// bar.h
#ifndef FOO_H
#define FOO_H

#endif

This happens occasionally as a result of copy-pasting one header file to another header file to get the basic layout (header file premable, include guards, namespace layout, etc) in place and then fixing up. But occasionally one forgets to fix the header guard, leading to mysterious compiler errors.

It would be nice if this warned, by keeping for each translation unit a mapping of hashed include guard to include file name, and if an entry is found that exists in the hash table under a different filename, generating a warning.

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillaclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions