Coverage Report

Created: 2023-09-25 06:15

/src/cppcheck/lib/checkpostfixoperator.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Cppcheck - A tool for static C/C++ code analysis
3
 * Copyright (C) 2007-2023 Cppcheck team.
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
20
//---------------------------------------------------------------------------
21
#ifndef checkpostfixoperatorH
22
#define checkpostfixoperatorH
23
//---------------------------------------------------------------------------
24
25
#include "check.h"
26
#include "config.h"
27
#include "tokenize.h"
28
29
#include <string>
30
31
class ErrorLogger;
32
class Settings;
33
class Token;
34
35
/// @addtogroup Checks
36
/// @{
37
38
/**
39
 * @brief Using postfix operators ++ or -- rather than postfix operator.
40
 */
41
42
class CPPCHECKLIB CheckPostfixOperator : public Check {
43
    friend class TestPostfixOperator;
44
45
public:
46
    /** This constructor is used when registering the CheckPostfixOperator */
47
2
    CheckPostfixOperator() : Check(myName()) {}
48
49
private:
50
    /** This constructor is used when running checks. */
51
    CheckPostfixOperator(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
52
1.36k
        : Check(myName(), tokenizer, settings, errorLogger) {}
53
54
1.36k
    void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
55
1.36k
        if (tokenizer.isC())
56
0
            return;
57
58
1.36k
        CheckPostfixOperator checkPostfixOperator(&tokenizer, tokenizer.getSettings(), errorLogger);
59
1.36k
        checkPostfixOperator.postfixOperator();
60
1.36k
    }
61
62
    /** Check postfix operators */
63
    void postfixOperator();
64
65
    /** Report Error */
66
    void postfixOperatorError(const Token *tok);
67
68
0
    void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
69
0
        CheckPostfixOperator c(nullptr, settings, errorLogger);
70
0
        c.postfixOperatorError(nullptr);
71
0
    }
72
73
1.36k
    static std::string myName() {
74
1.36k
        return "Using postfix operators";
75
1.36k
    }
76
77
0
    std::string classInfo() const override {
78
0
        return "Warn if using postfix operators ++ or -- rather than prefix operator\n";
79
0
    }
80
};
81
/// @}
82
//---------------------------------------------------------------------------
83
#endif // checkpostfixoperatorH