fix clang-tidy workflow and reported errors

This commit is contained in:
Joao Paulo Magalhaes
2025-01-12 21:17:13 +00:00
parent 6fbd63a856
commit ff35392ce4
31 changed files with 497 additions and 344 deletions

110
.clang-tidy Normal file
View File

@@ -0,0 +1,110 @@
Checks:
- '*' # enable everything
# but disable the following:
- -altera-id-dependent-backward-branch # backward branch (for loop) is ID-dependent due to variable reference to 'n' and may cause performance degradation
- -altera-struct-pack-align # accessing fields in struct 'base64_wrapper_<char>' is inefficient due to poor alignment; currently aligned to 8 bytes, but recommended alignment is 16 bytes
- -altera-unroll-loops # kernel performance could be improved by unrolling this loop with a '#pragma unroll' directive
- -bugprone-branch-clone # repeated branch body in conditional chain
- -bugprone-easily-swappable-parameters # 2 adjacent parameters of 'Tree' of similar type are easily swapped by mistake
- -bugprone-reserved-identifier # warnings on identifiers with leading _
- -bugprone-switch-missing-default-case # switching on non-enum value without default case may not cover all cases
- -cert-dcl37-c # warnings on identifiers with leading _
- -cert-dcl51-cpp # warnings on identifiers with leading _
- -cert-dcl59-cpp,fuchsia-header-anon-namespaces # do not use unnamed namespaces in header files
- -clang-analyzer-optin.core.EnumCastOutOfRange # The value '44' provided to the cast expression is not in the valid range of values for the enum
- -clang-diagnostic-pragma-system-header-outside-header # #pragma system_header ignored in main file
- -clang-diagnostic-unknown-warning-option # unknown compiler options
- -cppcoreguidelines-avoid-c-arrays # allow C arrays
- -cppcoreguidelines-avoid-do-while # avoid do-while loops
- -cppcoreguidelines-avoid-magic-numbers
- -cppcoreguidelines-avoid-non-const-global-variables # variable 's_default_callbacks' is non-const and globally accessible, consider making it const
- -cppcoreguidelines-init-variables # variable 'node' is not initialized
- -cppcoreguidelines-macro-to-enum # replace macro with enum
- -cppcoreguidelines-macro-usage # function-like macro 'c4append_' used; consider a 'constexpr' template function
- -cppcoreguidelines-no-malloc # do not manage memory manually; consider a container or a smart pointer
- -cppcoreguidelines-owning-memory # initializing non-owner 'void *' with a newly created 'gsl::owner<>'
- -cppcoreguidelines-pro-bounds-array-to-pointer-decay
- -cppcoreguidelines-pro-bounds-constant-array-index # do not use array subscript when the index is not an integer constant expression
- -cppcoreguidelines-pro-bounds-pointer-arithmetic # do not use pointer arithmetic
- -cppcoreguidelines-pro-type-cstyle-cast # do not use C-style cast to convert between unrelated types
- -cppcoreguidelines-pro-type-member-init # constructor does not initialize these fields: len
- -cppcoreguidelines-pro-type-vararg # do not call c-style vararg functions
- -cppcoreguidelines-use-default-member-init # use default member initializer for 'm_pos'
- -fuchsia-default-arguments-calls # calling a function that uses a default argument is disallowed
- -fuchsia-default-arguments-declarations # declaring a parameter with a default argument is disallowed
- -fuchsia-overloaded-operator # overloading 'operator[]' is disallowed
- -fuchsia-statically-constructed-objects # static objects are disallowed; if possible, use a constexpr constructor instead
- -fuchsia-trailing-return # a trailing return type is disallowed for this function declaration
- -google-build-namespaces # do not use unnamed namespaces in header files
- -google-build-using-namespace # do not use namespace using-directives; use using-declarations instead
- -google-explicit-constructor # single-argument constructors must be marked explicit to avoid unintentional implicit conversions
- -google-readability-braces-around-statements # statement should be inside braces
- -google-readability-casting # C-style casts are discouraged; use static_cast
- -google-readability-function-size # function '_handle_map_block' exceeds recommended size/complexity thresholds
- -google-readability-namespace-comments # anonymous namespace not terminated with a closing comment
- -google-readability-todo # missing username/bug in TODO
- -hicpp-avoid-c-arrays # allow C arrays
- -hicpp-braces-around-statements # statement should be inside braces
- -hicpp-deprecated-headers # inclusion of deprecated C++ header 'stdlib.h'; consider using 'cstdlib' instead
- -hicpp-explicit-conversions # single-argument constructors must be marked explicit to avoid unintentional implicit conversions
- -hicpp-function-size # function '_handle_map_block' exceeds recommended size/complexity thresholds
- -hicpp-member-init # constructor does not initialize these fields: len
- -hicpp-named-parameter # all parameters should be named in a function
- -hicpp-no-array-decay # do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead
- -hicpp-no-malloc # do not manage memory manually; consider a container or a smart pointer
- -hicpp-uppercase-literal-suffix # integer literal has suffix 'u', which is not uppercase
- -hicpp-use-auto,modernize-use-auto # use auto when initializing with a cast to avoid duplicating the type name
- -hicpp-vararg # do not call c-style vararg functions
- -llvm-else-after-return,readability-else-after-return # do not use 'else' after 'return'
- -llvm-header-guard # header guard does not follow preferred style
- -llvm-include-order # #includes are not sorted properly
- -llvm-namespace-comment # anonymous namespace not terminated with a closing comment
- -llvmlibc-callee-namespace # ... must resolve to a function declared within the namespace defined by the ... macro
- -llvmlibc-implementation-in-namespace # the outermost namespace should be the 'LIBC_NAMESPACE' macro
- -llvmlibc-inline-function-decl # '_is_idchar' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration
- -llvmlibc-restrict-system-libc-headers # system include stdlib.h not allowed
- -misc-const-correctness # variable 's2c' of type 'char' can be declared 'const'
- -misc-include-cleaner # no header providing ... is directly included
- -misc-no-recursion # function 'reserve' is within a recursive call chain
- -misc-non-private-member-variables-in-classes # member variable 'data' has public visibility
- -modernize-avoid-c-arrays # allow C arrays
- -modernize-concat-nested-namespaces # nested namespaces can be concatenated
- -modernize-deprecated-headers # inclusion of deprecated C++ header 'stdlib.h'; consider using 'cstdlib' instead
- -modernize-deprecated-headers # inclusion of deprecated C++ header 'stdlib.h'; consider using 'cstdlib' instead
- -modernize-loop-convert # use range-based for loop instead
- -modernize-macro-to-enum # replace macro with enum
- -modernize-return-braced-init-list # avoid repeating the return type from the declaration; use a braced initializer list instead
- -modernize-type-traits # use c++17 style variable templates
- -modernize-use-auto # use auto when initializing with a cast to avoid duplicating the type name
- -modernize-use-default-member-init # use default member initializer for 'm_pos'
- -modernize-use-nodiscard # function 'valid' should be marked nodiscard
- -modernize-use-trailing-return-type # don't care about this
- -modernize-use-using # use 'using' instead of 'typedef'
- -performance-enum-size # enum '_ppstate' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size
- -readability-avoid-nested-conditional-operator # conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators
- -readability-avoid-unconditional-preprocessor-if # preprocessor condition is always 'false', consider removing both the condition and its contents
- -readability-braces-around-statements # statement should be inside braces
- -readability-else-after-return # do not use 'else' after 'return'
- -readability-function-cognitive-complexity # function ... has cognitive complexity of ... (threshold ...)
- -readability-function-size # function '_handle_map_block' exceeds recommended size/complexity thresholds
- -readability-identifier-length # variable name 'c' is too short, expected at least 3 characters
- -readability-implicit-bool-conversion # implicit conversion 'NodeData *' -> 'bool'
- -readability-inconsistent-declaration-parameter-name # definition with different parameter names
- -readability-isolate-declaration # multiple declarations in a single statement reduces readability
- -readability-magic-numbers # 16 is a magic number; consider replacing it with a named constant
- -readability-named-parameter # all parameters should be named in a function
- -readability-redundant-access-specifiers # redundant access specifier has the same accessibility as the previous access specifier
- -readability-redundant-member-init # initializer for member 'm_arena' is redundant
- -readability-simplify-boolean-expr # boolean expression can be simplified by DeMorgan's theorem
- -readability-suspicious-call-argument # 1st argument 'after' (passed to 'node') looks like it might be swapped with the 2nd, 'node' (passed to 'sib')
- -readability-uppercase-literal-suffix # integer literal has suffix 'u', which is not uppercase
- -readability-use-anyofallof # replace loop by 'std::all_of()'
# Turn all the warnings from the checks above into errors.
WarningsAsErrors: '*'
#CheckOptions:
# - { key: readability-identifier-naming.ClassCase, value: CamelCase }
# - { key: readability-identifier-naming.MethodCase, value: CamelCase }
# - { key: readability-identifier-naming.MemberPrefix, value: m_ }
# - { key: readability-identifier-naming.MemberCase, value: lower_case }

View File

