Skip to content
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

GSL violates SF.12 #1025

Closed
beinhaerter opened this issue Jan 27, 2022 · 1 comment
Closed

GSL violates SF.12 #1025

beinhaerter opened this issue Jan 27, 2022 · 1 comment

Comments

@beinhaerter
Copy link
Contributor

beinhaerter commented Jan 27, 2022

SF.12: Prefer the quoted form of #include for files relative to the including file and the angle bracket form everywhere else

[...] the guidance is to use the quoted form for including files that exist at a relative path to the file containing the #include statement (from within the same component or project) and to use the angle bracket form everywhere else, where possible. [...]

The GSL includes its own files as #include <gsl/xxx>. It would be better to use #include "xxx" as SF.12 proposes.

If you agree to SF.12, I would be ready to prepare a PR.


The way it currently is, results in problems in our projects. Following is some background.

We have a build environment which handles all projects and the include pathes. For example

Project not under my control:

project1/include/...
project1/src/project1.cpp

Project under my control:

project2/include/project2/project2.h
project2/src/project2.cpp

Project under my control:

project3/include/project3/project3.h
project3/src/project3.cpp

For project3 the build environment (not under my control) uses gcc with -Iproject1/include -Iproject2/include.
project3.cpp uses #include <project2/project2.h>.

In this structure we want to integrate GSL. GSL cannot be a made global project, so I must make it a subfolder in a project under my control (project2). I want to add a new folder project2/include/project2/gsl with all the GSL headers like

project2/include/project2/gsl/narrow
project2/include/project2/gsl/util

The GSL folder is added under project2/include/project2/ and not under project2/include/ so that it cannot collide if for example project1's author decides to add the gsl folder as project1/include/gsl.


In this setup, to use GSL, project2 needs to write #include <project2/gsl/narrow>.

This fails because gsl/narrow does #include <gsl/util> which fails. It would however work if GSL used #include "util" as SF.12 suggests.

The way we currently solve it, is to apply the changes that I ask for, in our local copy of the GSL.

@dmitrykobets-msft
Copy link
Member

Hi @beinhaerter, thanks for the clear explanation of this issue. Your proposal seems good to me, I'd be happy to take a look at your PR.

beinhaerter pushed a commit to beinhaerter/GSL that referenced this issue Jan 31, 2022
[SF.12: Prefer the quoted form of #include for files relative to the including file and the angle bracket form everywhere else](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rs-incform)

Additionally changed #include order in `span` so that all `span_ext` is in the GSL include block and not in the STL include block.

Fixes issues microsoft#1025.
dmitrykobets-msft pushed a commit that referenced this issue Jan 31, 2022
[SF.12: Prefer the quoted form of #include for files relative to the including file and the angle bracket form everywhere else](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rs-incform)

Additionally changed #include order in `span` so that all `span_ext` is in the GSL include block and not in the STL include block.

Fixes issues #1025.

Co-authored-by: Werner Henze <w.henze@avm.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants