Skip to content

Commit 85a76d4

Browse files
committed
mitigated bugprone-assignment-in-selection-statement clang-tidy warning
fixed `readability-redundant-parentheses` clang-tidy warnings mitigated `misc-explicit-constructor` clang-tidy warnings disabled `-Wlifetime-safety-*` Clang warnings for now mitigated `misc-const-correctness` clang-tidy warnings .clang-tidy: disabled `bugprone-std-exception-baseclass` for now .clang-tidy: disabled `bugprone-signed-bitwise` for now mitigated `bugprone-unhandled-code-paths` clang-tidy warnings .clang-tidy: disabled `readability-trailing-comma` clang-tidy check .clang-tidy: removed disabling of `hicpp-*` checks as they no longer exist clang-tidy.yml: updated to Clang 23
1 parent c44d686 commit 85a76d4

7 files changed

Lines changed: 43 additions & 32 deletions

File tree

.clang-tidy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Checks: >
1010
-cppcoreguidelines-*,
1111
-fuchsia-*,
1212
-google-*,
13-
-hicpp-*,
1413
-linuxkernel-*,
1514
-llvm-*,
1615
-llvmlibc-*,
@@ -21,6 +20,8 @@ Checks: >
2120
-bugprone-branch-clone,
2221
-bugprone-easily-swappable-parameters,
2322
-bugprone-narrowing-conversions,
23+
-bugprone-signed-bitwise,
24+
-bugprone-std-exception-baseclass,
2425
-bugprone-switch-missing-default-case,
2526
-bugprone-throwing-static-initialization,
2627
-bugprone-unchecked-string-to-number-conversion,
@@ -42,6 +43,7 @@ Checks: >
4243
-readability-isolate-declaration,
4344
-readability-magic-numbers,
4445
-readability-redundant-inline-specifier,
46+
-readability-trailing-comma,
4547
-readability-use-concise-preprocessor-directives,
4648
-readability-uppercase-literal-suffix,
4749
-performance-avoid-endl,

.github/workflows/clang-tidy.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ jobs:
3333
run: |
3434
wget https://apt.llvm.org/llvm.sh
3535
chmod +x llvm.sh
36-
sudo ./llvm.sh 22
37-
sudo apt-get install clang-tidy-22
36+
sudo ./llvm.sh 23
37+
sudo apt-get install clang-tidy-23
3838
3939
- name: Verify clang-tidy configuration
4040
run: |
41-
clang-tidy-22 --verify-config
41+
clang-tidy-23 --verify-config
4242
4343
- name: Prepare CMake
4444
run: |
4545
cmake -S . -B cmake.output -Werror=dev --warn-uninitialized -DCMAKE_CXX_STANDARD=23 -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
4646
env:
47-
CXX: clang-22
47+
CXX: clang-23
4848

4949
- name: Clang-Tidy
5050
run: |
51-
run-clang-tidy-22 -q -j $(nproc) -enable-check-profile -p=cmake.output
51+
run-clang-tidy-23 -q -j $(nproc) -enable-check-profile -p=cmake.output

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
7373
add_compile_options_safe(-Wno-thread-safety-negative)
7474
add_compile_options_safe(-Wno-thread-safety-beta)
7575

76+
# TODO: enable
77+
add_compile_options_safe(-Wno-lifetime-safety-intra-tu-suggestions)
78+
add_compile_options_safe(-Wno-lifetime-safety-intra-tu-constructor-suggestions)
79+
add_compile_options_safe(-Wno-lifetime-safety-cross-tu-constructor-suggestions)
80+
7681
# TODO: fix these?
7782
add_compile_options(-Wno-padded)
7883
add_compile_options(-Wno-sign-conversion)

main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static bool isDir(const std::string& path)
2626
return (file_stat.st_mode & S_IFMT) == S_IFDIR;
2727
}
2828