@@ -494,6 +494,7 @@ jobs:
-DCMAKE_C_COMPILER=clang-${{matrix.cxx}} \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS_DEBUG="-m${{matrix.bits}}" \
-DCMAKE_C_FLAGS_DEBUG="-m${{matrix.bits}}" \
-DC4_CXX_STANDARD=${{matrix.std}} \
-DRYML_CXX_STANDARD=${{matrix.std}} \
-DRYML_BUILD_TESTS=ON \
@@ -519,6 +520,7 @@ jobs:
-DCMAKE_C_COMPILER=clang-${{matrix.cxx}} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS_RELEASE="-O1 -DNDEBUG -m${{matrix.bits}}" \
-DCMAKE_C_FLAGS_RELEASE="-O1 -DNDEBUG -m${{matrix.bits}}" \
-DC4_CXX_STANDARD=${{matrix.std}} \
-DRYML_CXX_STANDARD=${{matrix.std}} \
-DRYML_BUILD_TESTS=ON \
@@ -544,6 +546,7 @@ jobs:
-DCMAKE_C_COMPILER=clang-${{matrix.cxx}} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS_RELEASE="-O2 -DNDEBUG -m${{matrix.bits}}" \
-DCMAKE_C_FLAGS_RELEASE="-O2 -DNDEBUG -m${{matrix.bits}}" \
-DC4_CXX_STANDARD=${{matrix.std}} \
-DRYML_CXX_STANDARD=${{matrix.std}} \
-DRYML_BUILD_TESTS=ON \
@@ -569,6 +572,7 @@ jobs:
-DCMAKE_C_COMPILER=clang-${{matrix.cxx}} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG -m${{matrix.bits}}" \
-DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG -m${{matrix.bits}}" \
-DC4_CXX_STANDARD=${{matrix.std}} \
-DRYML_CXX_STANDARD=${{matrix.std}} \
-DRYML_BUILD_TESTS=ON \
@@ -594,6 +598,7 @@ jobs:
-DCMAKE_C_COMPILER=clang-${{matrix.cxx}} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS_RELEASE="-Os -DNDEBUG -m${{matrix.bits}}" \
-DCMAKE_C_FLAGS_RELEASE="-Os -DNDEBUG -m${{matrix.bits}}" \
-DC4_CXX_STANDARD=${{matrix.std}} \
-DRYML_CXX_STANDARD=${{matrix.std}} \
-DRYML_BUILD_TESTS=ON \

View File

@@ -21,53 +21,17 @@ jobs:
clang_tidy:
if: always()
continue-on-error: false
name: clang_tidy/c++${{matrix.std}}/${{matrix.bt}}
runs-on: ubuntu-24.04
container: ghcr.io/biojppm/c4core/ubuntu22.04:latest
name: clang_tidy/c++${{matrix.std}}/${{matrix.bt}}
strategy:
fail-fast: false
matrix:
include:
- std: 11
cxx: clang++-17
clang: 18
bt: Debug
lint: clang-tidy
bitlinks: shared64
- std: 11
cxx: clang++-17
bt: Debug
lint: clang-tidy
bitlinks: shared32
- std: 11
cxx: clang++-17
bt: Debug
lint: clang-tidy
bitlinks: static64
- std: 11
cxx: clang++-17
bt: Debug
lint: clang-tidy
bitlinks: static32
- std: 11
cxx: clang++-17
bt: ReleaseWithDebInfo
lint: clang-tidy
bitlinks: shared64
- std: 11
cxx: clang++-17
bt: ReleaseWithDebInfo
lint: clang-tidy
bitlinks: shared32
- std: 11
cxx: clang++-17
bt: ReleaseWithDebInfo
lint: clang-tidy
bitlinks: static64
- std: 11
cxx: clang++-17
bt: ReleaseWithDebInfo
lint: clang-tidy
bitlinks: static32
bits: 64
env:
STD: ${{matrix.std}}
CXX_: ${{matrix.cxx}}
@@ -84,38 +48,20 @@ jobs:
submodules: recursive
fetch-depth: 0
- run: git config --system --add safe.directory '*'
- run: c4core-install ${{matrix.cxx}}
- name: show info
run: source .github/setenv.sh && c4_show_info
- name: shared64-configure---------------------------------------------------
run: source .github/setenv.sh && c4_cfg_test shared64
- name: shared64-build
run: source .github/setenv.sh && c4_build_test shared64
- name: shared64-run
run: source .github/setenv.sh && c4_run_test shared64
- name: shared64-pack
run: source .github/setenv.sh && c4_package shared64
- name: static64-configure---------------------------------------------------
run: source .github/setenv.sh && c4_cfg_test static64
- name: static64-build
run: source .github/setenv.sh && c4_build_test static64
- name: static64-run
run: source .github/setenv.sh && c4_run_test static64
- name: static64-pack
run: source .github/setenv.sh && c4_package static64
- name: static32-configure---------------------------------------------------
run: source .github/setenv.sh && c4_cfg_test static32
- name: static32-build
run: source .github/setenv.sh && c4_build_test static32
- name: static32-run
run: source .github/setenv.sh && c4_run_test static32
- name: static32-pack
run: source .github/setenv.sh && c4_package static32
- name: shared32-configure---------------------------------------------------
run: source .github/setenv.sh && c4_cfg_test shared32
- name: shared32-build
run: source .github/setenv.sh && c4_build_test shared32
- name: shared32-run
run: source .github/setenv.sh && c4_run_test shared32
- name: shared32-pack
run: source .github/setenv.sh && c4_package shared32
- name: install
run: c4core-install clang++-${{matrix.clang}}
- name: configure
run: |
cmake -S . -B build \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_CXX_COMPILER=clang++-${{matrix.clang}} \
-DCMAKE_C_COMPILER=clang-${{matrix.clang}} \
-DCLANG_TIDY=/usr/bin/clang-tidy-${{matrix.clang}} \
-DCMAKE_BUILD_TYPE=${{matrix.bt}} \
-DRYML_DEV=ON \
-DRYML_VALGRIND=OFF \
-DRYML_BUILD_TESTS=OFF \
-DRYML_BUILD_BENCHMARKS=OFF \
-DRYML_DBG=OFF
- name: clang-tidy
run: cmake --build build --target ryml-clang-tidy --verbose

View File

@@ -5,21 +5,30 @@
jobs:
clang_tidy:
:: setup-job('clang_tidy' 'clang_tidy')
:: setup-job('clang_tidy' 'clang_tidy') + runs-on-docker-c4core('22.04')
name: clang_tidy/c++${{matrix.std}}/${{matrix.bt}}
:: runs-on-docker-c4core('22.04')
strategy:
fail-fast: false
matrix:
include::
? for
bt qw(Debug ReleaseWithDebInfo)
bl qw(shared64 shared32 static64 static32)
: !
std: 11
cxx: clang++-17
bt:: bt
lint: clang-tidy
bitlinks:: bl
include:
- {std: 11, clang: 18, bt: Debug, bits: 64}
env:: load('share/env.yaml')
steps:: checkout-action-docker + install-cxx + run-steps
steps:
- :: checkout-action-docker
- name: install
run: c4core-install clang++-${{matrix.clang}}
- name: configure
run: |
cmake -S . -B build \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_CXX_COMPILER=clang++-${{matrix.clang}} \
-DCMAKE_C_COMPILER=clang-${{matrix.clang}} \
-DCLANG_TIDY=/usr/bin/clang-tidy-${{matrix.clang}} \
-DCMAKE_BUILD_TYPE=${{matrix.bt}} \
-DRYML_DEV=ON \
-DRYML_VALGRIND=OFF \
-DRYML_BUILD_TESTS=OFF \
-DRYML_BUILD_BENCHMARKS=OFF \
-DRYML_DBG=OFF
- name: clang-tidy
run: cmake --build build --target ryml-clang-tidy --verbose

View File

@@ -735,6 +735,7 @@ jobs:
-DCMAKE_C_COMPILER=gcc-${{matrix.cxx}} \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS_DEBUG="-m${{matrix.bits}}" \
-DCMAKE_C_FLAGS_DEBUG="-m${{matrix.bits}}" \
-DC4_CXX_STANDARD=${{matrix.std}} \
-DRYML_CXX_STANDARD=${{matrix.std}} \
-DRYML_BUILD_TESTS=ON \
@@ -760,6 +761,7 @@ jobs:
-DCMAKE_C_COMPILER=gcc-${{matrix.cxx}} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS_RELEASE="-O1 -DNDEBUG -m${{matrix.bits}}" \
-DCMAKE_C_FLAGS_RELEASE="-O1 -DNDEBUG -m${{matrix.bits}}" \
-DC4_CXX_STANDARD=${{matrix.std}} \
-DRYML_CXX_STANDARD=${{matrix.std}} \
-DRYML_BUILD_TESTS=ON \
@@ -785,6 +787,7 @@ jobs:
-DCMAKE_C_COMPILER=gcc-${{matrix.cxx}} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS_RELEASE="-O2 -DNDEBUG -m${{matrix.bits}}" \
-DCMAKE_C_FLAGS_RELEASE="-O2 -DNDEBUG -m${{matrix.bits}}" \
-DC4_CXX_STANDARD=${{matrix.std}} \
-DRYML_CXX_STANDARD=${{matrix.std}} \
-DRYML_BUILD_TESTS=ON \
@@ -810,6 +813,7 @@ jobs:
-DCMAKE_C_COMPILER=gcc-${{matrix.cxx}} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG -m${{matrix.bits}}" \
-DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG -m${{matrix.bits}}" \
-DC4_CXX_STANDARD=${{matrix.std}} \
-DRYML_CXX_STANDARD=${{matrix.std}} \
-DRYML_BUILD_TESTS=ON \
@@ -835,6 +839,7 @@ jobs:
-DCMAKE_C_COMPILER=gcc-${{matrix.cxx}} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS_RELEASE="-Os -DNDEBUG -m${{matrix.bits}}" \
-DCMAKE_C_FLAGS_RELEASE="-Os -DNDEBUG -m${{matrix.bits}}" \
-DC4_CXX_STANDARD=${{matrix.std}} \
-DRYML_CXX_STANDARD=${{matrix.std}} \
-DRYML_BUILD_TESTS=ON \

View File

@@ -186,3 +186,38 @@ jobs:
run: source .github/setenv.sh && c4_run_test arm
- name: pack
run: source .github/setenv.sh && c4_package arm
#----------------------------------------------------------------------------
#analyzer:
# :: setup-job('gcc' 'analyzer')
# name: analyzer/${{matrix.bits}}bit/${{matrix.bt}}
# :: runs-on-docker-c4core('${{matrix.img}}')
# strategy:
# fail-fast: false
# matrix:
# include:
# - {std: 11, gcc: 14, bits: 64, bt: Debug , img: 22.04}
# - {std: 11, gcc: 14, bits: 64, bt: Release, img: 22.04}
# - {std: 11, gcc: 14, bits: 32, bt: Debug , img: 22.04}
# - {std: 11, gcc: 14, bits: 32, bt: Release, img: 22.04}
# steps:
# - :: checkout-action-docker
# - name: install
# run: c4core-install g++-${{matrix.gcc}}
# - name: configure
# run: |
# cmake -S . -B build \
# -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
# -DCMAKE_GCC_COMPILER=g++-${{matrix.gcc}} \
# -DCMAKE_C_COMPILER=gcc-${{matrix.gcc}} \
# -DCMAKE_BUILD_TYPE=${{matrix.bt}} \
# -DRYML_DEV=ON \
# -DRYML_VALGRIND=OFF \
# -DRYML_BUILD_TESTS=ON \
# -DRYML_BUILD_BENCHMARKS=OFF \
# -DRYML_DBG=OFF \
# -DRYML_FANALYZER=ON
# - name: build
# run: cmake --build build --target ryml-test-build --parallel --verbose
# - name: run
# run: cmake --build build --target ryml-test-run --verbose

