Edit

Share via


C++ Core Guidelines checker reference

This section lists C++ Core Guidelines Checker warnings. For information about Code Analysis, see /analyze (Code Analysis) and Quick Start: Code Analysis for C/C++.

Note

Some warnings belong to more than one group, and not all warnings have a complete reference topic.

OWNER_POINTER Group

C26402 DONT_HEAP_ALLOCATE_MOVABLE_RESULT
Return a scoped object instead of a heap-allocated if it has a move constructor. See C++ Core Guidelines R.3.

C26403 RESET_OR_DELETE_OWNER
Reset or explicitly delete an owner<T> pointer 'variable'. See C++ Core Guidelines R.3.

C26404 DONT_DELETE_INVALID
Do not delete an owner<T> that may be in invalid state. See C++ Core Guidelines R.3.

C26405 DONT_ASSIGN_TO_VALID
Do not assign to an owner<T> that may be in valid state. See C++ Core Guidelines R.3.

C26406 DONT_ASSIGN_RAW_TO_OWNER
Do not assign a raw pointer to an owner<T>. See C++ Core Guidelines R.3.

C26407 DONT_HEAP_ALLOCATE_UNNECESSARILY
Prefer scoped objects, don't heap-allocate unnecessarily. See C++ Core Guidelines R.5.

C26429 USE_NOTNULL
Symbol 'symbol' is never tested for nullness, it can be marked as not_null. See C++ Core Guidelines F.23.

C26430 TEST_ON_ALL_PATHS
Symbol 'symbol' is not tested for nullness on all paths. See C++ Core Guidelines F.23.

C26431 DONT_TEST_NOTNULL
The type of expression 'expr' is already gsl::not_null. Do not test it for nullness. See C++ Core Guidelines F.23.

RAW_POINTER Group

C26400 NO_RAW_POINTER_ASSIGNMENT
Do not assign the result of an allocation or a function call with an owner<T> return value to a raw pointer; use owner<T> instead. See C++ Core Guidelines I.11.

C26401 DONT_DELETE_NON_OWNER
Do not delete a raw pointer that is not an owner<T>. See C++ Core Guidelines I.11.

C26402 DONT_HEAP_ALLOCATE_MOVABLE_RESULT
Return a scoped object instead of a heap-allocated if it has a move constructor. See C++ Core Guidelines R.3.

C26408 NO_MALLOC_FREE
Avoid malloc() and free(), prefer the nothrow version of new with delete. See C++ Core Guidelines R.10.

C26409 NO_NEW_DELETE
Avoid calling new and delete explicitly, use std::make_unique<T> instead. See C++ Core Guidelines R.11.

C26429 USE_NOTNULL
Symbol 'symbol' is never tested for nullness, it can be marked as not_null. See C++ Core Guidelines F.23.

C26430 TEST_ON_ALL_PATHS
Symbol 'symbol' is not tested for nullness on all paths. See C++ Core Guidelines F.23.

C26431 DONT_TEST_NOTNULL
The type of expression 'expr' is already gsl::not_null. Do not test it for nullness. See C++ Core Guidelines F.23.

C26481 NO_POINTER_ARITHMETIC
Don't use pointer arithmetic. Use span instead. See C++ Core Guidelines Bounds.1.

C26485 NO_ARRAY_TO_POINTER_DECAY
Expression 'expr': No array to pointer decay. See C++ Core Guidelines Bounds.3.

UNIQUE_POINTER Group

C26410 NO_REF_TO_CONST_UNIQUE_PTR
The parameter 'parameter' is a reference to const unique pointer, use const T* or const T& instead. See C++ Core Guidelines R.32.

C26411 NO_REF_TO_UNIQUE_PTR
The parameter 'parameter' is a reference to unique pointer and it is never reassigned or reset, use T* or T& instead. See C++ Core Guidelines R.33.

C26414 RESET_LOCAL_SMART_PTR
Move, copy, reassign, or reset a local smart pointer 'symbol'. See C++ Core Guidelines R.5.

C26415 SMART_PTR_NOT_NEEDED
Smart pointer parameter 'symbol' is used only to access contained pointer. Use T* or T& instead. See C++ Core Guidelines R.30.

SHARED_POINTER Group

C26414 RESET_LOCAL_SMART_PTR
Move, copy, reassign, or reset a local smart pointer 'symbol'. See C++ Core Guidelines R.5.

C26415 SMART_PTR_NOT_NEEDED
Smart pointer parameter 'symbol' is used only to access contained pointer. Use T* or T& instead. See C++ Core Guidelines R.30.

