Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ and coverity issues

MyClass* const Func(const std::string& statename)

for this coverity is giving the error

Parse warning (PW.USELESS_TYPE_QUALIFIER_ON_RETURN_TYPE) type qualifier on return type is meaningless .

Do we really need to remove the const here.?

like image 324
Sudhakar Avatar asked Dec 10 '22 03:12

Sudhakar


1 Answers

The warning is correct. The MyClass* const is not needed. It should be MyClass* simply. However, you don't need to remove it, but you should remove it.

The reason is, theoretically MyClass* const would prevent the return value of Func() from being edited. But that is anyway not editable even without const, as it's not an lvalue.See the demo here. So with/without const, the compiler will always generate error, for an attempt to modify the return value of Func().

like image 87
iammilind Avatar answered Dec 25 '22 23:12

iammilind