Skip to content

Rs-incform: clarify what a relative path is and offer implementation suggestion #2272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CppCoreGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -19629,10 +19629,21 @@ Failing to follow this results in difficult to diagnose errors due to picking up

Library creators should put their headers in a folder and have clients include those files using the relative path `#include <some_library/common.h>`

##### Project Example

Consider a project with two components where src/component2/foo.cpp is using src/component1/utilities.hpp:

projectRoot/src/component1/utilities.hpp
projectRoot/src/component2/foo.cpp // #include "../component1/utilities.hpp" OR #include "utilities.hpp" with -I../component1

foo.cpp can `#include "../component1/utilities.hpp"` or it can `#include "utilities.hpp"` and provide the compiler with the relative path to component1 (e.g. `g++ -o foo.o -I../component1 foo.cpp`). Using either quoted form, makes it clear that utilities.hpp is part of the project and will remain with the project when it is cloned. Likewise, headers included using angle brackets such as `#include <string>` cannot be modified in the project. If an angle-bracket header is modified, it can impact many projects including those of other users on the system.

##### Enforcement

A test should identify whether headers referenced via `""` could be referenced with `<>`.

Compilers can report the absolute path of file being referenced in a `#include` directive and using this information, the test can verify that all includes of headers within the project root are included using quotes.

### <a name="Rs-portable-header-id"></a>SF.13: Use portable header identifiers in `#include` statements

##### Reason
Expand Down