Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 1.28 KB

c26461.md

File metadata and controls

48 lines (36 loc) · 1.28 KB
title ms.date f1_keywords helpviewer_keywords description
Warning C26461
03/22/2018
C26461
USE_CONST_POINTER_ARGUMENTS
C26461
CppCoreCheck rule that enforces C++ Core Guidelines con.3

Warning C26461

The pointer argument 'argument' for function 'function' can be marked as a pointer to const (con.3).

Remarks

A function with a T* argument has the potential to modify the value of the object. If that isn't the intent of the function, it's better to make the pointer a const T* instead.

Code analysis name: USE_CONST_POINTER_ARGUMENTS

Example

struct MyStruct
{
    void MemberFn1() const;
    void MemberFn2();
};

void Function1_Helper(const MyStruct* myStruct);
void Function1(MyStruct* myStruct) // C26461, neither of the operations on myStruct would modify the pointer's value.
{
    if (!myStruct)
        return;

    myStruct->MemberFn1();      // The member function is const
    Function1_Helper(myStruct); // Function1_Helper takes a const
}

void Function2(MyStruct* myStruct)
{
    if (!myStruct)
        return;

    myStruct->MemberFn2(); // The member function is non-const, so no C26461 will be issued
}

See also

C++ Core Guidelines con.3.