29-
int main(int argc, char **argv)
29+
int main(int argc, char *argv[])
3030
{
3131
bool error = false;
3232
const char *filename = nullptr;
@@ -49,6 +49,7 @@ int main(int argc, char **argv)
4949
if (*arg == '-') {
5050
bool found = false;
5151
const char c = arg[1];
52+
// NOLINTNEXTLINE(bugprone-unhandled-code-paths)
5253
switch (c) {
5354
case 'D': { // define symbol
5455
found = true;

simplecpp.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ static bool endsWith(const std::string &s, const std::string &e)
153153
return (s.size() >= e.size()) && std::equal(e.rbegin(), e.rend(), s.rbegin());
154154
}
155155

156-
static bool sameline(const simplecpp::Token *tok1, const simplecpp::Token *tok2)
156+
static bool sameline(const simplecpp::Token * const tok1, const simplecpp::Token * const tok2)
157157
{
158158
return tok1 && tok2 && tok1->location.sameline(tok2->location);
159159
}
160160

161-
static bool isAlternativeBinaryOp(const simplecpp::Token *tok, const std::string &alt)
161+
static bool isAlternativeBinaryOp(const simplecpp::Token * const tok, const std::string &alt)
162162
{
163163
return (tok->name &&
164164
tok->str() == alt &&
@@ -168,7 +168,7 @@ static bool isAlternativeBinaryOp(const simplecpp::Token *tok, const std::string
168168
(tok->next->number || tok->next->name || tok->next->op == '('));
169169
}
170170

171-
static bool isAlternativeUnaryOp(const simplecpp::Token *tok, const std::string &alt)
171+
static bool isAlternativeUnaryOp(const simplecpp::Token * const tok, const std::string &alt)
172172
{
173173
return ((tok->name && tok->str() == alt) &&
174174
(!tok->previous || tok->previous->op == '(') &&
@@ -622,7 +622,7 @@ static std::string escapeString(const std::string &str)
622622
return ostr.str();
623623
}
624624

625-
static void portabilityBackslash(simplecpp::OutputList *outputList, const simplecpp::Location &location)
625+
static void portabilityBackslash(simplecpp::OutputList * const outputList, const simplecpp::Location &location)
626626
{
627627
if (!outputList)
628628
return;
@@ -799,7 +799,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
799799
if (ch == '\\') {
800800
TokenString tmp;
801801
char tmp_ch = ch;
802-
while ((stream.good()) && (tmp_ch == '\\' || tmp_ch == ' ' || tmp_ch == '\t')) {
802+
while (stream.good() && (tmp_ch == '\\' || tmp_ch == ' ' || tmp_ch == '\t')) {
803803
tmp += tmp_ch;
804804
tmp_ch = stream.readChar();
805805
}
@@ -999,7 +999,7 @@ void simplecpp::TokenList::constFold()
999999
}
10001000
}
10011001

1002-
static bool isFloatSuffix(const simplecpp::Token *tok)
1002+
static bool isFloatSuffix(const simplecpp::Token * const tok)
10031003
{
10041004
if (!tok || tok->str().size() != 1U)
10051005
return false;
@@ -1010,7 +1010,7 @@ static bool isFloatSuffix(const simplecpp::Token *tok)
10101010
static const std::string AND("and");
10111011
static const std::string BITAND("bitand");
10121012
static const std::string BITOR("bitor");
1013-
static bool isAlternativeAndBitandBitor(const simplecpp::Token* tok)
1013+
static bool isAlternativeAndBitandBitor(const simplecpp::Token * const tok)
10141014
{
10151015
return isAlternativeBinaryOp(tok, AND) || isAlternativeBinaryOp(tok, BITAND) || isAlternativeBinaryOp(tok, BITOR);
10161016
}
@@ -1699,7 +1699,7 @@ namespace simplecpp {
16991699
};
17001700

17011701
struct invalidDirectiveAsMacroParameter : public Error {
1702-
invalidDirectiveAsMacroParameter(const Location &loc)
1702+
explicit invalidDirectiveAsMacroParameter(const Location &loc)
17031703
: Error(loc, "it is invalid to use a preprocessor directive as macro parameter") {}
17041704
};
17051705

@@ -2296,7 +2296,7 @@ namespace simplecpp {
22962296
* @return token after B
22972297
*/
22982298
const Token *expandHashHash(TokenList &output, const Location &loc, const Token *tok, const MacroMap &macros, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> &parametertokens, bool expandResult=true) const {
2299-
Token *A = output.back();
2299+
Token * const A = output.back();
23002300
if (!A)
23012301
throw invalidHashHash(tok->location, name(), "Missing first argument");
23022302
if (!sameline(tok, tok->next) || !sameline(tok, tok->next->next))
@@ -3258,7 +3258,7 @@ static bool getFileId(const std::string &path, FileID &id)
32583258
#endif
32593259
}
32603260

3261-
simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens, std::vector<std::string> &filenames, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, FileDataCache cache)
3261+
simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens, std::vector<std::string> &filenames, const simplecpp::DUI &dui, simplecpp::OutputList * const outputList, FileDataCache cache)
32623262
{
32633263
#ifdef SIMPLECPP_WINDOWS
32643264
if (dui.clearIncludeCache)
@@ -3341,7 +3341,7 @@ simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens,
33413341
return cache;
33423342
}
33433343

3344-
static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token *&tok1, simplecpp::MacroMap &macros, std::vector<std::string> &files, simplecpp::OutputList *outputList)
3344+
static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token *&tok1, simplecpp::MacroMap &macros, std::vector<std::string> &files, simplecpp::OutputList * const outputList)
33453345
{
33463346
const simplecpp::Token * const tok = tok1;
33473347
const simplecpp::MacroMap::const_iterator it = tok->name ? macros.find(tok->str()) : macros.end();
@@ -3391,21 +3391,21 @@ static void getLocaltime(struct tm &ltime)
33913391
#endif
33923392
}
33933393

3394-
static std::string getDateDefine(const struct tm *timep)
3394+
static std::string getDateDefine(const struct tm * const timep)
33953395
{
33963396
char buf[] = "??? ?? ????";
33973397
strftime(buf, sizeof(buf), "%b %d %Y", timep);
33983398
return std::string("\"").append(buf).append("\"");
33993399
}
34003400

3401-
static std::string getTimeDefine(const struct tm *timep)
3401+
static std::string getTimeDefine(const struct tm * const timep)
34023402
{
34033403
char buf[] = "??:??:??";
34043404
strftime(buf, sizeof(buf), "%H:%M:%S", timep);
34053405
return std::string("\"").append(buf).append("\"");
34063406
}
34073407

3408-
void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, simplecpp::FileDataCache &cache, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage, std::list<simplecpp::IfCond> *ifCond)
3408+
void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, simplecpp::FileDataCache &cache, const simplecpp::DUI &dui, simplecpp::OutputList * const outputList, std::list<simplecpp::MacroUsage> * const macroUsage, std::list<simplecpp::IfCond> * const ifCond)
34093409
{
34103410
#ifdef SIMPLECPP_WINDOWS
34113411
if (dui.clearIncludeCache)
@@ -3783,6 +3783,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
37833783
std::string header;
37843784

37853785
if (systemheader) {
3786+
// NOLINTNEXTLINE(bugprone-assignment-in-selection-statement)
37863787
while ((tok = tok->next) && tok->op != '>')
37873788
header += tok->str();
37883789
if (tok && tok->op == '>')

simplecpp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ namespace simplecpp {
7575
struct View
7676
{
7777
// cppcheck-suppress noExplicitConstructor
78+
// NOLINTNEXTLINE(misc-explicit-constructor)
7879
View(const char* data)
7980
: mData(data)
8081
, mSize(strlen(data))
@@ -88,6 +89,7 @@ namespace simplecpp {
8889
{}
8990

9091
// cppcheck-suppress noExplicitConstructor
92+
// NOLINTNEXTLINE(misc-explicit-constructor)
9193
View(const std::string& str)
9294
: mData(str.data())
9395
, mSize(str.size())

test.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void assertThrowFailed(int line)
8686
std::cerr << "exception not thrown" << std::endl;
8787
}
8888

89-
static void testcase(const std::string &name, void (*f)(), int argc, char * const *argv)
89+
static void testcase(const std::string &name, void (*const f)(), int argc, char *argv[])
9090
{
9191
if (argc == 1) {
9292
f();
@@ -101,7 +101,7 @@ static void testcase(const std::string &name, void (*f)(), int argc, char * cons
101101

102102
#define TEST_CASE(F) (testcase(#F, F, argc, argv))
103103

104-
static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
104+
static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList * const outputList=nullptr)
105105
{
106106
switch (USE_INPUT) {
107107
case Input::Stringstream: {
@@ -115,24 +115,24 @@ static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, s
115115
return simplecpp::TokenList{filenames}; // unreachable - needed for GCC and Visual Studio
116116
}
117117

118-
static simplecpp::TokenList makeTokenList(const char code[], std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
118+
static simplecpp::TokenList makeTokenList(const char code[], std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList * const outputList=nullptr)
119119
{
120120
return makeTokenList(code, strlen(code), filenames, filename, outputList);
121121
}
122122

123-
static std::string readfile(const char code[], simplecpp::OutputList *outputList=nullptr)
123+
static std::string readfile(const char code[], simplecpp::OutputList * const outputList=nullptr)
124124
{
125125
std::vector<std::string> files;
126126
return makeTokenList(code,files,std::string(),outputList).stringify();
127127
}
128128

129-
static std::string readfile(const char code[], std::size_t size, simplecpp::OutputList *outputList=nullptr)
129+
static std::string readfile(const char code[], std::size_t size, simplecpp::OutputList * const outputList=nullptr)
130130
{
131131
std::vector<std::string> files;
132132
return makeTokenList(code,size,files,std::string(),outputList).stringify();
133133
}
134134

135-
static std::string preprocess(const char code[], const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage = nullptr, std::list<simplecpp::IfCond> *ifCond = nullptr, const std::string &file = std::string())
135+
static std::string preprocess(const char code[], const simplecpp::DUI &dui, simplecpp::OutputList * const outputList, std::list<simplecpp::MacroUsage> * const macroUsage = nullptr, std::list<simplecpp::IfCond> * const ifCond = nullptr, const std::string &file = std::string())
136136
{
137137
std::vector<std::string> files;
138138
simplecpp::FileDataCache cache;
@@ -160,17 +160,17 @@ static std::string preprocess(const char code[], const simplecpp::DUI &dui)
160160
return preprocess(code, dui, nullptr);
161161
}
162162

163-
static std::string preprocess(const char code[], simplecpp::OutputList *outputList)
163+
static std::string preprocess(const char code[], simplecpp::OutputList * const outputList)
164164
{
165165
return preprocess(code, simplecpp::DUI(), outputList);
166166
}
167167

168-
static std::string preprocess(const char code[], std::list<simplecpp::IfCond> *ifCond)
168+
static std::string preprocess(const char code[], std::list<simplecpp::IfCond> * const ifCond)
169169
{
170170
return preprocess(code, simplecpp::DUI(), nullptr, nullptr, ifCond);
171171
}
172172

173-
static std::string preprocess(const char code[], std::list<simplecpp::MacroUsage> *macroUsage)
173+
static std::string preprocess(const char code[], std::list<simplecpp::MacroUsage> * const macroUsage)
174174
{
175175
return preprocess(code, simplecpp::DUI(), nullptr, macroUsage);
176176
}
@@ -3960,7 +3960,7 @@ static void leak()
39603960
}
39613961
}
39623962

3963-
static void runTests(int argc, char **argv, Input input)
3963+
static void runTests(int argc, char *argv[], Input input)
39643964
{
39653965
USE_INPUT = input;
39663966

@@ -4257,7 +4257,7 @@ static void runTests(int argc, char **argv, Input input)
42574257
TEST_CASE(leak);
42584258
}
42594259

4260-
int main(int argc, char **argv)
4260+
int main(int argc, char *argv[])
42614261
{
42624262
runTests(argc, argv, Input::Stringstream);
42634263
runTests(argc, argv, Input::CharBuffer);

0 commit comments

Comments
 (0)