Skip to content

RFC: Introduce NeverNull<T>, port some things to it

Jan Blackquill requested to merge work/janb/de-raw into master

NeverNull helps enforce the invariant of some things never being nullptrs by:

  • encoding that explicitly in the source code
  • ensuring that straight-up '= nullptr' are impossible
  • aborting at assignment site instead of crashing at use site, so that it's easier to figure out where something wrongly became nullptr

It can wrap any type comprable to nullptr, and doesn't add anything to the size of one.

In the long run, I think porting KWin to stuff like this (+ smart pointers + a MaybeNull type) would help w/ overall reliability by relying on better compile time instrumenting to prevent errors from making it to runtime in the first place, and by having runtime abort when the system enters an invalid state instead of crashing some time later when code assumes the state is valid and it isn't and you need to spend time figuring out how the system got to an invalid state in the first place to fix the crash.

Merge request reports