diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 8b3c2b022..57737f68d 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -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 ` +##### 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 ` 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. + ### SF.13: Use portable header identifiers in `#include` statements ##### Reason