isocpp / isocpp/CppCoreGuidelines

gsl not_null throw exception

Open
#2,132 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
45.3k
Forks
5.6k
PR merge metrics
No merged PRs in 30d

Description

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-nullptr

Was throwing an exception considered? ie. std::logic_error or std::invalid_argument

Perhaps it is left implementation defined, as I can't spot a specific behavior described.

Presently GSL calls std::terminate(), quite a strong response. gsl-lite is the same.

An exception gives the application a chance to handle it (even if that was just gracefully logging). The user wouldn't be impacted by a std::terminate core dump SEGV; which is a bad outcome in a safety critical environment. Even worse in a library, we can't link to anything that might call std::terminate() like this in a safety critical environment; would be an uncontrolled program termination event.

Here is a one file example based on https://github.com/gsl-lite/gsl-lite

https://godbolt.org/z/Wdea6G9EW

This isn't production code, just an example.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the CppCoreGuidelines Rf-nullptr section and the linked Godbolt example, then compare the reported behavior with GSL and gsl-lite. Decide whether not_null exception behavior should be specified, and record the resulting contract; the issue names no repository files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.