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

Coexistence of GSL implementations #1519

Open
mbeutel opened this issue Sep 19, 2019 · 1 comment
Open

Coexistence of GSL implementations #1519

mbeutel opened this issue Sep 19, 2019 · 1 comment
Assignees

Comments

@mbeutel
Copy link

mbeutel commented Sep 19, 2019

The Core Guidelines make clear that Microsoft's GSL is but one implementation of the GSL:

FAQ.51: Is github.com/Microsoft/GSL the GSL?

No. That is just a first implementation contributed by Microsoft. Other implementations by other vendors are encouraged, as are forks of and contributions to that implementation. As of this writing one week into the public project, at least one GPLv3 open-source implementation already exists. We plan to produce a WG21-style interface specification to ensure that different implementations agree.

Existing implementations of the GSL do diverge in some details which are underspecified or seem questionable, so a precise interface specification would help. However, this doesn't address the question how different GSL implementations can coexist. This becomes a problem when using the GSL in library code; my function may accept a parameter of type gsl::span<>, but what if I use a different GSL than my caller?

I'd appreciate if the Core Guidelines editors could take up a stance on this. E.g.:

  • Different GSL implementations cannot be expected to coexist. This would raise the follow-up question if the GSL should be used at all in libraries.
  • The GSL is header-only, so we're fine if every translation unit uses only one of the implementations. This could still lead to link-time issues because there can be two distinct types called gsl::span<> in the same target.
  • Every GSL implementation should use a dedicated namespace (e.g. ms_gsl, gsl_lite) and corresponding macro prefixes (ms_gsl_Expects(), gsl_lite_Expects()); it could still offer a convenience header which says namespace gsl = ms_gsl and which would be incompatible with the convenience header of competing implementations, but at least we get no link-time ambiguity.
@mbeutel
Copy link
Author

mbeutel commented Mar 29, 2021

Somewhat related issue: right now CppCoreCheck seem to hard-code some GSL type names such as gsl::span<>, gsl::not_null<>, gsl::owner<> (cf. gsl-lite/gsl-lite#240). If GSL implementations were encouraged to use their own namespace (e.g. namespace gsl_lite), the static analysis checks would no longer work. Instead of hard-coding them, perhaps the Core Guidelines should specify an attribute annotation such as [[gsl::span_type]], [[gsl::not_null_type]], [[gsl::owner_alias]] with which the corresponding types could be tagged?

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