parent
8c657872d1
commit
b964551424
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -1143,7 +1144,7 @@ void CheckClass::thisSubtractionError(const Token *tok)
|
|||
|
||||
void CheckClass::checkConst()
|
||||
{
|
||||
// This is an inconclusive check. False positives: #3252, #3322, #3360.
|
||||
// This is an inconclusive check. False positives: #2340, #3322, #3360.
|
||||
if (!_settings->inconclusive)
|
||||
return;
|
||||
|
||||
|
@ -1192,15 +1193,19 @@ void CheckClass::checkConst()
|
|||
|
||||
if (temp->str() != "const")
|
||||
continue;
|
||||
} else if (func->isOperator && Token::Match(func->tokenDef->previous(), ";|{|}|public:|private:|protected:")) { // Operator without return type: conversion operator
|
||||
const std::string& name = func->token->str();
|
||||
if (name.compare(8, 5, "const") != 0 && name[name.size()-1] == '&')
|
||||
continue;
|
||||
} else {
|
||||
// don't warn for unknown types..
|
||||
// LPVOID, HDC, etc
|
||||
if (previous->isName()) {
|
||||
bool allupper = true;
|
||||
const std::string s(previous->str());
|
||||
const std::string& s(previous->str());
|
||||
for (std::string::size_type pos = 0; pos < s.size(); ++pos) {
|
||||
const char ch = s[pos];
|
||||
if (!(ch == '_' || (ch >= 'A' && ch <= 'Z'))) {
|
||||
if (ch != '_' && !std::isupper(ch)) {
|
||||
allupper = false;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -196,6 +196,7 @@ private:
|
|||
TEST_CASE(constoperator2); // operator<<
|
||||
TEST_CASE(constoperator3);
|
||||
TEST_CASE(constoperator4);
|
||||
TEST_CASE(constoperator5); // ticket #3252
|
||||
TEST_CASE(constincdec); // increment/decrement => non-const
|
||||
TEST_CASE(constassign1);
|
||||
TEST_CASE(constassign2);
|
||||
|
@ -4084,6 +4085,30 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void constoperator5() { // ticket #3252
|
||||
checkConst("class A {\n"
|
||||
" int c;\n"
|
||||
"public:\n"
|
||||
" operator int& () {return c}\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkConst("class A {\n"
|
||||
" int c;\n"
|
||||
"public:\n"
|
||||
" operator const int& () {return c}\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (style) Technically the member function 'A::operatorconstint&' can be const.\n", errout.str());
|
||||
|
||||
checkConst("class A {\n"
|
||||
" int c;\n"
|
||||
"public:\n"
|
||||
" operator int () {return c}\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (style) Technically the member function 'A::operatorint' can be const.\n", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void const5() {
|
||||
// ticket #1482
|
||||
checkConst("class A {\n"
|
||||
|
|
Loading…
Reference in New Issue