SkillAgentSearch skills...

SaferCPlusPlus

A collection of safe data types that are compatible with, and can substitute for, common unsafe native c++ types

Install / Use

/learn @duneroadrunner/SaferCPlusPlus
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Feb 2025

Overview

"SaferCPlusPlus" is essentially a collection of safe data types intended to facilitate memory and data race safe C++ programming. This library is intended to work with a safety assuring static analyzer like scpptool and, optionally, the Core Guidelines lifetime checker, over their various stages of development and availability. (Including situations where they are not available at all.)

The library's elements are designed, as much as possible, to seamlessly integrate with all manner of existing and future C++ code. It includes things like:

  • Drop-in replacements for std::vector<>, std::array<> and std::string.

  • Replacements for std::string_view and std::span.

  • Drop-in replacements for int, size_t and bool that ensure against the use of uninitialized values and address the "signed-unsigned mismatch" issues.

  • Data types for safe sharing of objects among concurrently executing threads.

  • Replacements for native pointers/references with various flexibility and performance trade-offs.

While a "static safety analyzer/enforcer" like the scpptool would be required to ensure complete safety, the SaferCPlusPlus library elements have a lot of safety enforcement already built in. The library is extensive enough that most existing uses of unsafe C++ elements can be replaced.

Besides zero-overhead pointers that enforce some of the necessary restrictions that would be imposed by a complete "static safety analyzer/enforcer", the library provides a reference counting pointer that's smaller and faster than std::shared_ptr<>, and (non-owning) unrestricted pointers that ensure memory safety via run-time checks. The latter two being not (yet) provided by the Guidelines Support Library, but valuable in the context of having to work around the somewhat draconian restrictions imposed by the (eventual completed) lifetime checker.

To see the library in action, you can check out some benchmark code. There you can compare traditional C++ and (high-performance) SaferCPlusPlus implementations of the same algorithms. Also, the msetl_example.cpp and msetl_example2.cpp files contain usage examples of the library's elements. But at this point, there are a lot of them, so it might be more effective to peruse the documentation first, then search those files for the element(s) you're interested in. (An online interactive version of these examples is also available, but the whole collection is large enough that the build will likely time-out. Often, the documentation for individual library elements will include a link to a more specific interactive example that should build fine.)

Elements in this library are currently based on the C++17 version of their counterpart APIs. (C++14 is still supported.)

Supported platforms

Tested with the microsoft compiler (v.19.50.35718), g++13.3.0 and clang++18.1.3 (Ubuntu 24.04.1). Versions of g++ prior to version 5 are not supported. Apple clang++ is not currently a regular test target. With the microsoft compiler, compiling in "conformance" mode (/permissive-) (which is not the default when using C++17 or lower) is recommended.

Table of contents

  1. Overview

  2. Use cases

  3. Setup and dependencies

  4. Comparisons

    1. SaferCPlusPlus versus Clang/LLVM Sanitizers
    2. SaferCPlusPlus versus Rust
  5. Getting started on safening existing code

  6. <details> <summary>Registered pointers</summary>
    1. Overview
    2. TRegisteredPointer
      1. TRegisteredNotNullPointer
      2. TRegisteredFixedPointer
      3. TRegisteredRefWrapper
    3. TCRegisteredPointer
    4. TNDRegisteredPointer, TNDCRegisteredPointer
    </details>
  7. <details> <summary>Norad pointers</summary>
    1. Overview
    2. TNoradPointer
    </details>
  8. Simple benchmarks

  9. <details> <summary>Reference counting pointers</summary>
    1. Overview
    2. TRefCountingPointer
      1. TRefCountingNotNullPointer
      2. TRefCountingFixedPointer
    3. Using registered pointers as weak pointers
    </details>
  10. <details> <summary>Single owner pointer</summary>
    1. Overview
    2. TSingleOwnerPointer
    </details>
  11. <details> <summary>Scope pointers</summary>
    1. Overview
    2. TXScopeFixedPointer
    3. TXScopeOwnerPointer
    4. make_xscope_strong_pointer_store()
    5. make_xscope_borrowing_strong_pointer_store()
    6. TRegisteredProxyPointer
    7. TNoradProxyPointer
    8. xscope_chosen()
    9. as_a_returnable_fparam()
    10. as_an_fparam()
    11. Conformance helpers
      1. return_value()
      2. TMemberObj
    </details>
  12. make_pointer_to_member_v2()

  13. Poly pointers

    1. TXScopePolyPointer
    2. TPolyPointer
    3. TAnyPointer
  14. pointer_to()

  15. Safely passing parameters by reference

  16. <details> <summary>Multithreading</summary>
    1. Overview
    2. TAsyncPassableObj
    3. thread
    4. async()
    5. Asynchronously shared objects
      1. TAsyncShareableObj
      2. TAsyncShareableAndPassableObj
      3. TAsyncSharedV2ReadWriteAccessRequester
      4. TAsyncSharedV2ReadOnlyAccessRequester
      5. TAsyncSharedV2ImmutableFixedPointer
      6. TAsyncSharedV2AtomicFixedPointer
      7. TAsyncRASectionSplitter
    6. Scope threads
      1. access controlled objects
      2. xscope_thread_carrier
      3. xscope_future_carrier
      4. make_xscope_asyncsharedv2acoreadwrite()
      5. make_xscope_aco_locker_for_sharing()
      6. make_xscope_exclusive_strong_pointer_store_for_sharing()
      7. TXScopeExclusiveStrongPointerStoreForAccessControl
      8. exclusive writer objects
      9. scope atomics
      10. TXScopeACORASectionSplitter and TXScopeAsyncACORASectionSplitter
    7. static and global variables
      1. static immutables
      2. static atomics
      3. static access controlled objects and access requesters
    </details>
  17. Primitives

    1. CInt, CSize_t and CBool
    2. CNDInt, CNDSize_t and CNDBool
    3. Quarantined types
  18. <details> <summary>Arrays</summary>
    1. Overview
    2. mstd::array
    3. nii_array
    4. xscope_nii_array
    5. xscope_iterator
    </details>
  19. <details> <summary>Vectors</summary>
    1. Overview
    2. mstd::vector
    3. nii_vector
    4. fixed_nii_vector
    5. xscope_borrowing_fixed_nii_vector
    6. ivector
    </details>
  20. TRandomAccessSection

  21. <details> <summary>Strings</summary>
    1. Overview
    2. mstd::string
    3. nii_string
    4. xscope_borrowing_fixed_nii_basic_string
    5. TStringSection
    6. [TNRPStringSection](#txscopenrpstringsection-txscopenrpstringconstsection-tnrpstringsect

Related Skills

View on GitHub
GitHub Stars420
CategoryDevelopment
Updated4d ago
Forks21

Languages

C++

Security Score

95/100

Audited on Mar 22, 2026

No findings