Skip to content

Commit 48a34f7

Browse files
matthiaskrgrdanmar
authored andcommitted
fix some cppcheck and compiler warnings (#93)
* fix cppcheck findings: [simplecpp.h:182] -> [simplecpp.cpp:226]: (style, inconclusive) Function 'push_back' argument 1 names different: declaration 'token' definition 'tok'. [simplecpp.h:249] -> [simplecpp.cpp:872]: (style, inconclusive) Function 'constFoldQuestionOp' argument 1 names different: declaration 'tok' definition 'tok1'. [simplecpp.cpp:1643]: (performance, inconclusive) Technically the member function 'simplecpp::Macro::isReplaced' can be static. * makefile: add -Warning flags that cppcheck uses to simplecpp build. Namely: -Wabi -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wredundant-decls -Wshadow * fix -Wshadow warning. Was: main.cpp:65:35: warning: declaration shadows a local variable [-Wshadow] for (const simplecpp::Output &output : outputList) { ^ main.cpp:60:26: note: previous declaration is here simplecpp::TokenList output(files); ^ 1 warning generated.
1 parent 39ac1a3 commit 48a34f7

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
all: testrunner simplecpp
22

3-
CXXFLAGS = -Wall -Wextra -pedantic -g -std=c++0x
3+
CXXFLAGS = -Wall -Wextra -Wabi -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wredundant-decls -Wshadow -pedantic -g -std=c++0x
44
LDFLAGS = -g
55

66
%.o: %.cpp

main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ int main(int argc, char **argv)
5757
std::map<std::string, simplecpp::TokenList*> included = simplecpp::load(rawtokens, files, dui, &outputList);
5858
for (std::pair<std::string, simplecpp::TokenList *> i : included)
5959
i.second->removeComments();
60-
simplecpp::TokenList output(files);
61-
simplecpp::preprocess(output, rawtokens, files, included, dui, &outputList);
60+
simplecpp::TokenList outputTokens(files);
61+
simplecpp::preprocess(outputTokens, rawtokens, files, included, dui, &outputList);
6262

6363
// Output
64-
std::cout << output.stringify() << std::endl;
64+
std::cout << outputTokens.stringify() << std::endl;
6565
for (const simplecpp::Output &output : outputList) {
6666
std::cerr << output.location.file() << ':' << output.location.line << ": ";
6767
switch (output.type) {

simplecpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ namespace simplecpp {
16401640
return nextTok;
16411641
}
16421642

1643-
bool isReplaced(const std::set<std::string> &expandedmacros) const {
1643+
static bool isReplaced(const std::set<std::string> &expandedmacros) {
16441644
// return true if size > 1
16451645
std::set<std::string>::const_iterator it = expandedmacros.begin();
16461646
if (it == expandedmacros.end())

simplecpp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ namespace simplecpp {
179179
bool empty() const {
180180
return !frontToken;
181181
}
182-
void push_back(Token *token);
182+
void push_back(Token *tok);
183183

184184
void dump() const;
185185
std::string stringify() const;
@@ -246,7 +246,7 @@ namespace simplecpp {
246246
void constFoldComparison(Token *tok);
247247
void constFoldBitwise(Token *tok);
248248
void constFoldLogicalOp(Token *tok);
249-
void constFoldQuestionOp(Token **tok);
249+
void constFoldQuestionOp(Token **tok1);
250250

251251
std::string readUntil(std::istream &istr, const Location &location, const char start, const char end, OutputList *outputList);
252252

0 commit comments

Comments
 (0)