Skip to content

Commit 933bee2

Browse files
author
John Ciolfi
committed
Rs-incform: clarify what a relative path is and offer implementation suggestion
- Add and example clarifying that #include "utilities.hpp" or #include "../module1/utilities.hpp" can resolve to same file and are both relative. - With this clarification, enforcement becomes very easy because compilers can report the absolute path of the file being reference.
1 parent 177b50e commit 933bee2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: CppCoreGuidelines.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -19629,9 +19629,18 @@ Failing to follow this results in difficult to diagnose errors due to picking up
1962919629

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

19632+
##### Project Example
19633+
19634+
Consider a project with modules where src/module2/foo.cpp is using src/module1/utilities.hpp:
19635+
19636+
projectRoot/src/module1/utilities.hpp
19637+
projectRoot/src/module2/foo.cpp // #include "../module1/utilities.hpp" OR #include "utilities.hpp" with -I../module1
19638+
19639+
foo.cpp can `#include "../module1/utilities.hpp"` or it can `#include "utilities.hpp"` and provide the compiler with the relative path to module1 (e.g. `g++ -o foo.o -I../module1 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.
19640+
1963219641
##### Enforcement
1963319642

19634-
A test should identify whether headers referenced via `""` could be referenced with `<>`.
19643+
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.
1963519644

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

0 commit comments

Comments
 (0)