parent
8c657872d1
commit
b964551424
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -1143,7 +1144,7 @@ void CheckClass::thisSubtractionError(const Token *tok)
|
||||||
|
|
||||||
void CheckClass::checkConst()
|
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)
|
if (!_settings->inconclusive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1192,15 +1193,19 @@ void CheckClass::checkConst()
|
||||||
|
|
||||||
if (temp->str() != "const")
|
if (temp->str() != "const")
|
||||||
continue;
|
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 {
|
} else {
|
||||||
// don't warn for unknown types..
|
// don't warn for unknown types..
|
||||||
// LPVOID, HDC, etc
|
// LPVOID, HDC, etc
|
||||||
if (previous->isName()) {
|
if (previous->isName()) {
|
||||||
bool allupper = true;
|
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) {
|
for (std::string::size_type pos = 0; pos < s.size(); ++pos) {
|
||||||
const char ch = s[pos];
|
const char ch = s[pos];
|
||||||
if (!(ch == '_' || (ch >= 'A' && ch <= 'Z'))) {
|
if (ch != '_' && !std::isupper(ch)) {
|
||||||
allupper = false;
|
allupper = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,6 +196,7 @@ private:
|
||||||
TEST_CASE(constoperator2); // operator<<
|
TEST_CASE(constoperator2); // operator<<
|
||||||
TEST_CASE(constoperator3);
|
TEST_CASE(constoperator3);
|
||||||
TEST_CASE(constoperator4);
|
TEST_CASE(constoperator4);
|
||||||
|
TEST_CASE(constoperator5); // ticket #3252
|
||||||
TEST_CASE(constincdec); // increment/decrement => non-const
|
TEST_CASE(constincdec); // increment/decrement => non-const
|
||||||
TEST_CASE(constassign1);
|
TEST_CASE(constassign1);
|
||||||
TEST_CASE(constassign2);
|
TEST_CASE(constassign2);
|
||||||
|
@ -4084,6 +4085,30 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void const5() {
|
||||||
// ticket #1482
|
// ticket #1482
|
||||||
checkConst("class A {\n"
|
checkConst("class A {\n"
|
||||||
|
|
Loading…
Reference in New Issue