C++ C++23

Last reviewed Oct 28, 2026

Export as PDF

Prompt Details

Prompt Composition

1prompt
  1. C++ C++23130 lines · 3.5K tokens

CWE Coverage

  • 14
  • 20
  • 22
  • 59
  • 78
  • 89
  • 116
  • 117
  • 125
  • 129
  • 131
  • 134
  • 190
  • 195
  • 197
  • 208
  • 209
  • 214
  • 252
  • 287
  • 295
  • 321
  • 338
  • 347
  • 362
  • 367
  • 377
  • 415
  • 416
  • 426
  • 427
  • 457
  • 476
  • 494
  • 502
  • 532
  • 674
  • 758
  • 770
  • 772
  • 787
  • 829
  • 833
  • 862
  • 916
  • 918
  • 1240
  • 1395

Prompt Preview

Use these rules for C++23 code that handles untrusted data, owns native resources, or crosses process and network boundaries.

Type and interface safety

  • Express ownership, nullability, bounds, and mutability in types instead of relying on comments or calling convention.
  • Prefer narrow value types, scoped enums, and validated constructors for security-relevant states.
  • Use std::span, ranges, and containers instead of passing an array as a pointer without a bound.
  • Mark single-argument constructors other than copy and move constructors explicit unless implicit conversion is intentionally safe.
  • Keep public interfaces small and reject invalid states before constructing domain objects.

Bounds and object representation

  • Validate indexes, iterator ranges, offsets, counts, and byte sizes before access or allocation.
  • Initialize scalar variables and buffer elements before reading or exposing them; std::make_unique_for_overwrite does not value-initialize the allocated objects.
  • Do not dereference invalidated iterators, dangling views, null pointers, or pointers outside an object's lifetime.
  • Avoid reinterpret_cast, type punning, placement construction, and manual layout unless isolated and reviewed.
  • Use std::bit_cast only between supported representations and still validate any untrusted semantic value.
  • Treat unions, packed structures, flexible wire layouts, and custom allocators as explicit trust boundaries.

Integer and size safety

  • Check signedness, range, and units before converting external values to sizes, indexes, durations, or enum