C26416 NO_RVALUE_REF_SHARED_PTR
Shared pointer parameter 'symbol' is passed by rvalue reference. Pass by value instead. See C++ Core Guidelines R.34.

C26417 NO_LVALUE_REF_SHARED_PTR
Shared pointer parameter 'symbol' is passed by reference and not reset or reassigned. Use T* or T& instead. See C++ Core Guidelines R.35.

C26418 NO_VALUE_OR_CONST_REF_SHARED_PTR
Shared pointer parameter 'symbol' is not copied or moved. Use T* or T& instead. See C++ Core Guidelines R.36.

DECLARATION Group

C26426 NO_GLOBAL_INIT_CALLS
Global initializer calls a non-constexpr function 'symbol'. See C++ Core Guidelines I.22.

C26427 NO_GLOBAL_INIT_EXTERNS
Global initializer accesses extern object 'symbol'. See C++ Core Guidelines I.22.

C26444 NO_UNNAMED_RAII_OBJECTS
Avoid unnamed objects with custom construction and destruction. See ES.84: Don't (try to) declare a local variable with no name.

CLASS Group

C26432 DEFINE_OR_DELETE_SPECIAL_OPS
If you define or delete any default operation in the type 'symbol', define or delete them all. See C++ Core Guidelines C.21.

C26433 OVERRIDE_EXPLICITLY
Function 'symbol' should be marked with 'override'. See C.128: Virtual functions should specify exactly one of virtual, override, or final.

C26434 DONT_HIDE_METHODS
Function 'symbol_1' hides a non-virtual function 'symbol_2'. See C++ Core Guidelines C.128.

C26435 SINGLE_VIRTUAL_SPECIFICATION
Function 'symbol' should specify exactly one of 'virtual', 'override', or 'final'. See C.128: Virtual functions should specify exactly one of virtual, override, or final.

C26436 NEED_VIRTUAL_DTOR
The type 'symbol' with a virtual function needs either public virtual or protected non-virtual destructor. See C++ Core Guidelines C.35.

C26443 NO_EXPLICIT_DTOR_OVERRIDE
Overriding destructor should not use explicit 'override' or 'virtual' specifiers. See C.128: Virtual functions should specify exactly one of virtual, override, or final.

STYLE Group

C26438 NO_GOTO
Avoid goto. See C++ Core Guidelines ES.76.

FUNCTION Group

C26439 SPECIAL_NOEXCEPT
This kind of function may not throw. Declare it noexcept. See C++ Core Guidelines F.6.

C26440 DECLARE_NOEXCEPT
Function 'symbol' can be declared noexcept. See C++ Core Guidelines F.6.

C26447 DONT_THROW_IN_NOEXCEPT
The function is declared noexcept but calls a function which may throw exceptions. See C++ Core Guidelines: F.6: If your function may not throw, declare it noexcept.

CONCURRENCY Group

C26441 NO_UNNAMED_GUARDS
Guard objects must be named. See C++ Core Guidelines cp.44.

CONST Group

C26460 USE_CONST_REFERENCE_ARGUMENTS
The reference argument 'argument' for function 'function' can be marked as const. See C++ Core Guidelines con.3.

C26461 USE_CONST_POINTER_ARGUMENTS:
The pointer argument 'argument' for function 'function' can be marked as a pointer to const. See C++ Core Guidelines con.3.

C26462 USE_CONST_POINTER_FOR_VARIABLE
The value pointed to by 'variable' is assigned only once, mark it as a pointer to const. See C++ Core Guidelines con.4.

C26463 USE_CONST_FOR_ELEMENTS
The elements of array 'array' are assigned only once, mark elements const. See C++ Core Guidelines con.4.

C26464 USE_CONST_POINTER_FOR_ELEMENTS
The values pointed to by elements of array 'array' are assigned only once, mark elements as pointer to const. See C++ Core Guidelines con.4.

C26496 USE_CONST_FOR_VARIABLE
The variable 'variable' is assigned only once, mark it as const. See C++ Core Guidelines con.4.

C26497 USE_CONSTEXPR_FOR_FUNCTION
This function function could be marked constexpr if compile-time evaluation is desired. See C++ Core Guidelines F.4.

C26498 USE_CONSTEXPR_FOR_FUNCTIONCALL
This function call function can use constexpr if compile-time evaluation is desired. See C++ Core Guidelines con.5.

TYPE Group

C26437 DONT_SLICE
Do not slice. See C++ Core Guidelines ES.63.

