Skip to content

Commit f2925b1

Browse files
committed
mitigated misc-const-correctness clang-tidy false positive
fixed `readability-math-missing-parentheses` clang-tidy warnings .clang-tidy: disabled `readability-use-concise-preprocessor-directives` split up Clang warnings in CMake disabled `-Wnrvo` Clang warning fixed `misc-const-correctness` clang-tidy warnings clang-tidy.yml: updated to Clang 21
1 parent 04f4dfa commit f2925b1

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Checks: >
4949
-readability-magic-numbers,
5050
-readability-redundant-inline-specifier,
5151
-readability-simplify-boolean-expr,
52+
-readability-use-concise-preprocessor-directives,
5253
-readability-uppercase-literal-suffix,
5354
-performance-avoid-endl,
5455
-performance-enum-size,

.github/workflows/clang-tidy.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ jobs:
2626
run: |
2727
wget https://apt.llvm.org/llvm.sh
2828
chmod +x llvm.sh
29-
sudo ./llvm.sh 20
30-
sudo apt-get install clang-tidy-20
29+
sudo ./llvm.sh 21
30+
sudo apt-get install clang-tidy-21
3131
3232
- name: Verify clang-tidy configuration
3333
run: |
34-
clang-tidy-20 --verify-config
34+
clang-tidy-21 --verify-config
3535
3636
- name: Prepare CMake
3737
run: |
3838
cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
3939
env:
40-
CXX: clang-20
40+
CXX: clang-21
4141

4242
- name: Clang-Tidy
4343
run: |
44-
run-clang-tidy-20 -q -j $(nproc) -p=cmake.output
44+
run-clang-tidy-21 -q -j $(nproc) -p=cmake.output

CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,25 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
4949
# no need for c++98 compatibility
5050
add_compile_options(-Wno-c++98-compat-pedantic)
5151
# these are not really fixable
52-
add_compile_options(-Wno-exit-time-destructors -Wno-global-constructors -Wno-weak-vtables)
52+
add_compile_options(-Wno-exit-time-destructors)
53+
add_compile_options(-Wno-global-constructors)
54+
add_compile_options(-Wno-weak-vtables)
5355
add_compile_options_safe(-Wno-unsafe-buffer-usage)
56+
add_compile_options_safe(-Wno-nrvo)
5457
# we are not interested in these
55-
add_compile_options(-Wno-multichar -Wno-four-char-constants)
58+
add_compile_options(-Wno-multichar)
59+
add_compile_options(-Wno-four-char-constants)
5660
# ignore C++11-specific warning
57-
add_compile_options(-Wno-suggest-override -Wno-suggest-destructor-override)
61+
add_compile_options(-Wno-suggest-override)
62+
add_compile_options(-Wno-suggest-destructor-override)
5863
# contradicts -Wcovered-switch-default
5964
add_compile_options(-Wno-switch-default)
6065
# TODO: fix these?
61-
add_compile_options(-Wno-padded -Wno-sign-conversion -Wno-implicit-int-conversion -Wno-shorten-64-to-32 -Wno-shadow-field-in-constructor)
66+
add_compile_options(-Wno-padded)
67+
add_compile_options(-Wno-sign-conversion)
68+
add_compile_options(-Wno-implicit-int-conversion)
69+
add_compile_options(-Wno-shorten-64-to-32)
70+
add_compile_options(-Wno-shadow-field-in-constructor)
6271

