Skip to content

Commit f477cb6

Browse files
committed
Fixes related to clang-tidy
1 parent bfd5710 commit f477cb6

20 files changed

Lines changed: 504 additions & 369 deletions

.clang-tidy

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
3+
# Unfortunately const-correctness seems to be almost completely broken
4+
# (clang 19)
25
Checks: "*,
36
-abseil-*,
47
-altera-*,
@@ -11,13 +14,16 @@ Checks: "*,
1114
-readability-else-after-return,
1215
-readability-static-accessed-through-instance,
1316
-readability-avoid-const-params-in-decls,
17+
-readability-simplify-boolean-expr,
1418
-cppcoreguidelines-non-private-member-variables-in-classes,
1519
-misc-non-private-member-variables-in-classes,
20+
-misc-const-correctness,
1621
"
1722
WarningsAsErrors: ''
18-
HeaderFilterRegex: ''
23+
HeaderFilterRegex: '^(src|include)/.*'
1924
FormatStyle: none
2025

26+
2127
# Command line options
2228
ExtraArgs: [
2329
'-Wno-unknown-warning-option',
@@ -31,6 +37,6 @@ ExtraArgs: [
3137
# It doesn't have a YAML equivalent
3238

3339
CheckOptions:
34-
readability-identifier-length.IgnoredVariableNames: 'x|y|z|id|ch'
35-
readability-identifier-length.IgnoredParameterNames: 'x|y|z|id|ch'
40+
readability-identifier-length.IgnoredVariableNames: 'x|y|z|id|ch|to'
41+
readability-identifier-length.IgnoredParameterNames: 'x|y|z|id|ch|to'
3642

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ include(cmake/PreventInSourceBuilds.cmake)
2626
include(cmake/Emscripten.cmake)
2727
include(ProjectOptions.cmake)
2828

29+
if(MSVC)
30+
31+
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
32+
add_compile_options(-fconstexpr-steps=12712420)
33+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
34+
35+
else()
36+
37+
# TODO support Intel compiler
38+
endif()
2939

3040
cons_expr_setup_options()
3141

cmake/StaticAnalyzers.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ macro(cons_expr_enable_clang_tidy target WARNINGS_AS_ERRORS)
7777
-extra-arg=-Wno-unused-command-line-argument
7878
-extra-arg=-Wno-unknown-argument
7979
-extra-arg=-Wno-gcc-compat
80+
-extra-arg=-Wno-gcc-compat
81+
-extra-arg=-fconstexpr-steps=12712420
8082
--quiet
8183
-p)
8284
# set standard

examples/compile_test.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#include <cons_expr/cons_expr.hpp>
2+
#include <cstdint>
3+
#include <cstdio>
24
#include <format>
5+
#include <string_view>
6+
#include <functional>
37

48
using cons_expr_type = lefticus::cons_expr<std::uint16_t, char, long long, long double>;
59

10+
namespace {
611
constexpr long long add(long long x, long long y) { return x + y; }
712

813
consteval auto make_scripted_function()
@@ -28,6 +33,7 @@ consteval auto make_scripted_function()
2833

2934
return std::bind_front(evaluator.make_callable<long long(long long, long long)>("sum"), evaluator);
3035
}
36+
}
3137

3238

3339
int main()
@@ -40,7 +46,7 @@ int main()
4046
std::puts(std::format("sum({} to {}) = {}", from, to, func(from, to).value()).c_str());
4147
};
4248

43-
print_sum(101, 132414);
44-
print_sum(1, 1222222);
45-
print_sum(-10, 10);
49+
print_sum(101, 132414); // NOLINT these values are arbitrary
50+
print_sum(1, 1222222); // NOLINT
51+
print_sum(-10, 10); // NOLINT
4652
}

examples/speed_test.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#include <cons_expr/cons_expr.hpp>
2+
#include <cstdint>
23
#include <iostream>
4+
#include <string_view>
35

6+
7+
8+
namespace {
49
constexpr long long add(long long x, long long y) { return x + y; }
510

6-
void display(long long i) { std::cout << i << '\n'; }
11+
void display(long long value) { std::cout << value << '\n'; }
712

813
using cons_expr_type = lefticus::cons_expr<std::uint16_t, char, long long, double>;
914

@@ -21,6 +26,7 @@ template<typename Result> Result evaluate_to(std::string_view input)
2126
{
2227
return std::get<Result>(std::get<cons_expr_type::Atom>(evaluate(input).value));
2328
}
29+
}
2430

2531
int main()
2632
{

fuzz_test/fuzz_tester.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#include <cons_expr/cons_expr.hpp>
2-
#include <cons_expr/utility.hpp>
3-
#include <fmt/format.h>
2+
#include <cstdint>
3+
#include <cstddef>
4+
#include <iterator>
45
#include <string>
5-
#include <string_view>
66

77
// Fuzzer that tests the cons_expr parser and evaluator
88
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
99
{
10-
// Create a string view from the fuzz data
11-
std::string_view script(reinterpret_cast<const char *>(data), size);
10+
const std::string script(data, std::next(data, static_cast<std::ptrdiff_t>(size)));
1211

1312
// Initialize the cons_expr evaluator
1413
lefticus::cons_expr<> evaluator;
@@ -21,4 +20,4 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
2120
[[maybe_unused]] auto result = evaluator.sequence(evaluator.global_scope, parse_result);
2221

2322
return 0;// Non-zero return values are reserved for future use
24-
}
23+
}

src/ccons_expr/main.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
#include <cstddef>
2+
#include <exception>
13
#include <format>
24
#include <string>
35
#include <vector>
46

5-
#include "ftxui/component/captured_mouse.hpp"// for ftxui
67
#include "ftxui/component/component.hpp"// for Input, Renderer, ResizableSplitLeft
78
#include "ftxui/component/component_base.hpp"// for ComponentBase, Component
89
#include "ftxui/component/screen_interactive.hpp"// for ScreenInteractive
910
#include "ftxui/dom/elements.hpp"// for operator|, separator, text, Element, flex, vbox, border
10-
#include "ftxui/dom/table.hpp"// for operator|, separator, text, Element, flex, vbox, border
1111

1212
#include <cons_expr/cons_expr.hpp>
1313
#include <cons_expr/utility.hpp>
1414

1515
#include <internal_use_only/config.hpp>
1616

17+
static constexpr int InitialSplitWidth = 50;
18+
static constexpr int GlobalsHeight = 5;
19+
static constexpr int ValuesHeight = 7;
1720

1821
int main([[maybe_unused]] int argc, [[maybe_unused]] const char *argv[])
1922
{
@@ -38,19 +41,19 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] const char *argv[])
3841

3942
auto update_objects = [&]() {
4043
entries.clear();
41-
for (std::size_t index = 0; auto item : evaluator.values[{ 0, evaluator.values.size() }]) {
44+
for (std::size_t index = 0; auto item : evaluator.values[{ .start=0, .size=evaluator.values.size() }]) {
4245
entries.push_back(std::format("{}: {}", index, to_string(evaluator, true, item)));
4346
++index;
4447
}
4548

4649
characters.clear();
47-
for (std::size_t index = 0; auto item : evaluator.strings[{ 0, evaluator.strings.size() }]) {
50+
for (std::size_t index = 0; auto item : evaluator.strings[{ .start=0, .size=evaluator.strings.size() }]) {
4851
characters.push_back(std::format("{}: '{}'", index, item));
4952
++index;
5053
}
5154

5255
globals.clear();
53-
for (auto [key, value] : evaluator.global_scope[{ 0, evaluator.global_scope.size() }]) {
56+
for (auto [key, value] : evaluator.global_scope[{ .start=0, .size=evaluator.global_scope.size() }]) {
5457
globals.push_back(std::format("{}: '{}'", to_string(evaluator, false, key), to_string(evaluator, true, value)));
5558
}
5659
};
@@ -77,7 +80,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] const char *argv[])
7780

7881

7982
auto button = ftxui::Button("Evaluate", do_evaluate);
80-
int size = 50;
83+
int size = InitialSplitWidth;
8184
auto resizeable_bits = ftxui::ResizableSplitLeft(textarea_1, output_1, &size);
8285

8386
auto radiobox = ftxui::Menu(&entries, &selected);
@@ -113,10 +116,10 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] const char *argv[])
113116
return ftxui::hbox({ characterbox->Render() | ftxui::vscroll_indicator | ftxui::frame,
114117
ftxui::separator(),
115118
ftxui::vbox({ globalsbox->Render() | ftxui::vscroll_indicator | ftxui::frame
116-
| ftxui::size(ftxui::HEIGHT, ftxui::EQUAL, 5),
119+
| ftxui::size(ftxui::HEIGHT, ftxui::EQUAL, GlobalsHeight),
117120
ftxui::separator(),
118121
radiobox->Render() | ftxui::vscroll_indicator | ftxui::frame
119-
| ftxui::size(ftxui::HEIGHT, ftxui::EQUAL, 7),
122+
| ftxui::size(ftxui::HEIGHT, ftxui::EQUAL, ValuesHeight),
120123
ftxui::separator(),
121124
resizeable_bits->Render() | ftxui::flex,
122125
ftxui::separator(),

src/cons_expr_cli/main.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
#include <CLI/CLI.hpp>
2+
#include <cstdio>
3+
#include <cstdlib>
4+
#include <exception>
25
#include <filesystem>
36
#include <format>
47
#include <fstream>
8+
#include <iostream>
9+
#include <ios>
10+
#include <optional>
11+
#include <ostream>
512
#include <spdlog/spdlog.h>
613
#include <sstream>
714

815
#include <cons_expr/cons_expr.hpp>
916
#include <cons_expr/utility.hpp>
1017

1118
#include <internal_use_only/config.hpp>
19+
#include <string>
20+
#include <stdexcept>
1221

1322
using cons_expr_type = lefticus::cons_expr<>;
1423
namespace fs = std::filesystem;
1524

16-
void display(cons_expr_type::int_type i) { std::cout << i << '\n'; }
25+
namespace {
26+
void display(cons_expr_type::int_type value) { std::cout << value << '\n'; }
1727

1828
// Read a file into a string
1929
std::string read_file(const fs::path &path)
2030
{
2131
if (!fs::exists(path)) { throw std::runtime_error(std::format("File not found: {}", path.string())); }
2232

23-
std::ifstream file(path, std::ios::in | std::ios::binary);
33+
std::ifstream const file(path, std::ios::in | std::ios::binary);
2434
if (!file) { throw std::runtime_error(std::format("Failed to open file: {}", path.string())); }
2535

2636
std::stringstream buffer;
2737
buffer << file.rdbuf();
2838
return buffer.str();
2939
}
40+
}
3041

3142
int main(int argc, const char **argv)
3243
{
@@ -63,7 +74,7 @@ int main(int argc, const char **argv)
6374
if (file_path) {
6475
try {
6576
std::cout << "Executing script from file: " << *file_path << '\n';
66-
std::string file_content = read_file(fs::path(*file_path));
77+
std::string const file_content = read_file(fs::path(*file_path));
6778

6879
auto [parse_result, remaining] = evaluator.parse(file_content);
6980
auto result = evaluator.sequence(evaluator.global_scope, parse_result);

test/cond_tests.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include <catch2/catch_test_macros.hpp>
2-
#include <catch2/matchers/catch_matchers_floating_point.hpp>
32

43
#include <cons_expr/cons_expr.hpp>
5-
#include <cons_expr/utility.hpp>
6-
#include <internal_use_only/config.hpp>
4+
#include <cstdint>
5+
#include <string_view>
6+
#include <variant>
77

88
using IntType = int;
99
using FloatType = double;
1010

11+
namespace {
1112
template<typename Result> constexpr Result evaluate_to(std::string_view input)
1213
{
1314
lefticus::cons_expr<std::uint16_t, char, IntType, FloatType> evaluator;
@@ -20,13 +21,15 @@ template<typename Result> constexpr bool evaluate_expected(std::string_view inpu
2021
return evaluator.evaluate_to<Result>(input).value() == result;
2122
}
2223

24+
2325
// Helper to check if an expression results in an error
2426
constexpr bool is_error(std::string_view input)
2527
{
2628
lefticus::cons_expr<std::uint16_t, char, IntType, FloatType> evaluator;
2729
auto result = evaluator.evaluate(input);
2830
return std::holds_alternative<lefticus::Error<std::uint16_t>>(result.value);
2931
}
32+
}
3033

3134
TEST_CASE("Cond expression basic usage", "[cond]")
3235
{

0 commit comments

Comments
 (0)