C & C++

C & C++

Made by DeepSource

Found value copy of non-trivially copyable parameter CXX-P2009

Performance
Major

A parameter is declared to be call-by-value when a const reference will suffice. This parameter type is expensive to copy.

The check is only applied to parameters of types that are expensive to copy which means they are not trivially copyable or have a non-trivial copy constructor or destructor.

Consider using a const reference to the value instead.

Bad practice

void f(const string Value) {
    // consider making Value a reference.
}

void g(ExpensiveToCopy Value) {
    // consider making Value a const reference.
    Value.ConstMethd();
    ExpensiveToCopy Copy(Value);
}

Recommended

void f(const string& Value) {
    // ...
}

void g(const ExpensiveToCopy& Value) {
    // ...
    Value.ConstMethd();
    ExpensiveToCopy Copy(Value);
}