View File

@@ -278,6 +278,7 @@ defn run-manual-with-flags(cxx cc buildtype flags="")::
-DCMAKE_C_COMPILER=$cc-${{matrix.cxx}} \
-DCMAKE_BUILD_TYPE=$buildtype \
-DCMAKE_CXX_FLAGS_$(buildtype:uc)="$flags" \
-DCMAKE_C_FLAGS_$(buildtype:uc)="$flags" \
-DC4_CXX_STANDARD=${{matrix.std}} \
-DRYML_CXX_STANDARD=${{matrix.std}} \
-DRYML_BUILD_TESTS=ON \

View File

@@ -20,7 +20,7 @@ endif()
option(RYML_USE_ASSERT "Enable assertions regardless of build type. Default is only when NDEBUG is not defined (which is in release builds). This causes a slowdown of the code." OFF)
option(RYML_BUILD_TOOLS "Build tools" OFF)
option(RYML_BUILD_API "Enable API generation (python, etc)" OFF)
option(RYML_DBG "Enable (very verbose) ryml debug prints." OFF)
option(RYML_DBG "Enable (very verbose) debug prints." OFF)
option(RYML_INSTALL "Enable install target" ON)
@@ -123,7 +123,6 @@ endif()
#-------------------------------------------------------
# developer targets
# extern libraries, used only for testing/benchmarking
if(RYML_BUILD_TESTS OR RYML_BUILD_BENCHMARKS OR RYML_BUILD_TOOLS)
include(ext/testbm.cmake)
@@ -138,3 +137,33 @@ c4_add_dev_targets()
add_custom_target(ryml-uninstall
"${CMAKE_COMMAND}" -P "${PROJECT_SOURCE_DIR}/cmake/uninstall.cmake"
)
#-------------------------------------------------------
# clang-tidy
function(ryml_setup_clang_tidy rootdir)
get_target_property(srcs ryml SOURCES)
string(REPLACE "${rootdir}/" "./" srcs "${srcs}")
set(exclude ./ext/.* parse_engine.def.hpp .natvis)
foreach(e ${exclude})
list(FILTER srcs EXCLUDE REGEX ${e})
endforeach()
set(cmd ${srcs} -p ${CMAKE_BINARY_DIR}
"--config-file=${rootdir}/.clang-tidy"
"--header-filter=${rootdir}/src/.*")
add_custom_target(ryml-clang-tidy
COMMAND ${CMAKE_COMMAND} -E cat ${CMAKE_BINARY_DIR}/compile_commands.json
COMMAND ${CLANG_TIDY} --version
COMMAND ${CLANG_TIDY} ${cmd} --dump-config
COMMAND ${CLANG_TIDY} ${cmd} --list-checks
COMMAND ${CLANG_TIDY} ${cmd}
WORKING_DIRECTORY ${rootdir}
VERBATIM
)
endfunction()
find_program(CLANG_TIDY clang-tidy)
if(CLANG_TIDY)
ryml_setup_clang_tidy(${CMAKE_CURRENT_LIST_DIR})
endif()

View File

@@ -30,20 +30,20 @@ void report_error_impl(const char* msg, size_t length, Location loc, FILE *f)
{
// this is more portable than using fprintf("%.*s:") which
// is not available in some embedded platforms
fwrite(loc.name.str, 1, loc.name.len, f);
fputc(':', f);
fwrite(loc.name.str, 1, loc.name.len, f); // NOLINT
fputc(':', f); // NOLINT
}
fprintf(f, "%zu:", loc.line);
fprintf(f, "%zu:", loc.line); // NOLINT
if(loc.col)
fprintf(f, "%zu:", loc.col);
fprintf(f, "%zu:", loc.col); // NOLINT
if(loc.offset)
fprintf(f, " (%zuB):", loc.offset);
fputc(' ', f);
fprintf(f, " (%zuB):", loc.offset); // NOLINT
fputc(' ', f); // NOLINT
}
RYML_ASSERT(!csubstr(msg, length).ends_with('\0'));
fwrite(msg, 1, length, f);
fputc('\n', f);
fflush(f);
fwrite(msg, 1, length, f); // NOLINT
fputc('\n', f); // NOLINT
fflush(f); // NOLINT
}
[[noreturn]] void error_impl(const char* msg, size_t length, Location loc, void * /*user_data*/)
@@ -76,7 +76,7 @@ void free_impl(void *mem, size_t /*length*/, void * /*user_data*/)
Callbacks::Callbacks()
Callbacks::Callbacks() noexcept
:
m_user_data(nullptr),
#ifndef RYML_NO_DEFAULT_CALLBACKS

View File

