Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 1.18 KB

c26460.md

File metadata and controls

42 lines (32 loc) · 1.18 KB
title ms.date f1_keywords helpviewer_keywords description
Warning C26460
03/22/2018
C26460
USE_CONST_REFERENCE_ARGUMENTS
C26460
CppCoreCheck rule that enforces C++ Core Guidelines Con.3

Warning C26460

The reference argument 'argument' for function 'function' can be marked as const (con.3).

Remarks

Passing an object by reference indicates that the function has the potential modify the object. If that isn't the intent of the function, it's better to mark the argument as a const reference.

Code analysis name: USE_CONST_REFERENCE_ARGUMENTS

Example

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

void Function1_Helper(const MyStruct&);
void Function1(MyStruct& myStruct) // C26460, see comments below.
{
    myStruct.MemberFn1();       // The member function is marked as const
    Function1_Helper(myStruct); // Function1_Helper takes a const reference
}

void Function2(MyStruct& myStruct)
{
    myStruct.MemberFn2(); // MemberFn2 is non-const and has the potential to modify data
}

See also

C++ Core Guidelines con.3.