| #include <expected>
|
| #include <cmath>
|
|
|
| // for printf to not get warnings about std::print throwing...
|
| #include <cstdio>
|
|
|
| std::expected<int, int> squareRoot(int value)
|
| {
|
| if (value < 0)
|
| {
|
| return std::unexpected{0};
|
| } else {
|
| return std::sqrt(value);
|
| }
|
| }
|
|
|
| void sillySquareRootNoReturn(int value)
|
| {
|
| auto valueResult = squareRoot(value);
|
| if (not valueResult)
|
| {
|
| // NOLINTNEXTLINE(modernize-use-std-print)
|
| printf("Error: invalid value %d\n", value);
|
| return;
|
| }
|
|
|
| auto root = valueResult.value();
|
|
|
| // NOLINTNEXTLINE(modernize-use-std-print)
|
| printf("the square root of %d is %d\n", value, root);
|
| }
|
|
|
| int sillySquareRootWithReturn(int value)
|
| {
|
| auto valueResult = squareRoot(value);
|
| if (not valueResult)
|
| {
|
| // NOLINTNEXTLINE(modernize-use-std-print)
|
| printf("Error: invalid value %d\n", value);
|
| return 0;
|
| }
|
|
|
| return valueResult.value();
|
| }
|
|
|
| int main() {
|
| int value = -9;
|
|
|
| sillySquareRootNoReturn(value);
|
|
|
| // NOLINTNEXTLINE(modernize-use-std-print)
|
| printf("the square root of %d is %d\n", value, sillySquareRootWithReturn(value));
|
|
|
| return 0;
|
| }
|
| project(
|
| 'stupidtidy',
|
| 'cpp',
|
| meson_version : '>= 1.3.0',
|
| version : '0.1',
|
| default_options : ['warning_level=3', 'cpp_std=c++23'],
|
| license : 'MIT',
|
| )
|
|
|
| sources = ['stupidtidy.cpp']
|
|
|
| exe = executable(
|
| 'stupidtidy',
|
| [sources],
|
| dependencies : [],
|
| install : true,
|
| )
|
|
|
| test('basic', exe)
|
| # instructions:
|
| # meson setup build
|
| # meson compile -C build
|
| # ./build/stupidtidy
|
| # run-clang-tidy -p build
|
| ---
|
| Checks: 'clang-diagnostic-*,clang-analyzer-*,bugprone*'
|
| WarningsAsErrors: ''
|
| HeaderFileExtensions:
|
| - ''
|
| - h
|
| - hh
|
| - hpp
|
| - hxx
|
| ImplementationFileExtensions:
|
| - c
|
| - cc
|
| - cpp
|
| - cxx
|
| HeaderFilterRegex: ''
|
| FormatStyle: none
|
| CheckOptions:
|
| cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU'
|
| SystemHeaders: false
|
| ...
|
| ---
|
| Checks: 'clang-diagnostic-*,clang-analyzer-*,bugprone*'
|
| WarningsAsErrors: ''
|
| HeaderFileExtensions:
|
| - ''
|
| - h
|
| - hh
|
| - hpp
|
| - hxx
|
| ImplementationFileExtensions:
|
| - c
|
| - cc
|
| - cpp
|
| - cxx
|
| HeaderFilterRegex: ''
|
| FormatStyle: none
|
| CheckOptions:
|
| cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU'
|
| SystemHeaders: false
|
| ...
|