C26465 NO_CONST_CAST_UNNECESSARY
Don't use const_cast to cast away const. const_cast is not required; constness or volatility is not being removed by this conversion. See C++ Core Guidelines Type.3.

C26466 NO_STATIC_DOWNCAST_POLYMORPHIC
Don't use static_cast downcasts. A cast from a polymorphic type should use dynamic_cast. See C++ Core Guidelines Type.2.

C26471 NO_REINTERPRET_CAST_FROM_VOID_PTR
Don't use reinterpret_cast. A cast from void* can use static_cast. See C++ Core Guidelines Type.1.

C26472 NO_CASTS_FOR_ARITHMETIC_CONVERSION
Don't use a static_cast for arithmetic conversions. Use brace initialization, gsl::narrow_cast, or gsl::narrow. See C++ Core Guidelines Type.1.

C26473 NO_IDENTITY_CAST
Don't cast between pointer types where the source type and the target type are the same. See C++ Core Guidelines Type.1.

C26474 NO_IMPLICIT_CAST
Don't cast between pointer types when the conversion could be implicit. See C++ Core Guidelines Type.1.

C26475 NO_FUNCTION_STYLE_CASTS
Do not use function style C-casts. See C++ Core Guidelines ES.49.

C26490 NO_REINTERPRET_CAST
Don't use reinterpret_cast. See C++ Core Guidelines Type.1.

C26491 NO_STATIC_DOWNCAST
Don't use static_cast downcasts. See C++ Core Guidelines Type.2.

C26492 NO_CONST_CAST
Don't use const_cast to cast away const. See C++ Core Guidelines Type.3.

C26493 NO_CSTYLE_CAST
Don't use C-style casts. See C++ Core Guidelines Type.4.

C26494 VAR_USE_BEFORE_INIT
Variable 'variable' is uninitialized. Always initialize an object. See C++ Core Guidelines Type.5.

C26495 MEMBER_UNINIT
Variable 'variable' is uninitialized. Always initialize a member variable. See C++ Core Guidelines Type.6.

BOUNDS Group

C26446 USE_GSL_AT
Prefer to use gsl::at() instead of unchecked subscript operator. See C++ Core Guidelines: Bounds.4: Don't use standard-library functions and types that are not bounds-checked.

C26481 NO_POINTER_ARITHMETIC
Don't use pointer arithmetic. Use span instead. See C++ Core Guidelines Bounds.1

C26482 NO_DYNAMIC_ARRAY_INDEXING
Only index into arrays using constant expressions. See C++ Core Guidelines Bounds.2

C26483 STATIC_INDEX_OUT_OF_RANGE
Value value is outside the bounds (0, bound) of variable 'variable'. Only index into arrays using constant expressions that are within bounds of the array. See C++ Core Guidelines Bounds.2

C26485 NO_ARRAY_TO_POINTER_DECAY
Expression 'expr': No array to pointer decay. See C++ Core Guidelines Bounds.3

GSL Group

C26445 NO_SPAN_REF
A reference to gsl::span or std::string_view may be an indication of a lifetime issue. See C++ Core Guidelines GSL.view: Views

C26446 USE_GSL_AT
Prefer to use gsl::at() instead of unchecked subscript operator. See C++ Core Guidelines: Bounds.4: Don't use standard-library functions and types that are not bounds-checked.

C26448 USE_GSL_FINALLY
Consider using gsl::finally if final action is intended. See C++ Core Guidelines: GSL.util: Utilities.

C26449 NO_SPAN_FROM_TEMPORARY
gsl::span or std::string_view created from a temporary will be invalid when the temporary is invalidated. See C++ Core Guidelines: GSL.view: Views.

Deprecated Warnings

The following warnings are present in an early experimental rule set of the core guidelines checker, but are now deprecated and can be safely ignored. The warnings are superseded by warnings from the list above.

  • 26412 DEREF_INVALID_POINTER
  • 26413 DEREF_NULLPTR
  • 26420 ASSIGN_NONOWNER_TO_EXPLICIT_OWNER
  • 26421 ASSIGN_VALID_OWNER
  • 26422 VALID_OWNER_LEAVING_SCOPE
  • 26423 ALLOCATION_NOT_ASSIGNED_TO_OWNER
  • 26424 VALID_ALLOCATION_LEAVING_SCOPE
  • 26425 ASSIGNING_TO_STATIC
  • 26499 NO_LIFETIME_TRACKING

See also

Using the C++ Core Guidelines Checkers