@@ -304,7 +304,7 @@ struct RYML_EXPORT Location
csubstr name;
operator bool () const { return !name.empty() || line != 0 || offset != 0 || col != 0; }
operator LineCol const& () const { return reinterpret_cast<LineCol const&>(*this); }
operator LineCol const& () const { return reinterpret_cast<LineCol const&>(*this); } // NOLINT
Location() = default;
Location( size_t l, size_t c) : offset( ), line(l), col(c), name( ) {}
@@ -381,7 +381,7 @@ struct RYML_EXPORT Callbacks
/** Construct an object with the default callbacks. If
* @ref RYML_NO_DEFAULT_CALLBACKS is defined, the object will have null
* members.*/
Callbacks();
Callbacks() noexcept;
/** Construct an object with the given callbacks.
*
@@ -499,7 +499,7 @@ struct FilterResult
{
C4_ALWAYS_INLINE bool valid() const noexcept { return str.str != nullptr; }
C4_ALWAYS_INLINE size_t required_len() const noexcept { return str.len; }
C4_ALWAYS_INLINE csubstr get() { RYML_ASSERT(valid()); return str; }
C4_ALWAYS_INLINE csubstr get() const { RYML_ASSERT(valid()); return str; }
csubstr str;
};
/** Abstracts the fact that a scalar filter result may not fit in the
@@ -508,7 +508,7 @@ struct FilterResultExtending
{
C4_ALWAYS_INLINE bool valid() const noexcept { return str.str != nullptr; }
C4_ALWAYS_INLINE size_t required_len() const noexcept { return reqlen; }
C4_ALWAYS_INLINE csubstr get() { RYML_ASSERT(valid()); return str; }
C4_ALWAYS_INLINE csubstr get() const { RYML_ASSERT(valid()); return str; }
csubstr str;
size_t reqlen;
};
@@ -567,7 +567,7 @@ struct _SubstrWriter
//! get the part written so far
csubstr curr() const { return pos <= buf.len ? buf.first(pos) : buf; }
//! get the part that is still free to write to (the remainder)
substr rem() { return pos < buf.len ? buf.sub(pos) : buf.last(0); }
substr rem() const { return pos < buf.len ? buf.sub(pos) : buf.last(0); }
size_t advance(size_t more) { pos += more; return pos; }
};

View File

@@ -30,7 +30,7 @@ inline void check_invariants(Tree const& t, id_type node)
{
if(node == NONE)
{
if(t.size() == 0) return;
if(t.empty()) return;
node = t.root_id();
}

View File

@@ -13,19 +13,15 @@
//-----------------------------------------------------------------------------
// some debugging scaffolds
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4068/*unknown pragma*/)
#endif
// NOLINTBEGIN(*)
C4_SUPPRESS_WARNING_GCC_CLANG_PUSH
C4_SUPPRESS_WARNING_MSVC_PUSH
C4_SUPPRESS_WARNING_MSVC(4068/*unknown pragma*/)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
//#pragma GCC diagnostic ignored "-Wpragma-system-header-outside-header"
#pragma GCC system_header
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Werror"
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
C4_SUPPRESS_WARNING_GCC("-Wunknown-pragmas")
C4_SUPPRESS_WARNING_CLANG("-Wgnu-zero-variadic-macro-arguments")
// NOLINTEND(*)
#ifndef RYML_DBG
@@ -89,7 +85,7 @@ C4_NO_INLINE void _dbg_printf(c4::csubstr fmt, Args const& ...args)
C4_CHECK(needed_size <= buf.len);
}
}
inline void __c4presc(const char *s, size_t len, bool keep_newlines=false)
inline C4_NO_INLINE void __c4presc(const char *s, size_t len, bool keep_newlines=false)
{
RYML_ASSERT(s || !len);
size_t prev = 0;
@@ -145,11 +141,7 @@ inline void __c4presc(csubstr s, bool keep_newlines=false)
#endif // RYML_DBG
#pragma clang diagnostic pop
#pragma GCC diagnostic pop
#if defined(_MSC_VER)
# pragma warning(pop)
#endif
C4_SUPPRESS_WARNING_GCC_CLANG_POP
C4_SUPPRESS_WARNING_MSVC_POP
#endif /* _C4_YML_DETAIL_PARSER_DBG_HPP_ */

View File

@@ -69,9 +69,12 @@ public:
stack& operator= (stack const& that) RYML_NOEXCEPT
{
_cb(that.m_callbacks);
resize(that.m_size);
_cp(&that);
if(&that != this)
{
_cb(that.m_callbacks);
resize(that.m_size);
_cp(&that);
}
return *this;
}

View File

@@ -717,7 +717,7 @@ again:
_rymlindent_nextline();
this->Writer::_do_write(s.range(i, pos));
i = pos;
goto again;
goto again; // NOLINT
}
// consume the newlines after the indented block
// to prevent them from being escaped
@@ -898,7 +898,7 @@ void Emitter<Writer>::_write_scalar_dquo(csubstr s, id_type ilevel)
for(size_t i = 0; i < s.len; ++i)
{
const char curr = s.str[i];
switch(curr)
switch(curr) // NOLINT
{
case '"':
case '\\':

View File

@@ -75,9 +75,9 @@ typedef enum {
struct EmitOptions
{
typedef enum : uint32_t {
DEFAULT_FLAGS = 0,
JSON_ERR_ON_TAG = 1 << 0,
JSON_ERR_ON_ANCHOR = 1 << 1,
DEFAULT_FLAGS = 0u,
JSON_ERR_ON_TAG = 1u << 0u,
JSON_ERR_ON_ANCHOR = 1u << 1u,
_JSON_ERR_MASK = JSON_ERR_ON_TAG|JSON_ERR_ON_ANCHOR,
} EmitOptionFlags_e;
@@ -896,6 +896,6 @@ C4_SUPPRESS_WARNING_GCC_CLANG_POP
#undef RYML_DEPRECATE_EMIT
#undef RYML_DEPRECATE_EMITRS
#include "c4/yml/emit.def.hpp"
#include "c4/yml/emit.def.hpp" // NOLINT
#endif /* _C4_YML_EMIT_HPP_ */

View File

@@ -5,6 +5,10 @@
#include "c4/yml/detail/stack.hpp"
#endif
#ifndef _C4_YML_NODE_TYPE_HPP_
#include "c4/yml/node_type.hpp"
#endif
#ifndef _C4_YML_DETAIL_PARSER_DBG_HPP_
#include "c4/yml/detail/parser_dbg.hpp"
#endif
@@ -19,6 +23,8 @@
#endif
#endif
// NOLINTBEGIN(hicpp-signed-bitwise)
namespace c4 {
namespace yml {
@@ -183,4 +189,6 @@ protected:
} // namespace yml
} // namespace c4
// NOLINTEND(hicpp-signed-bitwise)
#endif /* _C4_YML_EVENT_HANDLER_STACK_HPP_ */

View File

@@ -10,6 +10,7 @@
#endif
C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4702) // unreachable code
// NOLINTBEGIN(hicpp-signed-bitwise)
namespace c4 {
namespace yml {
@@ -663,7 +664,7 @@ public:
public:
C4_ALWAYS_INLINE void _set_state_(state *C4_RESTRICT s, id_type id) noexcept
C4_ALWAYS_INLINE void _set_state_(state *C4_RESTRICT s, id_type id) const noexcept
{
s->node_id = id;
s->tr_data = m_tree->_p(id);
@@ -710,7 +711,7 @@ public:
{
_c4dbgp("remove speculative node");
_RYML_CB_ASSERT(m_stack.m_callbacks, m_tree);
_RYML_CB_ASSERT(m_tree->callbacks(), m_tree->size() > 0);
_RYML_CB_ASSERT(m_tree->callbacks(), !m_tree->empty());
const id_type last_added = m_tree->size() - 1;
if(m_tree->has_parent(last_added))
if(m_tree->_p(last_added)->m_type == NOTYPE)
@@ -720,7 +721,7 @@ public:
void _remove_speculative_with_parent()
{
_RYML_CB_ASSERT(m_stack.m_callbacks, m_tree);
_RYML_CB_ASSERT(m_tree->callbacks(), m_tree->size() > 0);
_RYML_CB_ASSERT(m_tree->callbacks(), !m_tree->empty());
const id_type last_added = m_tree->size() - 1;
_RYML_CB_ASSERT(m_tree->callbacks(), m_tree->has_parent(last_added));
if(m_tree->_p(last_added)->m_type == NOTYPE)
@@ -749,6 +750,7 @@ public:
} // namespace yml
} // namespace c4
// NOLINTEND(hicpp-signed-bitwise)
C4_SUPPRESS_WARNING_MSVC_POP
#endif /* _C4_YML_EVENT_HANDLER_TREE_HPP_ */

View File

@@ -63,7 +63,7 @@ struct FilterProcessorSrcDst
C4_ALWAYS_INLINE void skip() noexcept { ++rpos; }
C4_ALWAYS_INLINE void skip(size_t num) noexcept { rpos += num; }
C4_ALWAYS_INLINE void set_at(size_t pos, char c) noexcept
C4_ALWAYS_INLINE void set_at(size_t pos, char c) noexcept // NOLINT(readability-make-member-function-const)
{
RYML_ASSERT(pos < wpos);
dst.str[pos] = c;

View File

@@ -36,7 +36,7 @@ namespace yml {
*
* @{
*/
template<class K> struct Key { K & k; };
template<class K> struct Key { K & k; }; // NOLINT
template<> struct Key<fmt::const_base64_wrapper> { fmt::const_base64_wrapper wrapper; };
template<> struct Key<fmt::base64_wrapper> { fmt::base64_wrapper wrapper; };
@@ -101,11 +101,11 @@ struct children_view_
n_iterator b, e;
inline children_view_(n_iterator const& C4_RESTRICT b_,
children_view_(n_iterator const& C4_RESTRICT b_,
n_iterator const& C4_RESTRICT e_) : b(b_), e(e_) {}
inline n_iterator begin() const { return b; }
inline n_iterator end () const { return e; }
n_iterator begin() const { return b; }
n_iterator end () const { return e; }
};
template<class NodeRefType, class Visitor>
@@ -832,7 +832,7 @@ public:
*
* @warning The lifetime of the tree must be larger than that of this
* object. It is up to the user to ensure that this happens. */
class RYML_EXPORT ConstNodeRef : public detail::RoNodeMethods<ConstNodeRef, ConstNodeRef>
class RYML_EXPORT ConstNodeRef : public detail::RoNodeMethods<ConstNodeRef, ConstNodeRef> // NOLINT
{
public:
@@ -860,8 +860,8 @@ public:
ConstNodeRef(ConstNodeRef const&) noexcept = default;
ConstNodeRef(ConstNodeRef &&) noexcept = default;
ConstNodeRef(NodeRef const&) noexcept;
ConstNodeRef(NodeRef &&) noexcept;
inline ConstNodeRef(NodeRef const&) noexcept;
inline ConstNodeRef(NodeRef &&) noexcept;
/** @} */
@@ -935,6 +935,8 @@ public:
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// NOLINTBEGIN(cppcoreguidelines-c-copy-assignment-signature,misc-unconventional-assign-operator)
/** A reference to a node in an existing yaml tree, offering a more
* convenient API than the index-based API used in the tree.
*
@@ -971,7 +973,7 @@ public:
* @warning The lifetime of the tree must be larger than that of this
* object. It is up to the user to ensure that this happens.
*/
class RYML_EXPORT NodeRef : public detail::RoNodeMethods<NodeRef, ConstNodeRef>
class RYML_EXPORT NodeRef : public detail::RoNodeMethods<NodeRef, ConstNodeRef> // NOLINT
{
public:
@@ -1020,7 +1022,7 @@ public:
NodeRef(Tree *t, id_type id, csubstr seed_key) noexcept : m_tree(t), m_id(id), m_seed(seed_key) {}
NodeRef(std::nullptr_t) noexcept : m_tree(nullptr), m_id(NONE), m_seed() {}
inline void _clear_seed() noexcept { /*do the following manually or an assert is triggered: */ m_seed.str = nullptr; m_seed.len = npos; }
void _clear_seed() noexcept { /*do the following manually or an assert is triggered: */ m_seed.str = nullptr; m_seed.len = npos; }
/** @} */
@@ -1043,11 +1045,11 @@ public:
* @{ */
/** true if the object is not referring to any existing or seed node. @see the doc for @ref NodeRef */
inline bool invalid() const noexcept { return m_tree == nullptr || m_id == NONE; }
bool invalid() const noexcept { return m_tree == nullptr || m_id == NONE; }
/** true if the object is not invalid and in seed state. @see the doc for @ref NodeRef */
inline bool is_seed() const noexcept { return (m_tree != NULL && m_id != NONE) && (m_seed.str != nullptr || m_seed.len != (size_t)NONE); }
bool is_seed() const noexcept { return (m_tree != nullptr && m_id != NONE) && (m_seed.str != nullptr || m_seed.len != (size_t)NONE); }
/** true if the object is not invalid and not in seed state. @see the doc for @ref NodeRef */
inline bool readable() const noexcept { return (m_tree != NULL && m_id != NONE) && (m_seed.str == nullptr && m_seed.len == (size_t)NONE); }
bool readable() const noexcept { return (m_tree != nullptr && m_id != NONE) && (m_seed.str == nullptr && m_seed.len == (size_t)NONE); }
RYML_DEPRECATED("use one of readable(), is_seed() or !invalid()") inline bool valid() const { return m_tree != nullptr && m_id != NONE; }
@@ -1076,10 +1078,10 @@ public:
}
return false;
}
inline bool operator!= (NodeRef const& that) const { return ! this->operator==(that); }
bool operator!= (NodeRef const& that) const { return ! this->operator==(that); }
inline bool operator== (ConstNodeRef const& that) const { return m_tree == that.m_tree && m_id == that.m_id && !is_seed(); }
inline bool operator!= (ConstNodeRef const& that) const { return ! this->operator==(that); }
bool operator== (ConstNodeRef const& that) const { return m_tree == that.m_tree && m_id == that.m_id && !is_seed(); }
bool operator!= (ConstNodeRef const& that) const { return ! this->operator==(that); }
/** @cond dev */
RYML_DEPRECATED("use !readable()") bool operator== (std::nullptr_t) const { return m_tree == nullptr || m_id == NONE || is_seed(); }
@@ -1126,7 +1128,7 @@ public:
public:
inline void clear()
void clear()
{
if(is_seed())
return;
@@ -1134,65 +1136,65 @@ public:
m_tree->_clear(m_id);
}
inline void clear_key()
void clear_key()
{
if(is_seed())
return;
m_tree->_clear_key(m_id);
}
inline void clear_val()
void clear_val()
{
if(is_seed())
return;
m_tree->_clear_val(m_id);
}
inline void clear_children()
void clear_children()
{
if(is_seed())
return;
m_tree->remove_children(m_id);
}
inline void operator= (NodeType_e t)
void operator= (NodeType_e t)
{
_apply_seed();
m_tree->_add_flags(m_id, t);
}
inline void operator|= (NodeType_e t)
void operator|= (NodeType_e t)
{
_apply_seed();
m_tree->_add_flags(m_id, t);
}
inline void operator= (NodeInit const& v)
void operator= (NodeInit const& v)
{
_apply_seed();
_apply(v);
}
inline void operator= (NodeScalar const& v)
void operator= (NodeScalar const& v)
{
_apply_seed();
_apply(v);
}
inline void operator= (std::nullptr_t)
void operator= (std::nullptr_t)
{
_apply_seed();
_apply(csubstr{});
}
inline void operator= (csubstr v)
void operator= (csubstr v)
{
_apply_seed();
_apply(v);
}
template<size_t N>
inline void operator= (const char (&v)[N])
void operator= (const char (&v)[N])
{
_apply_seed();
csubstr sv;
@@ -1209,7 +1211,7 @@ public:
/** serialize a variable to the arena */
template<class T>
inline csubstr to_arena(T const& C4_RESTRICT s)
csubstr to_arena(T const& C4_RESTRICT s)
{
RYML_ASSERT(m_tree); // no need for valid or readable
return m_tree->to_arena(s);
@@ -1255,7 +1257,7 @@ public:
size_t set_val_serialized(fmt::const_base64_wrapper w);
/** serialize a variable, then assign the result to the node's val */
inline NodeRef& operator<< (csubstr s)
NodeRef& operator<< (csubstr s)
{
// this overload is needed to prevent ambiguity (there's also
// operator<< for writing a substr to a stream)
@@ -1266,7 +1268,7 @@ public:
}
template<class T>
inline NodeRef& operator<< (T const& C4_RESTRICT v)
NodeRef& operator<< (T const& C4_RESTRICT v)
{
_apply_seed();
write(this, v);
@@ -1275,7 +1277,7 @@ public:
/** serialize a variable, then assign the result to the node's key */
template<class T>
inline NodeRef& operator<< (Key<const T> const& C4_RESTRICT v)
NodeRef& operator<< (Key<const T> const& C4_RESTRICT v)
{
_apply_seed();
set_key_serialized(v.k);
@@ -1284,7 +1286,7 @@ public:
/** serialize a variable, then assign the result to the node's key */
template<class T>
inline NodeRef& operator<< (Key<T> const& C4_RESTRICT v)
NodeRef& operator<< (Key<T> const& C4_RESTRICT v)
{
_apply_seed();
set_key_serialized(v.k);
@@ -1330,17 +1332,17 @@ private:
}
}
inline void _apply(csubstr v)
void _apply(csubstr v)
{
m_tree->_set_val(m_id, v);
}
inline void _apply(NodeScalar const& v)
void _apply(NodeScalar const& v)
{
m_tree->_set_val(m_id, v);
}
inline void _apply(NodeInit const& i)
void _apply(NodeInit const& i)
{
m_tree->_set(m_id, i);
}
@@ -1350,7 +1352,7 @@ public:
/** @name modification of hierarchy */
/** @{ */
inline NodeRef insert_child(NodeRef after)
NodeRef insert_child(NodeRef after)
{
_C4RR();
_RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
@@ -1358,7 +1360,7 @@ public:
return r;
}
inline NodeRef insert_child(NodeInit const& i, NodeRef after)
NodeRef insert_child(NodeInit const& i, NodeRef after)
{
_C4RR();
_RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
@@ -1367,14 +1369,14 @@ public:
return r;
}
inline NodeRef prepend_child()
NodeRef prepend_child()
{
_C4RR();
NodeRef r(m_tree, m_tree->insert_child(m_id, NONE));
return r;
}
inline NodeRef prepend_child(NodeInit const& i)
NodeRef prepend_child(NodeInit const& i)
{
_C4RR();
NodeRef r(m_tree, m_tree->insert_child(m_id, NONE));
@@ -1382,14 +1384,14 @@ public:
return r;
}
inline NodeRef append_child()
NodeRef append_child()
{
_C4RR();
NodeRef r(m_tree, m_tree->append_child(m_id));
return r;
}
inline NodeRef append_child(NodeInit const& i)
NodeRef append_child(NodeInit const& i)
{
_C4RR();
NodeRef r(m_tree, m_tree->append_child(m_id));
@@ -1397,7 +1399,7 @@ public:
return r;
}
inline NodeRef insert_sibling(ConstNodeRef const& after)
NodeRef insert_sibling(ConstNodeRef const& after)
{
_C4RR();
_RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
@@ -1405,7 +1407,7 @@ public:
return r;
}
inline NodeRef insert_sibling(NodeInit const& i, ConstNodeRef const& after)
NodeRef insert_sibling(NodeInit const& i, ConstNodeRef const& after)
{
_C4RR();
_RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
@@ -1414,14 +1416,14 @@ public:
return r;
}
inline NodeRef prepend_sibling()
NodeRef prepend_sibling()
{
_C4RR();
NodeRef r(m_tree, m_tree->prepend_sibling(m_id));
return r;
}
inline NodeRef prepend_sibling(NodeInit const& i)
NodeRef prepend_sibling(NodeInit const& i)
{
_C4RR();
NodeRef r(m_tree, m_tree->prepend_sibling(m_id));
@@ -1429,14 +1431,14 @@ public:
return r;
}
inline NodeRef append_sibling()
NodeRef append_sibling()
{
_C4RR();
NodeRef r(m_tree, m_tree->append_sibling(m_id));
return r;
}
inline NodeRef append_sibling(NodeInit const& i)
NodeRef append_sibling(NodeInit const& i)
{
_C4RR();
NodeRef r(m_tree, m_tree->append_sibling(m_id));
@@ -1446,7 +1448,7 @@ public:
public:
inline void remove_child(NodeRef & child)
void remove_child(NodeRef & child)
{
_C4RR();
_RYML_CB_ASSERT(m_tree->m_callbacks, has_child(child));
@@ -1456,7 +1458,7 @@ public:
}
//! remove the nth child of this node
inline void remove_child(id_type pos)
void remove_child(id_type pos)
{
_C4RR();
_RYML_CB_ASSERT(m_tree->m_callbacks, pos >= 0 && pos < num_children());
@@ -1466,7 +1468,7 @@ public:
}
//! remove a child by name
inline void remove_child(csubstr key)
void remove_child(csubstr key)
{
_C4RR();
id_type child = m_tree->find_child(m_id, key);
@@ -1480,7 +1482,7 @@ public:
* @p after. To move to the first position in the parent, simply
* pass an empty or default-constructed reference like this:
* `n.move({})`. */
inline void move(ConstNodeRef const& after)
void move(ConstNodeRef const& after)
{
_C4RR();
m_tree->move(m_id, after.m_id);
@@ -1490,7 +1492,7 @@ public:
* different tree), placing it after @p after. When the
* destination parent is in a new tree, then this node's tree
* pointer is reset to the tree of the parent node. */
inline void move(NodeRef const& parent, ConstNodeRef const& after)
void move(NodeRef const& parent, ConstNodeRef const& after)
{
_C4RR();
if(parent.m_tree == m_tree)
@@ -1508,7 +1510,7 @@ public:
* place it after the node @p after. To place into the first
* position of the parent, simply pass an empty or
* default-constructed reference like this: `n.move({})`. */
inline NodeRef duplicate(ConstNodeRef const& after) const
NodeRef duplicate(ConstNodeRef const& after) const
{
_C4RR();
_RYML_CB_ASSERT(m_tree->m_callbacks, m_tree == after.m_tree || after.m_id == NONE);
@@ -1522,7 +1524,7 @@ public:
* @p after. To place into the first position of the parent,
* simply pass an empty or default-constructed reference like
* this: `n.move({})`. */
inline NodeRef duplicate(NodeRef const& parent, ConstNodeRef const& after) const
NodeRef duplicate(NodeRef const& parent, ConstNodeRef const& after) const
{
_C4RR();
_RYML_CB_ASSERT(m_tree->m_callbacks, parent.m_tree == after.m_tree || after.m_id == NONE);
@@ -1540,7 +1542,7 @@ public:
}
}
inline void duplicate_children(NodeRef const& parent, ConstNodeRef const& after) const
void duplicate_children(NodeRef const& parent, ConstNodeRef const& after) const
{
_C4RR();
_RYML_CB_ASSERT(m_tree->m_callbacks, parent.m_tree == after.m_tree);
@@ -1560,6 +1562,8 @@ public:
#undef _C4RID
};
// NOLINTEND(cppcoreguidelines-c-copy-assignment-signature,misc-unconventional-assign-operator)
//-----------------------------------------------------------------------------
@@ -1569,7 +1573,7 @@ inline ConstNodeRef::ConstNodeRef(NodeRef const& that) noexcept
{
}
inline ConstNodeRef::ConstNodeRef(NodeRef && that) noexcept
inline ConstNodeRef::ConstNodeRef(NodeRef && that) noexcept // NOLINT
: m_tree(that.m_tree)
, m_id(!that.is_seed() ? that.id() : (id_type)NONE)
{
@@ -1583,7 +1587,7 @@ inline ConstNodeRef& ConstNodeRef::operator= (NodeRef const& that) noexcept
return *this;
}
inline ConstNodeRef& ConstNodeRef::operator= (NodeRef && that) noexcept
inline ConstNodeRef& ConstNodeRef::operator= (NodeRef && that) noexcept // NOLINT
{
m_tree = (that.m_tree);
m_id = (!that.is_seed() ? that.id() : (id_type)NONE);

View File

@@ -67,7 +67,7 @@ csubstr NodeType::type_str(substr buf, NodeType_e flags) noexcept
#define _prflag(fl, txt) \
do { \
if((flags & fl) == (fl)) \
if((flags & (fl)) == (fl)) \
{ \
if(gotone) \
{ \
@@ -80,7 +80,7 @@ csubstr NodeType::type_str(substr buf, NodeType_e flags) noexcept
memcpy(buf.str + pos, fltxt.str, fltxt.len); \
pos += fltxt.len; \
gotone = true; \
flags = (flags & ~fl); /*remove the flag*/ \
flags = (flags & ~(fl)); /*remove the flag*/ \
} \
} while(0)

View File

@@ -28,7 +28,7 @@ using type_bits = uint32_t;
/** a bit mask for marking node types and styles */
typedef enum : type_bits {
#define __(v) (type_bits(1) << v) // a convenience define, undefined below
#define __(v) (type_bits(1) << v) // a convenience define, undefined below // NOLINT
NOTYPE = 0, ///< no node type or style is set
KEY = __(0), ///< is member of a map, must have non-empty key
VAL = __(1), ///< a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or SEQ

View File

@@ -12,7 +12,7 @@ class Tree;
class NodeRef;
template<class EventHandler> class ParseEngine;
struct EventHandlerTree;
RYML_EXPORT id_type estimate_tree_capacity(csubstr src);
RYML_EXPORT id_type estimate_tree_capacity(csubstr src); // NOLINT
/** @addtogroup doc_parse

View File

@@ -56,10 +56,12 @@
# endif
#endif
// NOLINTBEGIN(hicpp-signed-bitwise,cppcoreguidelines-avoid-goto,hicpp-avoid-goto,hicpp-multiway-paths-covered)
namespace c4 {
namespace yml {
namespace {
namespace { // NOLINT
C4_HOT C4_ALWAYS_INLINE bool _is_blck_token(csubstr s) noexcept
{
@@ -260,7 +262,7 @@ ParseEngine<EventHandler>::ParseEngine(EventHandler *evt_handler, ParserOptions
}
template<class EventHandler>
ParseEngine<EventHandler>::ParseEngine(ParseEngine &&that)
ParseEngine<EventHandler>::ParseEngine(ParseEngine &&that) noexcept
: m_options(that.m_options)
, m_file(that.m_file)
, m_buf(that.m_buf)
@@ -298,7 +300,7 @@ ParseEngine<EventHandler>::ParseEngine(ParseEngine const& that)
}
template<class EventHandler>
ParseEngine<EventHandler>& ParseEngine<EventHandler>::operator=(ParseEngine &&that)
ParseEngine<EventHandler>& ParseEngine<EventHandler>::operator=(ParseEngine &&that) noexcept
{
_free();
m_options = (that.m_options);
@@ -318,20 +320,23 @@ ParseEngine<EventHandler>& ParseEngine<EventHandler>::operator=(ParseEngine &&th
template<class EventHandler>
ParseEngine<EventHandler>& ParseEngine<EventHandler>::operator=(ParseEngine const& that)
{
_free();
m_options = (that.m_options);
m_file = (that.m_file);
m_buf = (that.m_buf);
m_evt_handler = that.m_evt_handler;
m_pending_anchors = that.m_pending_anchors;
m_pending_tags = that.m_pending_tags;
if(that.m_newline_offsets_capacity > m_newline_offsets_capacity)
_resize_locations(that.m_newline_offsets_capacity);
_RYML_CB_CHECK(m_evt_handler->m_stack.m_callbacks, m_newline_offsets_capacity >= that.m_newline_offsets_capacity);
_RYML_CB_CHECK(m_evt_handler->m_stack.m_callbacks, m_newline_offsets_capacity >= that.m_newline_offsets_size);
memcpy(m_newline_offsets, that.m_newline_offsets, that.m_newline_offsets_size * sizeof(size_t));
m_newline_offsets_size = that.m_newline_offsets_size;
m_newline_offsets_buf = that.m_newline_offsets_buf;
if(&that != this)
{
_free();
m_options = (that.m_options);
m_file = (that.m_file);
m_buf = (that.m_buf);
m_evt_handler = that.m_evt_handler;
m_pending_anchors = that.m_pending_anchors;
m_pending_tags = that.m_pending_tags;
if(that.m_newline_offsets_capacity > m_newline_offsets_capacity)
_resize_locations(that.m_newline_offsets_capacity);
_RYML_CB_CHECK(m_evt_handler->m_stack.m_callbacks, m_newline_offsets_capacity >= that.m_newline_offsets_capacity);
_RYML_CB_CHECK(m_evt_handler->m_stack.m_callbacks, m_newline_offsets_capacity >= that.m_newline_offsets_size);
memcpy(m_newline_offsets, that.m_newline_offsets, that.m_newline_offsets_size * sizeof(size_t));
m_newline_offsets_size = that.m_newline_offsets_size;
m_newline_offsets_buf = that.m_newline_offsets_buf;
}
return *this;
}
@@ -359,7 +364,7 @@ void ParseEngine<EventHandler>::_free()
m_newline_offsets = nullptr;
m_newline_offsets_size = 0u;
m_newline_offsets_capacity = 0u;
m_newline_offsets_buf = 0u;
m_newline_offsets_buf = nullptr;
}
}
@@ -385,9 +390,9 @@ template<class EventHandler>
void ParseEngine<EventHandler>::_relocate_arena(csubstr prev_arena, substr next_arena)
{
#define _ryml_relocate(s) \
if(s.is_sub(prev_arena)) \
if((s).is_sub(prev_arena)) \
{ \
s.str = next_arena.str + (s.str - prev_arena.str); \
(s).str = next_arena.str + ((s).str - prev_arena.str); \
}
_ryml_relocate(m_buf);
_ryml_relocate(m_newline_offsets_buf);
@@ -420,33 +425,33 @@ void ParseEngine<EventHandler>::_fmt_msg(DumpFn &&dumpfn) const
size_t offs = 3u + to_chars(substr{}, st->pos.line) + to_chars(substr{}, st->pos.col);
if(m_file.len)
{
detail::_dump(dumpfn, "{}:", m_file);
detail::_dump(std::forward<DumpFn>(dumpfn), "{}:", m_file);
offs += m_file.len + 1;
}
detail::_dump(dumpfn, "{}:{}: ", st->pos.line, st->pos.col);
detail::_dump(std::forward<DumpFn>(dumpfn), "{}:{}: ", st->pos.line, st->pos.col);
csubstr maybe_full_content = (contents.len < 80u ? contents : contents.first(80u));
csubstr maybe_ellipsis = (contents.len < 80u ? csubstr{} : csubstr("..."));
detail::_dump(dumpfn, "{}{} (size={})\n", maybe_full_content, maybe_ellipsis, contents.len);
detail::_dump(std::forward<DumpFn>(dumpfn), "{}{} (size={})\n", maybe_full_content, maybe_ellipsis, contents.len);
// highlight the remaining portion of the previous line
size_t firstcol = (size_t)(lc.rem.begin() - lc.full.begin());
size_t lastcol = firstcol + lc.rem.len;
for(size_t i = 0; i < offs + firstcol; ++i)
dumpfn(" ");
dumpfn("^");
std::forward<DumpFn>(dumpfn)(" ");
std::forward<DumpFn>(dumpfn)("^");
for(size_t i = 1, e = (lc.rem.len < 80u ? lc.rem.len : 80u); i < e; ++i)
dumpfn("~");
detail::_dump(dumpfn, "{} (cols {}-{})\n", maybe_ellipsis, firstcol+1, lastcol+1);
std::forward<DumpFn>(dumpfn)("~");
detail::_dump(std::forward<DumpFn>(dumpfn), "{} (cols {}-{})\n", maybe_ellipsis, firstcol+1, lastcol+1);
}
else
{
dumpfn("\n");
std::forward<DumpFn>(dumpfn)("\n");
}
#ifdef RYML_DBG
// next line: print the state flags
{
char flagbuf_[128];
detail::_dump(dumpfn, "top state: {}\n", detail::_parser_flags_to_str(flagbuf_, m_evt_handler->m_curr->flags));
detail::_dump(std::forward<DumpFn>(dumpfn), "top state: {}\n", detail::_parser_flags_to_str(flagbuf_, m_evt_handler->m_curr->flags));
}
#endif
}
@@ -4071,7 +4076,7 @@ template<class EventHandler>
void ParseEngine<EventHandler>::_add_annotation(Annotation *C4_RESTRICT dst, csubstr str, size_t indentation, size_t line)
{
_c4dbgpf("store annotation[{}]: '{}' indentation={} line={}", dst->num_entries, str, indentation, line);
if(C4_UNLIKELY(dst->num_entries >= C4_COUNTOF(dst->annotations)))
if(C4_UNLIKELY(dst->num_entries >= C4_COUNTOF(dst->annotations))) // NOLINT(bugprone-sizeof-expression)
_c4err("too many annotations");
dst->annotations[dst->num_entries].str = str;
dst->annotations[dst->num_entries].indentation = indentation;
@@ -6533,7 +6538,7 @@ mapblck_start:
addrem_flags(RNXT, RVAL);
_handle_annotations_before_blck_val_scalar();
m_evt_handler->begin_seq_val_flow();
addrem_flags(RSEQ|FLOW|RVAL, RMAP|BLCK|RNXT|BLCK);
addrem_flags(RSEQ|FLOW|RVAL, RMAP|BLCK|RNXT);
_set_indentation(m_evt_handler->m_curr->indref + 1u);
_line_progressed(1);
goto mapblck_finish;
@@ -8125,6 +8130,8 @@ void ParseEngine<EventHandler>::parse_in_place_ev(csubstr filename, substr src)
} // namespace yml
} // namespace c4
// NOLINTEND(hicpp-signed-bitwise,cppcoreguidelines-avoid-goto,hicpp-avoid-goto,hicpp-multiway-paths-covered)
#undef _c4dbgnextline
#if defined(_MSC_VER)

View File

@@ -15,6 +15,7 @@
# pragma warning(disable: 4251/*needs to have dll-interface to be used by clients of struct*/)
#endif
// NOLINTBEGIN(hicpp-signed-bitwise)
namespace c4 {
namespace yml {
@@ -214,8 +215,8 @@ struct RYML_EXPORT ParserOptions
private:
typedef enum : uint32_t {
SCALAR_FILTERING = (1u << 0),
LOCATIONS = (1u << 1),
SCALAR_FILTERING = (1u << 0u),
LOCATIONS = (1u << 1u),
DEFAULTS = SCALAR_FILTERING,
} Flags_e;
@@ -302,9 +303,9 @@ public:
ParseEngine(EventHandler *evt_handler, ParserOptions opts={});
~ParseEngine();
ParseEngine(ParseEngine &&);
ParseEngine(ParseEngine &&) noexcept;
ParseEngine(ParseEngine const&);
ParseEngine& operator=(ParseEngine &&);
ParseEngine& operator=(ParseEngine &&) noexcept;
ParseEngine& operator=(ParseEngine const&);
/** @} */
@@ -628,7 +629,7 @@ private:
void _scan_line();
substr _peek_next_line(size_t pos=npos) const;
inline bool _at_line_begin() const
bool _at_line_begin() const
{
return m_evt_handler->m_curr->line_contents.rem.begin() == m_evt_handler->m_curr->line_contents.full.begin();
}
@@ -726,7 +727,7 @@ private:
public:
/** @cond dev */
EventHandler *C4_RESTRICT m_evt_handler;
EventHandler *C4_RESTRICT m_evt_handler; // NOLINT
/** @endcond */
private:
@@ -764,13 +765,15 @@ RYML_EXPORT C4_NO_INLINE size_t _find_last_newline_and_larger_indentation(csubst
* resulting number of nodes, notably if the YAML uses implicit
* maps as flow seq members as in `[these: are, individual:
* maps]`. */
RYML_EXPORT id_type estimate_tree_capacity(csubstr src);
RYML_EXPORT id_type estimate_tree_capacity(csubstr src); // NOLINT(readability-redundant-declaration)
/** @} */
} // namespace yml
} // namespace c4
// NOLINTEND(hicpp-signed-bitwise)
#if defined(_MSC_VER)
# pragma warning(pop)
#endif

View File

@@ -5,6 +5,8 @@
#include "c4/yml/common.hpp"
#endif
// NOLINTBEGIN(hicpp-signed-bitwise)
namespace c4 {
namespace yml {
@@ -202,4 +204,6 @@ static_assert(std::is_standard_layout<ParserState>::value, "ParserState not stan
} // namespace yml
} // namespace c4
// NOLINTEND(hicpp-signed-bitwise)
#endif /* _C4_YML_PARSER_STATE_HPP_ */

View File

@@ -21,7 +21,7 @@ C4_ALWAYS_INLINE bool _is_idchar(char c)
|| (c == '_' || c == '-' || c == '~' || c == '$');
}
typedef enum { kReadPending = 0, kKeyPending = 1, kValPending = 2 } _ppstate;
enum _ppstate : int { kReadPending = 0, kKeyPending = 1, kValPending = 2 };
C4_ALWAYS_INLINE _ppstate _next(_ppstate s)
{
int n = (int)s + 1;

View File

@@ -230,7 +230,7 @@ bool TagDirective::create_from_str(csubstr directive_, Tree *tree)
_RYML_CB_ERR(tree->callbacks(), "invalid tag directive");
}
next_node_id = tree->size();
if(tree->size() > 0)
if(!tree->empty())
{
const id_type prev = tree->size() - 1;
if(tree->is_root(prev) && tree->type(prev) != NOTYPE && !tree->is_stream(prev))

View File

@@ -114,9 +114,12 @@ Tree::Tree(Tree const& that) : Tree(that.m_callbacks)
Tree& Tree::operator= (Tree const& that)
{
_free();
m_callbacks = that.m_callbacks;
_copy(that);
if(&that != this)
{
_free();
m_callbacks = that.m_callbacks;
_copy(that);
}
return *this;
}
@@ -125,11 +128,14 @@ Tree::Tree(Tree && that) noexcept : Tree(that.m_callbacks)
_move(that);
}
Tree& Tree::operator= (Tree && that) RYML_NOEXCEPT
Tree& Tree::operator= (Tree && that) noexcept
{
_free();
m_callbacks = that.m_callbacks;
_move(that);
if(&that != this)
{
_free();
m_callbacks = that.m_callbacks;
_move(that);
}
return *this;
}
@@ -1466,7 +1472,7 @@ csubstr Tree::lookup_result::unresolved() const
return path.sub(path_pos);
}
void Tree::_advance(lookup_result *r, size_t more) const
void Tree::_advance(lookup_result *r, size_t more)
{
r->path_pos += more;
if(r->path.sub(r->path_pos).begins_with('.'))
@@ -1760,7 +1766,7 @@ Tree::_lookup_path_token Tree::_next_token(lookup_result *r, _lookup_path_token
}
} // namespace ryml
} // namespace yml
} // namespace c4

View File

@@ -110,17 +110,17 @@ struct NodeScalar
public:
/// initialize as an empty scalar
inline NodeScalar() noexcept : tag(), scalar(), anchor() {}
NodeScalar() noexcept : tag(), scalar(), anchor() {} // NOLINT
/// initialize as an untagged scalar
template<size_t N>
inline NodeScalar(const char (&s)[N]) noexcept : tag(), scalar(s), anchor() {}
inline NodeScalar(csubstr s ) noexcept : tag(), scalar(s), anchor() {}
NodeScalar(const char (&s)[N]) noexcept : tag(), scalar(s), anchor() {}
NodeScalar(csubstr s ) noexcept : tag(), scalar(s), anchor() {}
/// initialize as a tagged scalar
template<size_t N, size_t M>
inline NodeScalar(const char (&t)[N], const char (&s)[N]) noexcept : tag(t), scalar(s), anchor() {}
inline NodeScalar(csubstr t , csubstr s ) noexcept : tag(t), scalar(s), anchor() {}
NodeScalar(const char (&t)[N], const char (&s)[N]) noexcept : tag(t), scalar(s), anchor() {}
NodeScalar(csubstr t , csubstr s ) noexcept : tag(t), scalar(s), anchor() {}
public:
@@ -256,7 +256,7 @@ public:
Tree(Tree && that) noexcept;
Tree& operator= (Tree const& that);
Tree& operator= (Tree && that) RYML_NOEXCEPT;
Tree& operator= (Tree && that) noexcept;
/** @} */
@@ -271,13 +271,13 @@ public:
* @note does NOT clear the arena
* @see clear_arena() */
void clear();
inline void clear_arena() { m_arena_pos = 0; }
void clear_arena() { m_arena_pos = 0; }
inline bool empty() const { return m_size == 0; }
bool empty() const { return m_size == 0; }
inline id_type size() const { return m_size; }
inline id_type capacity() const { return m_cap; }
inline id_type slack() const { RYML_ASSERT(m_cap >= m_size); return m_cap - m_size; }
id_type size() const { return m_size; }
id_type capacity() const { return m_cap; }
id_type slack() const { RYML_ASSERT(m_cap >= m_size); return m_cap - m_size; }
Callbacks const& callbacks() const { return m_callbacks; }
void callbacks(Callbacks const& cb) { m_callbacks = cb; }
@@ -301,7 +301,7 @@ public:
//! get a pointer to a node's NodeData.
//! i can be NONE, in which case a nullptr is returned
inline NodeData *get(id_type node)
NodeData *get(id_type node) // NOLINT(readability-make-member-function-const)
{
if(node == NONE)
return nullptr;
@@ -310,7 +310,7 @@ public:
}
//! get a pointer to a node's NodeData.
//! i can be NONE, in which case a nullptr is returned.
inline NodeData const *get(id_type node) const
NodeData const *get(id_type node) const
{
if(node == NONE)
return nullptr;
@@ -320,10 +320,10 @@ public:
//! An if-less form of get() that demands a valid node index.
//! This function is implementation only; use at your own risk.
inline NodeData * _p(id_type node) { _RYML_CB_ASSERT(m_callbacks, node != NONE && node >= 0 && node < m_cap); return m_buf + node; }
NodeData * _p(id_type node) { _RYML_CB_ASSERT(m_callbacks, node != NONE && node >= 0 && node < m_cap); return m_buf + node; } // NOLINT(readability-make-member-function-const)
//! An if-less form of get() that demands a valid node index.
//! This function is implementation only; use at your own risk.
inline NodeData const * _p(id_type node) const { _RYML_CB_ASSERT(m_callbacks, node != NONE && node >= 0 && node < m_cap); return m_buf + node; }
NodeData const * _p(id_type node) const { _RYML_CB_ASSERT(m_callbacks, node != NONE && node >= 0 && node < m_cap); return m_buf + node; }
//! Get the id of the root node
id_type root_id() { if(m_cap == 0) { reserve(16); } _RYML_CB_ASSERT(m_callbacks, m_cap > 0 && m_size > 0); return 0; }
@@ -483,7 +483,7 @@ public:
return false;
}
RYML_DEPRECATED("use has_other_siblings()") bool has_siblings(id_type /*node*/) const { return true; }
RYML_DEPRECATED("use has_other_siblings()") static bool has_siblings(id_type /*node*/) { return true; }
/** @} */
@@ -712,7 +712,7 @@ public:
public:
/** remove an entire branch at once: ie remove the children and the node itself */
inline void remove(id_type node)
void remove(id_type node)
{
remove_children(node);
_release(node);
@@ -822,16 +822,16 @@ public:
/** get the current size of the tree's internal arena */
RYML_DEPRECATED("use arena_size() instead") size_t arena_pos() const { return m_arena_pos; }
/** get the current size of the tree's internal arena */
inline size_t arena_size() const { return m_arena_pos; }
size_t arena_size() const { return m_arena_pos; }
/** get the current capacity of the tree's internal arena */
inline size_t arena_capacity() const { return m_arena.len; }
size_t arena_capacity() const { return m_arena.len; }
/** get the current slack of the tree's internal arena */
inline size_t arena_slack() const { _RYML_CB_ASSERT(m_callbacks, m_arena.len >= m_arena_pos); return m_arena.len - m_arena_pos; }
size_t arena_slack() const { _RYML_CB_ASSERT(m_callbacks, m_arena.len >= m_arena_pos); return m_arena.len - m_arena_pos; }
/** get the current arena */
csubstr arena() const { return m_arena.first(m_arena_pos); }
/** get the current arena */
substr arena() { return m_arena.first(m_arena_pos); }
substr arena() { return m_arena.first(m_arena_pos); } // NOLINT(readability-make-member-function-const)
/** return true if the given substring is part of the tree's string arena */
bool in_arena(csubstr s) const
@@ -936,7 +936,7 @@ public:
{
return to_arena(to_csubstr(s));
}
C4_ALWAYS_INLINE csubstr to_arena(std::nullptr_t)
C4_ALWAYS_INLINE static csubstr to_arena(std::nullptr_t)
{
return csubstr{};
}
@@ -1053,7 +1053,7 @@ public:
size_t path_pos;
csubstr path;
inline operator bool() const { return target != NONE; }
operator bool() const { return target != NONE; }
lookup_result() : target(NONE), closest(NONE), path_pos(0), path() {}
lookup_result(csubstr path_, id_type start) : target(NONE), closest(start), path_pos(0), path(path_) {}
@@ -1089,7 +1089,7 @@ private:
NodeType type;
_lookup_path_token() : value(), type() {}
_lookup_path_token(csubstr v, NodeType t) : value(v), type(t) {}
inline operator bool() const { return type != NOTYPE; }
operator bool() const { return type != NOTYPE; }
bool is_index() const { return value.begins_with('[') && value.ends_with(']'); }
};
@@ -1101,7 +1101,7 @@ private:
id_type _next_node (lookup_result *r, _lookup_path_token *parent) const;
id_type _next_node_modify(lookup_result *r, _lookup_path_token *parent);
void _advance(lookup_result *r, size_t more) const;
static void _advance(lookup_result *r, size_t more);
_lookup_path_token _next_token(lookup_result *r, _lookup_path_token const& parent) const;
@@ -1123,7 +1123,7 @@ public:
#else
void _check_next_flags(id_type node, type_bits f)
{
auto n = _p(node);
NodeData *n = _p(node);
type_bits o = n->m_type; // old
C4_UNUSED(o);
if(f & MAP)
@@ -1154,14 +1154,14 @@ public:
}
#endif
inline void _set_flags(id_type node, NodeType_e f) { _check_next_flags(node, f); _p(node)->m_type = f; }
inline void _set_flags(id_type node, type_bits f) { _check_next_flags(node, f); _p(node)->m_type = f; }
void _set_flags(id_type node, NodeType_e f) { _check_next_flags(node, f); _p(node)->m_type = f; }
void _set_flags(id_type node, type_bits f) { _check_next_flags(node, f); _p(node)->m_type = f; }
inline void _add_flags(id_type node, NodeType_e f) { NodeData *d = _p(node); type_bits fb = f | d->m_type; _check_next_flags(node, fb); d->m_type = (NodeType_e) fb; }
inline void _add_flags(id_type node, type_bits f) { NodeData *d = _p(node); f |= d->m_type; _check_next_flags(node, f); d->m_type = f; }
void _add_flags(id_type node, NodeType_e f) { NodeData *d = _p(node); type_bits fb = f | d->m_type; _check_next_flags(node, fb); d->m_type = (NodeType_e) fb; }
void _add_flags(id_type node, type_bits f) { NodeData *d = _p(node); f |= d->m_type; _check_next_flags(node, f); d->m_type = f; }
inline void _rem_flags(id_type node, NodeType_e f) { NodeData *d = _p(node); type_bits fb = d->m_type & ~f; _check_next_flags(node, fb); d->m_type = (NodeType_e) fb; }
inline void _rem_flags(id_type node, type_bits f) { NodeData *d = _p(node); f = d->m_type & ~f; _check_next_flags(node, f); d->m_type = f; }
void _rem_flags(id_type node, NodeType_e f) { NodeData *d = _p(node); type_bits fb = d->m_type & ~f; _check_next_flags(node, fb); d->m_type = (NodeType_e) fb; }
void _rem_flags(id_type node, type_bits f) { NodeData *d = _p(node); f = d->m_type & ~f; _check_next_flags(node, f); d->m_type = f; }
void _set_key(id_type node, csubstr key, type_bits more_flags=0)
{
@@ -1252,12 +1252,12 @@ public:
void _swap_hierarchy(id_type n_, id_type m_);
void _copy_hierarchy(id_type dst_, id_type src_);
inline void _copy_props(id_type dst_, id_type src_)
void _copy_props(id_type dst_, id_type src_)
{
_copy_props(dst_, this, src_);
}
inline void _copy_props_wo_key(id_type dst_, id_type src_)
void _copy_props_wo_key(id_type dst_, id_type src_)
{
_copy_props_wo_key(dst_, this, src_);
}
@@ -1296,12 +1296,12 @@ public:
dst.m_val = src.m_val;
}
inline void _clear_type(id_type node)
void _clear_type(id_type node)
{
_p(node)->m_type = NOTYPE;
}
inline void _clear(id_type node)
void _clear(id_type node)
{
auto *C4_RESTRICT n = _p(node);
n->m_type = NOTYPE;
@@ -1312,13 +1312,13 @@ public:
n->m_last_child = NONE;
}
inline void _clear_key(id_type node)
void _clear_key(id_type node)
{
_p(node)->m_key.clear();
_rem_flags(node, KEY);
}
inline void _clear_val(id_type node)
void _clear_val(id_type node)
{
_p(node)->m_val.clear();
_rem_flags(node, VAL);

View File

@@ -34,7 +34,7 @@ struct WriterFile
WriterFile(FILE *f = nullptr) : m_file(f ? f : stdout), m_pos(0) {}
inline substr _get(bool /*error_on_excess*/)
substr _get(bool /*error_on_excess*/) const
{
substr sp;
sp.str = nullptr;
@@ -43,41 +43,32 @@ struct WriterFile
}
template<size_t N>
inline void _do_write(const char (&a)[N])
void _do_write(const char (&a)[N])
{
fwrite(a, sizeof(char), N - 1, m_file);
(void)fwrite(a, sizeof(char), N - 1, m_file);
m_pos += N - 1;
}
inline void _do_write(csubstr sp)
void _do_write(csubstr sp)
{
#if defined(__clang__)
# pragma clang diagnostic push
# pragma GCC diagnostic ignored "-Wsign-conversion"
#elif defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
if(sp.empty()) return;
fwrite(sp.str, sizeof(csubstr::char_type), sp.len, m_file);
C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wsign-conversion")
if(sp.empty())
return;
(void)fwrite(sp.str, sizeof(csubstr::char_type), sp.len, m_file);
m_pos += sp.len;
#if defined(__clang__)
# pragma clang diagnostic pop
#elif defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
C4_SUPPRESS_WARNING_GCC_CLANG_POP
}
inline void _do_write(const char c)
void _do_write(const char c)
{
fputc(c, m_file);
(void)fputc(c, m_file);
++m_pos;
}
inline void _do_write(const char c, size_t num_times)
void _do_write(const char c, size_t num_times)
{
for(size_t i = 0; i < num_times; ++i)
fputc(c, m_file);
(void)fputc(c, m_file);
m_pos += num_times;
}
};
@@ -90,12 +81,12 @@ struct WriterFile
template<class OStream>
struct WriterOStream
{
OStream& m_stream;
OStream* m_stream;
size_t m_pos;
WriterOStream(OStream &s) : m_stream(s), m_pos(0) {}
WriterOStream(OStream &s) : m_stream(&s), m_pos(0) {}
inline substr _get(bool /*error_on_excess*/)
substr _get(bool /*error_on_excess*/) const
{
substr sp;
sp.str = nullptr;
@@ -104,41 +95,32 @@ struct WriterOStream
}
template<size_t N>
inline void _do_write(const char (&a)[N])
void _do_write(const char (&a)[N])
{
m_stream.write(a, N - 1);
m_stream->write(a, N - 1);
m_pos += N - 1;
}
inline void _do_write(csubstr sp)
void _do_write(csubstr sp)
{
#if defined(__clang__)
# pragma clang diagnostic push
# pragma GCC diagnostic ignored "-Wsign-conversion"
#elif defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
if(sp.empty()) return;
m_stream.write(sp.str, sp.len);
C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wsign-conversion")
if(sp.empty())
return;
m_stream->write(sp.str, sp.len);
m_pos += sp.len;
#if defined(__clang__)
# pragma clang diagnostic pop
#elif defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
C4_SUPPRESS_WARNING_GCC_CLANG_POP
}
inline void _do_write(const char c)
void _do_write(const char c)
{
m_stream.put(c);
m_stream->put(c);
++m_pos;
}
inline void _do_write(const char c, size_t num_times)
void _do_write(const char c, size_t num_times)
{
for(size_t i = 0; i < num_times; ++i)
m_stream.put(c);
m_stream->put(c);
m_pos += num_times;
}
};
@@ -155,16 +137,12 @@ struct WriterBuf
WriterBuf(substr sp) : m_buf(sp), m_pos(0) {}
inline substr _get(bool error_on_excess)
substr _get(bool error_on_excess) const
{
if(m_pos <= m_buf.len)
{
return m_buf.first(m_pos);
}
if(error_on_excess)
{
else if(error_on_excess)
c4::yml::error("not enough space in the given buffer");
}
substr sp;
sp.str = nullptr;
sp.len = m_pos;
@@ -172,35 +150,32 @@ struct WriterBuf
}
template<size_t N>
inline void _do_write(const char (&a)[N])
void _do_write(const char (&a)[N])
{
RYML_ASSERT( ! m_buf.overlaps(a));
if(m_pos + N-1 <= m_buf.len)
{
memcpy(&(m_buf[m_pos]), a, N-1);
}
m_pos += N-1;
}
inline void _do_write(csubstr sp)
void _do_write(csubstr sp)
{
if(sp.empty()) return;
if(sp.empty())
return;
RYML_ASSERT( ! sp.overlaps(m_buf));
if(m_pos + sp.len <= m_buf.len)
{
memcpy(&(m_buf[m_pos]), sp.str, sp.len);
}
m_pos += sp.len;
}
inline void _do_write(const char c)
void _do_write(const char c)
{
if(m_pos + 1 <= m_buf.len)
m_buf[m_pos] = c;
++m_pos;
}
inline void _do_write(const char c, size_t num_times)
void _do_write(const char c, size_t num_times)
{
if(m_pos + num_times <= m_buf.len)
for(size_t i = 0; i < num_times; ++i)

View File

@@ -126,6 +126,15 @@ ryml_add_test_case_group(anchor)
ryml_add_test_case_group(indentation)
ryml_add_test_case_group(number)
ryml_add_test_case_group(github_issues)
# workaround for a false positive warning in gcc14 --std=c++20 -O2
if(CMAKE_COMPILER_IS_GNUCXX
AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 13)
AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15))
get_target_property(std ryml-test-scalar_plain CXX_STANDARD)
if(std EQUAL 20)
c4_target_compile_flags(ryml-test-scalar_plain PUBLIC GCC -Wno-array-bounds -Wno-stringop-overflow)
endif()
endif()
#-------------------------------------------------------------------------