| 299 | |
| 300 | |
| 301 | static bool isOperatorFunction(const std::string & funcName) |
| 302 | { |
| 303 | /* Operator functions are invalid function names for C, so no need to check |
| 304 | * this in here. As result the returned error function might be incorrect. |
| 305 | * |
| 306 | * List of valid operators can be found at: |
| 307 | * http://en.cppreference.com/w/cpp/language/operators |
| 308 | * |
| 309 | * Conversion functions must be a member function (at least for gcc), so no |
| 310 | * need to cover them for unused functions. |
| 311 | * |
| 312 | * To speed up the comparison, not the whole list of operators is used. |
| 313 | * Instead only the character after the operator prefix is checked to be a |
| 314 | * none alpa numeric value, but the '_', to cover function names like |
| 315 | * "operator_unused". In addition the following valid operators are checked: |
| 316 | * - new |
| 317 | * - new[] |
| 318 | * - delete |
| 319 | * - delete[] |
| 320 | */ |
| 321 | const std::string operatorPrefix = "operator"; |
| 322 | if (funcName.compare(0, operatorPrefix.length(), operatorPrefix) != 0) { |
| 323 | return false; |
| 324 | } |
| 325 | |
| 326 | // Taking care of funcName == "operator", which is no valid operator |
| 327 | if (funcName.length() == operatorPrefix.length()) { |
| 328 | return false; |
| 329 | } |
| 330 | |
| 331 | const char firstOperatorChar = funcName[operatorPrefix.length()]; |
| 332 | if (firstOperatorChar == '_') { |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | if (!std::isalnum(firstOperatorChar)) { |
| 337 | return true; |
| 338 | } |
| 339 | |
| 340 | const std::vector<std::string> additionalOperators = { |
| 341 | "new", "new[]", "delete", "delete[]" |
| 342 | }; |
| 343 | |
| 344 | |
| 345 | return std::find(additionalOperators.cbegin(), additionalOperators.cend(), funcName.substr(operatorPrefix.length())) != additionalOperators.cend(); |
| 346 | } |
| 347 | |
| 348 | void CheckUnusedFunctions::staticFunctionError(ErrorLogger& errorLogger, |
| 349 | const std::string &filename, nonneg int fileIndex, nonneg int lineNumber, nonneg int column, |
no test coverage detected