Skip to content

Commit d86671f

Browse files
authored
clang-tidy.yml: updated to Clang 21 (#421)
1 parent 60e743a commit d86671f

File tree

5 files changed

+37
-19
lines changed

5 files changed

+37
-19
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
@@ -33,19 +33,19 @@ jobs:
3333
run: |
3434
wget https://apt.llvm.org/llvm.sh
3535
chmod +x llvm.sh
36-
sudo ./llvm.sh 20
37-
sudo apt-get install clang-tidy-20
36+
sudo ./llvm.sh 21
37+
sudo apt-get install clang-tidy-21
3838
3939
- name: Verify clang-tidy configuration
4040
run: |
41-
clang-tidy-20 --verify-config
41+
clang-tidy-21 --verify-config
4242
4343
- name: Prepare CMake
4444
run: |
4545
cmake -S . -B cmake.output -Werror=dev --warn-uninitialized -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
4646
env:
47-
CXX: clang-20
47+
CXX: clang-21
4848

4949
- name: Clang-Tidy
5050
run: |
51-
run-clang-tidy-20 -q -j $(nproc) -p=cmake.output
51+
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: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
874874
back()->setstr(currentToken);
875875
location.adjust(currentToken);
876876
if (currentToken.find_first_of("\r\n") == std::string::npos)
877-
location.col += 2 + 2 * delim.size();
877+
location.col += 2 + (2 * delim.size());
878878
else
879879
location.col += 1 + delim.size();
880880

@@ -1329,6 +1329,7 @@ void simplecpp::TokenList::constFoldLogicalOp(Token *tok)
13291329
void simplecpp::TokenList::constFoldQuestionOp(Token **tok1)
13301330
{
13311331
bool gotoTok1 = false;
1332+
// NOLINTNEXTLINE(misc-const-correctness) - technically correct but used to access non-const data
13321333
for (Token *tok = *tok1; tok && tok->op != ')'; tok = gotoTok1 ? *tok1 : tok->next) {
13331334
gotoTok1 = false;
13341335
if (tok->str() != "?")
@@ -1508,7 +1509,12 @@ namespace simplecpp {
15081509
}
15091510

15101511
Macro(const Macro &other) : nameTokDef(nullptr), files(other.files), tokenListDefine(other.files), valueDefinedInCode_(other.valueDefinedInCode_) {
1511-
*this = other;
1512+
// TODO: remove the try-catch - see #537
1513+
// avoid bugprone-exception-escape clang-tidy warning
1514+
try {
1515+
*this = other;
1516+
}
1517+
catch (const Error&) {} // NOLINT(bugprone-empty-catch)
15121518
}
15131519

15141520
~Macro() {
@@ -1945,6 +1951,7 @@ namespace simplecpp {
19451951
}
19461952
}
19471953

1954+
// NOLINTNEXTLINE(misc-const-correctness) - technically correct but used to access non-const data
19481955
Token * const output_end_1 = output.back();
19491956

19501957
const Token *valueToken2;
@@ -2250,7 +2257,7 @@ namespace simplecpp {
22502257
const bool canBeConcatenatedStringOrChar = isStringLiteral_(A->str()) || isCharLiteral_(A->str());
22512258
const bool unexpectedA = (!A->name && !A->number && !A->str().empty() && !canBeConcatenatedWithEqual && !canBeConcatenatedStringOrChar);
22522259

2253-
Token * const B = tok->next->next;
2260+
const Token * const B = tok->next->next;
22542261
if (!B->name && !B->number && B->op && !B->isOneOf("#="))
22552262
throw invalidHashHash::unexpectedToken(tok->location, name(), B);
22562263

@@ -2528,11 +2535,11 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
25282535
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
25292536
if (tok->str() != "sizeof")
25302537
continue;
2531-
simplecpp::Token *tok1 = tok->next;
2538+
const simplecpp::Token *tok1 = tok->next;
25322539
if (!tok1) {
25332540
throw std::runtime_error("missing sizeof argument");
25342541
}
2535-
simplecpp::Token *tok2 = tok1->next;
2542+
const simplecpp::Token *tok2 = tok1->next;
25362543
if (!tok2) {
25372544
throw std::runtime_error("missing sizeof argument");
25382545
}
@@ -2547,7 +2554,7 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
25472554
}
25482555

25492556
std::string type;
2550-
for (simplecpp::Token *typeToken = tok1; typeToken != tok2; typeToken = typeToken->next) {
2557+
for (const simplecpp::Token *typeToken = tok1; typeToken != tok2; typeToken = typeToken->next) {
25512558
if ((typeToken->str() == "unsigned" || typeToken->str() == "signed") && typeToken->next->name)
25522559
continue;
25532560
if (typeToken->str() == "*" && type.find('*') != std::string::npos)
@@ -2598,11 +2605,11 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
25982605
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
25992606
if (tok->str() != HAS_INCLUDE)
26002607
continue;
2601-
simplecpp::Token *tok1 = tok->next;
2608+
const simplecpp::Token *tok1 = tok->next;
26022609
if (!tok1) {
26032610
throw std::runtime_error("missing __has_include argument");
26042611
}
2605-
simplecpp::Token *tok2 = tok1->next;
2612+
const simplecpp::Token *tok2 = tok1->next;
26062613
if (!tok2) {
26072614
throw std::runtime_error("missing __has_include argument");
26082615
}
@@ -2620,7 +2627,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
26202627
const bool systemheader = (tok1 && tok1->op == '<');
26212628
std::string header;
26222629
if (systemheader) {
2623-
simplecpp::Token *tok3 = tok1->next;
2630+
const simplecpp::Token *tok3 = tok1->next;
26242631
if (!tok3) {
26252632
throw std::runtime_error("missing __has_include closing angular bracket");
26262633
}
@@ -2631,7 +2638,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
26312638
}
26322639
}
26332640

2634-
for (simplecpp::Token *headerToken = tok1->next; headerToken != tok3; headerToken = headerToken->next)
2641+
for (const simplecpp::Token *headerToken = tok1->next; headerToken != tok3; headerToken = headerToken->next)
26352642
header += headerToken->str();
26362643
} else {
26372644
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
@@ -426,6 +426,7 @@ namespace simplecpp {
426426
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);
427427

428428
void insert(FileData data) {
429+
// NOLINTNEXTLINE(misc-const-correctness) - FP
429430
FileData *const newdata = new FileData(std::move(data));
430431

431432
mData.emplace_back(newdata);

0 commit comments

Comments
 (0)