6372
if (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
6473
# TODO: verify this regression still exists in clang-15

simplecpp.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
858858
back()->setstr(currentToken);
859859
location.adjust(currentToken);
860860
if (currentToken.find_first_of("\r\n") == std::string::npos)
861-
location.col += 2 + 2 * delim.size();
861+
location.col += 2 + (2 * delim.size());
862862
else
863863
location.col += 1 + delim.size();
864864

@@ -1313,7 +1313,7 @@ void simplecpp::TokenList::constFoldLogicalOp(Token *tok)
13131313
void simplecpp::TokenList::constFoldQuestionOp(Token **tok1)
13141314
{
13151315
bool gotoTok1 = false;
1316-
for (Token *tok = *tok1; tok && tok->op != ')'; tok = gotoTok1 ? *tok1 : tok->next) {
1316+
for (const Token *tok = *tok1; tok && tok->op != ')'; tok = gotoTok1 ? *tok1 : tok->next) {
13171317
gotoTok1 = false;
13181318
if (tok->str() != "?")
13191319
continue;
@@ -1927,7 +1927,7 @@ namespace simplecpp {
19271927
}
19281928
}
19291929

1930-
Token * const output_end_1 = output->back();
1930+
const Token * const output_end_1 = output->back();
19311931

19321932
const Token *valueToken2;
19331933
const Token *endToken2;
@@ -2232,7 +2232,7 @@ namespace simplecpp {
22322232
const bool canBeConcatenatedStringOrChar = isStringLiteral_(A->str()) || isCharLiteral_(A->str());
22332233
const bool unexpectedA = (!A->name && !A->number && !A->str().empty() && !canBeConcatenatedWithEqual && !canBeConcatenatedStringOrChar);
22342234

2235-
Token * const B = tok->next->next;
2235+
const Token * const B = tok->next->next;
22362236
if (!B->name && !B->number && B->op && !B->isOneOf("#="))
22372237
throw invalidHashHash::unexpectedToken(tok->location, name(), B);
22382238

@@ -2510,11 +2510,11 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
25102510
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
25112511
if (tok->str() != "sizeof")
25122512
continue;
2513-
simplecpp::Token *tok1 = tok->next;
2513+
const simplecpp::Token *tok1 = tok->next;
25142514
if (!tok1) {
25152515
throw std::runtime_error("missing sizeof argument");
25162516
}
2517-
simplecpp::Token *tok2 = tok1->next;
2517+
const simplecpp::Token *tok2 = tok1->next;
25182518
if (!tok2) {
25192519
throw std::runtime_error("missing sizeof argument");
25202520
}
@@ -2529,7 +2529,7 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
25292529
}
25302530

25312531
std::string type;
2532-
for (simplecpp::Token *typeToken = tok1; typeToken != tok2; typeToken = typeToken->next) {
2532+
for (const simplecpp::Token *typeToken = tok1; typeToken != tok2; typeToken = typeToken->next) {
25332533
if ((typeToken->str() == "unsigned" || typeToken->str() == "signed") && typeToken->next->name)
25342534
continue;
25352535
if (typeToken->str() == "*" && type.find('*') != std::string::npos)
@@ -2580,11 +2580,11 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
25802580
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
25812581
if (tok->str() != HAS_INCLUDE)
25822582
continue;
2583-
simplecpp::Token *tok1 = tok->next;
2583+
const simplecpp::Token *tok1 = tok->next;
25842584
if (!tok1) {
25852585
throw std::runtime_error("missing __has_include argument");
25862586
}
2587-
simplecpp::Token *tok2 = tok1->next;
2587+
const simplecpp::Token *tok2 = tok1->next;
25882588
if (!tok2) {
25892589
throw std::runtime_error("missing __has_include argument");
25902590
}
@@ -2602,7 +2602,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
26022602
const bool systemheader = (tok1 && tok1->op == '<');
26032603
std::string header;
26042604
if (systemheader) {
2605-
simplecpp::Token *tok3 = tok1->next;
2605+
const simplecpp::Token *tok3 = tok1->next;
26062606
if (!tok3) {
26072607
throw std::runtime_error("missing __has_include closing angular bracket");
26082608
}
@@ -2613,7 +2613,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
26132613
}
26142614
}
26152615

2616-
for (simplecpp::Token *headerToken = tok1->next; headerToken != tok3; headerToken = headerToken->next)
2616+
for (const simplecpp::Token *headerToken = tok1->next; headerToken != tok3; headerToken = headerToken->next)
26172617
header += headerToken->str();
26182618
} else {
26192619
header = tok1->str().substr(1U, tok1->str().size() - 2U);

simplecpp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ namespace simplecpp {
430430
std::pair<FileData *, bool> get(const std::string &sourcefile, const std::string &header, const DUI &dui, bool systemheader, std::vector<std::string> &filenames, OutputList *outputList);
431431

432432
void insert(FileData data) {
433+
// NOLINTNEXTLINE(misc-const-correctness) - FP
433434
FileData *const newdata = new FileData(std::move(data));
434435

435436
mData.emplace_back(newdata);

0 commit comments

Comments
 (0)