diff --git a/.clang-tidy b/.clang-tidy index 690a630687..44d03f0fc5 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,9 +1,14 @@ --- Checks: | -* - clang-analyzer-cplusplus.Move - clang-analyzer-cplusplus.NewDeleteLeaks - clang-analyzer-core.StackAddressEscape + clang-analyzer-core.* + clang-analyzer-deadcode.* + clang-analyzer-cplusplus.* + -clang-analyzer-cplusplus.NewDelete + performance-* + -performance-avoid-endl + -performance-unnecessary-value-param + -performance-enum-size cppcoreguidelines-* -cppcoreguidelines-owning-memory -cppcoreguidelines-narrowing-conversions @@ -17,16 +22,24 @@ Checks: | -cppcoreguidelines-pro-bounds-array-to-pointer-decay -cppcoreguidelines-avoid-const-or-ref-data-members -cppcoreguidelines-pro-bounds-constant-array-index + -cppcoreguidelines-noexcept-swap + -cppcoreguidelines-noexcept-move-operations + -cppcoreguidelines-noexcept-destructor bugprone-* -bugprone-sizeof-expression -bugprone-narrowing-conversions -bugprone-macro-parentheses -bugprone-easily-swappable-parameters -bugprone-implicit-widening-of-multiplication-result +WarningsAsErrors: '*' CheckOptions: cppcoreguidelines-macro-usage.CheckCapsOnly: true cppcoreguidelines-avoid-do-while.IgnoreMacros: true cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes: true + cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove: true + cppcoreguidelines-avoid-non-const-global-variables.AllowInternalLinkage: true + performance-move-const-arg.CheckTriviallyCopyableMove: false + performance-move-const-arg.CheckMoveToConstRef: false HeaderFilterRegex: '' FormatStyle: file ... diff --git a/.github/workflows/build-spack.yml b/.github/workflows/build-spack.yml index e66bbe8c4c..477df483e9 100644 --- a/.github/workflows/build-spack.yml +++ b/.github/workflows/build-spack.yml @@ -41,7 +41,7 @@ jobs: - geometry: "geant4" special: null geant: "11.0" - - geometry: "orange" + - geometry: "vecgeom" special: "clang-tidy" geant: "11.2" env: @@ -56,6 +56,7 @@ jobs: SPACK_BUILDCACHE: "celer-buildcache" # see spack.yaml CC: "clang-15" CXX: "clang++-15" + CLANG_TIDY: "clang-tidy-15" runs-on: ubuntu-22.04 continue-on-error: false steps: @@ -126,8 +127,6 @@ jobs: run: | ccache -z - name: Configure Celeritas - env: - CLANG_TIDY: "clang-tidy-15" run: | ln -fs scripts/cmake-presets/ci-ubuntu-github.json CMakeUserPresets.json if [ "${{matrix.geant}}" == "11.0" ]; then @@ -139,9 +138,12 @@ jobs: - name: Build all id: build working-directory: build - continue-on-error: ${{matrix.special == 'clang-tidy'}} run: | - ninja -v -k0 + if [ "${{matrix.special}}" == "clang-tidy" ]; then + ninja -k0 + else + ninja -v -k0 + fi - name: Regenerate ROOT test data if: ${{matrix.geant == '11.0'}} working-directory: build @@ -184,13 +186,14 @@ jobs: if: >- ${{ (matrix.special != 'asanlite') + && (matrix.special != 'clang-tidy') }} run: | . ${SPACK_VIEW}/rc CELER_INSTALL_DIR=${PWD}/build ./scripts/ci/test-examples.sh - name: Install id: install - if: ${{!cancelled() && steps.build.outcome == 'success'}} + if: ${{!cancelled() && steps.build.outcome == 'success' && matrix.special != 'clang-tidy'}} working-directory: build run: | ninja install diff --git a/app/celer-dump-data.cc b/app/celer-dump-data.cc index 8496cae004..a34340d41e 100644 --- a/app/celer-dump-data.cc +++ b/app/celer-dump-data.cc @@ -624,7 +624,7 @@ void print_trans_params(ImportTransParameters const& trans_params, for (auto const& kv : trans_params.looping) { auto pid = particles.find(PDGNumber{kv.first}); - auto par = particles.id_to_label(pid); + auto const& par = particles.id_to_label(pid); cout << PEP_STREAM_PAR_PARAM(threshold_trials, par) << PEP_STREAM_PAR_PARAM(important_energy, par); } @@ -810,8 +810,8 @@ class OpticalMfpHelper }; //! Construct helper for given model class out of the models - OpticalMfpHelper(std::vector const& models, optical::ImportModelClass imc) - : mfps_(nullptr) + OpticalMfpHelper(std::vector const& models, + optical::ImportModelClass imc) { auto iter = std::find_if(models.begin(), models.end(), [imc] (auto const& m) { return m.model_class == imc; }); if (iter != models.end()) @@ -831,7 +831,7 @@ class OpticalMfpHelper } private: - std::vector const* mfps_; + std::vector const* mfps_{nullptr}; }; /*! @@ -968,7 +968,7 @@ void print_optical_materials(std::vector const& io_models, /*! * Execute and run. */ -int main(int argc, char* argv[]) +int main(int argc, char* argv[]) // NOLINT(bugprone-exception-escape) { using namespace celeritas; using namespace celeritas::app; diff --git a/app/celer-g4/DetectorConstruction.cc b/app/celer-g4/DetectorConstruction.cc index be5ea6bce5..7abe6c7af1 100644 --- a/app/celer-g4/DetectorConstruction.cc +++ b/app/celer-g4/DetectorConstruction.cc @@ -312,6 +312,7 @@ void DetectorConstruction::ConstructSDandField() * Apply a function to the range of volumes for each detector. */ template +// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) void DetectorConstruction::foreach_detector(F&& apply_to_range) const { auto start = detectors_.begin(); diff --git a/app/celer-g4/GeantDiagnostics.cc b/app/celer-g4/GeantDiagnostics.cc index accefa93d1..783119f38c 100644 --- a/app/celer-g4/GeantDiagnostics.cc +++ b/app/celer-g4/GeantDiagnostics.cc @@ -75,7 +75,7 @@ GeantDiagnostics::GeantDiagnostics(SharedParams const& params) CELER_LOG_LOCAL(status) << "Initializing Geant4 diagnostics"; // Get output registry - auto output_reg = params.output_reg(); + auto const& output_reg = params.output_reg(); CELER_ASSERT(output_reg); size_type num_threads = params.num_streams(); diff --git a/app/celer-g4/SensitiveHit.cc b/app/celer-g4/SensitiveHit.cc index cb542ac2cd..33099ce733 100644 --- a/app/celer-g4/SensitiveHit.cc +++ b/app/celer-g4/SensitiveHit.cc @@ -24,6 +24,7 @@ namespace app */ auto SensitiveHit::allocator() -> HitAllocator& { + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static G4ThreadLocal HitAllocator* alloc_; if (CELER_UNLIKELY(!alloc_)) { @@ -36,10 +37,7 @@ auto SensitiveHit::allocator() -> HitAllocator& /*! * Construct with hit data. */ -SensitiveHit::SensitiveHit(EventHitData const& hit) - : G4VHit(), data_{std::move(hit)} -{ -} +SensitiveHit::SensitiveHit(EventHitData const& hit) : G4VHit(), data_{hit} {} //---------------------------------------------------------------------------// } // namespace app diff --git a/app/celer-geo/celer-geo.cc b/app/celer-geo/celer-geo.cc index 5d9c0b792d..5aa5837762 100644 --- a/app/celer-geo/celer-geo.cc +++ b/app/celer-geo/celer-geo.cc @@ -132,6 +132,7 @@ void run_trace(Runner& run_trace, std::ofstream image_file(trace_setup.bin_file, std::ios::binary); std::vector image_data(img_params.num_pixels()); image->copy_to_host(make_span(image_data)); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) image_file.write(reinterpret_cast(image_data.data()), image_data.size() * sizeof(int)); } diff --git a/scripts/cmake-presets/ci-ubuntu-github.json b/scripts/cmake-presets/ci-ubuntu-github.json index 871bb3d790..67c067d299 100644 --- a/scripts/cmake-presets/ci-ubuntu-github.json +++ b/scripts/cmake-presets/ci-ubuntu-github.json @@ -77,9 +77,9 @@ "inherits": ["spack"] }, { - "name": "reldeb-orange-clang-tidy", + "name": "reldeb-vecgeom-clang-tidy", "description": "Build with ORANGE and clang-tidy checks", - "inherits": ["spack"], + "inherits": ["spack", ".vecgeom"], "cacheVariables": { "CELERITAS_DEBUG": {"type": "BOOL", "value": "ON"}, "CELERITAS_BUILD_TESTS": {"type": "BOOL", "value": "OFF"}, diff --git a/src/accel/ExceptionConverter.cc b/src/accel/ExceptionConverter.cc index e307b24a5d..d6c897064a 100644 --- a/src/accel/ExceptionConverter.cc +++ b/src/accel/ExceptionConverter.cc @@ -166,7 +166,7 @@ void ExceptionConverter::operator()(std::exception_ptr eptr) const msg << "\n[error while exporting state: " << e.what() << "]"; } - catch (...) + catch (...) // NOLINT(bugprone-empty-catch) { /* Do nothing */ } diff --git a/src/accel/SharedParams.cc b/src/accel/SharedParams.cc index 318c426d85..57eb82e697 100644 --- a/src/accel/SharedParams.cc +++ b/src/accel/SharedParams.cc @@ -599,7 +599,7 @@ void SharedParams::initialize_core(SetupOptions const& options) asfi.cutoff = params.cutoff; asfi.physics = params.physics; asfi.imported = imported; - auto const along_step{options.make_along_step(asfi)}; + auto along_step{options.make_along_step(asfi)}; CELER_VALIDATE(along_step, << "along-step factory returned a null pointer"); return along_step; diff --git a/src/accel/detail/HitProcessor.cc b/src/accel/detail/HitProcessor.cc index cc60513bc3..9974376f23 100644 --- a/src/accel/detail/HitProcessor.cc +++ b/src/accel/detail/HitProcessor.cc @@ -141,7 +141,7 @@ HitProcessor::~HitProcessor() { CELER_LOG_LOCAL(debug) << "Deallocating hit processor"; } - catch (...) + catch (...) // NOLINT(bugprone-empty-catch) { // Ignore anything bad that happens while logging } diff --git a/src/celeritas/ext/detail/CelerOpticalPhysics.cc b/src/celeritas/ext/detail/CelerOpticalPhysics.cc index 0119a89917..c8554d85cb 100644 --- a/src/celeritas/ext/detail/CelerOpticalPhysics.cc +++ b/src/celeritas/ext/detail/CelerOpticalPhysics.cc @@ -20,6 +20,8 @@ #include #include #include + +#include "corecel/Macros.hh" #if G4VERSION_NUMBER >= 1070 # include # include @@ -54,6 +56,33 @@ enum class OpticalProcessType size_, }; +/*! + * Wrapper around a unique pointer to accomodate keeping track whether we + * delegated ownership to Geant4. We have to assume that Geant4 won't free the + * memory before we're done reading it... + */ +template +class ObservingUniquePtr +{ + public: + explicit ObservingUniquePtr(std::unique_ptr ptr) + : uptr_(std::move(ptr)), ptr_{uptr_.get()} + { + } + // False positive(fixed in clang-tidy-18) + // NOLINTNEXTLINE(performance-noexcept-move-constructor) + CELER_DEFAULT_MOVE_DELETE_COPY(ObservingUniquePtr); + ~ObservingUniquePtr() = default; + + T* release() noexcept { return uptr_.release(); } + operator T*() const noexcept { return ptr_; } + T* operator->() const noexcept { return ptr_; } + + private: + std::unique_ptr uptr_; + T* ptr_; +}; + #if G4VERSION_NUMBER >= 1070 G4OpticalProcessIndex optical_process_type_to_geant_index(OpticalProcessType value) @@ -239,13 +268,13 @@ void CelerOpticalPhysics::ConstructProcess() // NB: boundary is also used later on in loop over particles, // though it's only ever applicable to G4OpticalPhotons - auto boundary = std::make_unique(); + auto boundary = ObservingUniquePtr{std::make_unique()}; #if G4VERSION_NUMBER < 1070 boundary->SetInvokeSD(options_.boundary.invoke_sd); #endif if (process_is_active(OpticalProcessType::boundary, options_)) { - process_manager->AddDiscreteProcess(boundary.get()); + process_manager->AddDiscreteProcess(boundary.release()); CELER_LOG(debug) << "Loaded Optical boundary process with G4OpBoundaryProcess " "process"; @@ -275,7 +304,7 @@ void CelerOpticalPhysics::ConstructProcess() // Add photon-generating processes to all particles they apply to // TODO: Eventually replace with Celeritas step collector processes - auto scint = std::make_unique(); + auto scint = ObservingUniquePtr{std::make_unique()}; #if G4VERSION_NUMBER < 1070 scint->SetStackPhotons(options_.scintillation.stack_photons); scint->SetTrackSecondariesFirst( @@ -290,7 +319,7 @@ void CelerOpticalPhysics::ConstructProcess() #endif scint->AddSaturation(G4LossTableManager::Instance()->EmSaturation()); - auto cerenkov = std::make_unique(); + auto cerenkov = ObservingUniquePtr{std::make_unique()}; #if G4VERSION_NUMBER < 1070 cerenkov->SetStackPhotons(options_.cerenkov.stack_photons); cerenkov->SetTrackSecondariesFirst( @@ -311,8 +340,8 @@ void CelerOpticalPhysics::ConstructProcess() if (cerenkov->IsApplicable(*p) && process_is_active(OpticalProcessType::cerenkov, options_)) { - process_manager->AddProcess(cerenkov.get()); - process_manager->SetProcessOrdering(cerenkov.get(), idxPostStep); + process_manager->AddProcess(cerenkov.release()); + process_manager->SetProcessOrdering(cerenkov, idxPostStep); CELER_LOG(debug) << "Loaded Optical Cerenkov with G4Cerenkov " "process for particle " << p->GetParticleName(); @@ -320,9 +349,9 @@ void CelerOpticalPhysics::ConstructProcess() if (scint->IsApplicable(*p) && process_is_active(OpticalProcessType::scintillation, options_)) { - process_manager->AddProcess(scint.get()); - process_manager->SetProcessOrderingToLast(scint.get(), idxAtRest); - process_manager->SetProcessOrderingToLast(scint.get(), idxPostStep); + process_manager->AddProcess(scint.release()); + process_manager->SetProcessOrderingToLast(scint, idxAtRest); + process_manager->SetProcessOrderingToLast(scint, idxPostStep); CELER_LOG(debug) << "Loaded Optical Scintillation with G4Scintillation " "process for particle " @@ -331,13 +360,9 @@ void CelerOpticalPhysics::ConstructProcess() if (boundary->IsApplicable(*p) && process_is_active(OpticalProcessType::boundary, options_)) { - process_manager->SetProcessOrderingToLast(boundary.get(), - idxPostStep); + process_manager->SetProcessOrderingToLast(boundary, idxPostStep); } } - boundary.release(); - cerenkov.release(); - scint.release(); } } // namespace detail diff --git a/src/celeritas/global/CoreState.cc b/src/celeritas/global/CoreState.cc index 1bfc2e9cc2..6e4a6d3644 100644 --- a/src/celeritas/global/CoreState.cc +++ b/src/celeritas/global/CoreState.cc @@ -83,7 +83,7 @@ CoreState::~CoreState() << "Deallocating " << to_cstring(M) << " core state (stream " << this->stream_id().unchecked_get() << ')'; } - catch (...) + catch (...) // NOLINT(bugprone-empty-catch) { // Ignore anything bad that happens while logging } diff --git a/src/celeritas/mat/MaterialParams.cc b/src/celeritas/mat/MaterialParams.cc index f92965b31f..2fe8483c77 100644 --- a/src/celeritas/mat/MaterialParams.cc +++ b/src/celeritas/mat/MaterialParams.cc @@ -349,6 +349,7 @@ void MaterialParams::append_element_def(ElementInput const& inp, // Isotopic data std::vector vec_eic; + vec_eic.reserve(inp.isotopes_fractions.size()); for (auto const& key : inp.isotopes_fractions) { vec_eic.push_back(ElIsotopeComponent{key.first, key.second}); diff --git a/src/celeritas/phys/ImportedProcessAdapter.cc b/src/celeritas/phys/ImportedProcessAdapter.cc index 12d0a7d993..c844fe1eb9 100644 --- a/src/celeritas/phys/ImportedProcessAdapter.cc +++ b/src/celeritas/phys/ImportedProcessAdapter.cc @@ -203,7 +203,7 @@ auto ImportedProcessAdapter::step_limits(Applicability const& applic) const { try { - return this->step_limits_impl(std::move(applic)); + return this->step_limits_impl(applic); } catch (...) { diff --git a/src/celeritas/phys/PrimaryGenerator.cc b/src/celeritas/phys/PrimaryGenerator.cc index abbcf3749b..ba88751c9f 100644 --- a/src/celeritas/phys/PrimaryGenerator.cc +++ b/src/celeritas/phys/PrimaryGenerator.cc @@ -33,7 +33,7 @@ PrimaryGenerator::from_options(SPConstParticles particles, PrimaryGenerator::Input inp; inp.seed = opts.seed; - inp.pdg = std::move(opts.pdg); + inp.pdg = opts.pdg; inp.num_events = opts.num_events; inp.primaries_per_event = opts.primaries_per_event; inp.sample_energy = make_energy_sampler(opts.energy); @@ -49,9 +49,9 @@ PrimaryGenerator::from_options(SPConstParticles particles, PrimaryGenerator::PrimaryGenerator(SPConstParticles particles, Input const& inp) : num_events_(inp.num_events) , primaries_per_event_(inp.primaries_per_event) - , sample_energy_(std::move(inp.sample_energy)) - , sample_pos_(std::move(inp.sample_pos)) - , sample_dir_(std::move(inp.sample_dir)) + , sample_energy_(inp.sample_energy) + , sample_pos_(inp.sample_pos) + , sample_dir_(inp.sample_dir) { CELER_EXPECT(particles); diff --git a/src/celeritas/user/SimpleCalo.cc b/src/celeritas/user/SimpleCalo.cc index e6b3f4760b..c8b0a1663e 100644 --- a/src/celeritas/user/SimpleCalo.cc +++ b/src/celeritas/user/SimpleCalo.cc @@ -128,6 +128,7 @@ void SimpleCalo::output(JsonPimpl* j) const // Save detector volumes { std::vector ids; + ids.reserve(volume_ids_.size()); for (VolumeId vid : volume_ids_) { ids.push_back(static_cast(vid.get())); diff --git a/src/celeritas/user/SlotDiagnostic.cc b/src/celeritas/user/SlotDiagnostic.cc index 18781919df..1ef7ff21a5 100644 --- a/src/celeritas/user/SlotDiagnostic.cc +++ b/src/celeritas/user/SlotDiagnostic.cc @@ -10,6 +10,7 @@ #include #include +#include "corecel/Macros.hh" #include "corecel/data/AuxParamsRegistry.hh" #include "corecel/data/AuxStateVec.hh" #include "corecel/io/JsonPimpl.hh" @@ -32,7 +33,12 @@ struct SlotDiagnostic::State final : AuxStateInterface std::ofstream outfile; std::vector buffer; - ~State() { CELER_LOG_LOCAL(debug) << "Closing slot diagnostic file"; } + State() = default; + CELER_DEFAULT_MOVE_DELETE_COPY(State); + ~State() final + { + CELER_LOG_LOCAL(debug) << "Closing slot diagnostic file"; + } }; //---------------------------------------------------------------------------// diff --git a/src/corecel/data/CollectionMirror.hh b/src/corecel/data/CollectionMirror.hh index ac1b0881d0..ffd81dc6dd 100644 --- a/src/corecel/data/CollectionMirror.hh +++ b/src/corecel/data/CollectionMirror.hh @@ -48,7 +48,7 @@ namespace celeritas * \endcode */ template class P> -class CollectionMirror : public ParamsDataInterface

+class CollectionMirror final : public ParamsDataInterface

{ public: //!@{ diff --git a/src/corecel/io/ColorUtils.cc b/src/corecel/io/ColorUtils.cc index 0642393e99..fe7da1c5e1 100644 --- a/src/corecel/io/ColorUtils.cc +++ b/src/corecel/io/ColorUtils.cc @@ -102,7 +102,7 @@ char const* color_code(char abbrev) return "\033[31;1m"; case 'W': return "\033[37;1m"; - case ' ': + default: return "\033[0m"; } diff --git a/src/corecel/io/ExceptionOutput.cc b/src/corecel/io/ExceptionOutput.cc index b015918276..139ca0f841 100644 --- a/src/corecel/io/ExceptionOutput.cc +++ b/src/corecel/io/ExceptionOutput.cc @@ -84,6 +84,7 @@ void eptr_to_json(nlohmann::json& j, std::exception_ptr const& eptr) { try_nested_to_json(j, e); } + // NOLINTNEXTLINE(bugprone-empty-catch) catch (...) { } diff --git a/src/corecel/io/LoggerTypes.cc b/src/corecel/io/LoggerTypes.cc index 4d5dc7174f..e4e5f13157 100644 --- a/src/corecel/io/LoggerTypes.cc +++ b/src/corecel/io/LoggerTypes.cc @@ -40,7 +40,7 @@ char const* to_color_code(LogLevel lev) char c = ' '; switch (lev) { - case LogLevel::debug: c = 'x'; break; + case LogLevel::debug: [[fallthrough]]; case LogLevel::diagnostic: c = 'x'; break; case LogLevel::status: c = 'b'; break; case LogLevel::info: c = 'g'; break; diff --git a/src/corecel/io/detail/ReprImpl.cc b/src/corecel/io/detail/ReprImpl.cc index ad6e2ec065..365b81cc65 100644 --- a/src/corecel/io/detail/ReprImpl.cc +++ b/src/corecel/io/detail/ReprImpl.cc @@ -68,6 +68,7 @@ void repr_char(std::ostream& os, char value) std::string char_to_hex_string(unsigned char value) { char buffer[3]; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) int size = std::snprintf(buffer, sizeof(buffer), "%02hhx", value); CELER_ENSURE(size == 2); return {buffer, buffer + 2}; diff --git a/src/corecel/sys/MultiExceptionHandler.cc b/src/corecel/sys/MultiExceptionHandler.cc index c547a86428..a4d7356c26 100644 --- a/src/corecel/sys/MultiExceptionHandler.cc +++ b/src/corecel/sys/MultiExceptionHandler.cc @@ -27,6 +27,7 @@ void log_exception(std::exception const& e, Logger::Message* msg) log_exception(next, msg); *msg << "\n... from: "; } + // NOLINTNEXTLINE(bugprone-empty-catch) catch (...) { // Ignore unknown exception @@ -46,7 +47,7 @@ namespace detail [[noreturn]] void log_and_rethrow_impl(MultiExceptionHandler&& exceptions) { CELER_EXPECT(!exceptions.empty()); - auto exc_vec = exceptions.release(); + auto exc_vec = std::move(exceptions).release(); for (auto eptr_iter = exc_vec.begin() + 1; eptr_iter != exc_vec.end(); ++eptr_iter) @@ -79,7 +80,7 @@ namespace detail { CELER_EXPECT(!exceptions_.empty()); - for (auto eptr : exceptions_) + for (auto const& eptr : exceptions_) { try { diff --git a/src/corecel/sys/MultiExceptionHandler.hh b/src/corecel/sys/MultiExceptionHandler.hh index 1f1cae8cc5..96202455e2 100644 --- a/src/corecel/sys/MultiExceptionHandler.hh +++ b/src/corecel/sys/MultiExceptionHandler.hh @@ -62,7 +62,7 @@ class MultiExceptionHandler bool empty() const { return exceptions_.empty(); } //! Release exceptions for someone else to process (not thread safe) - VecExceptionPtr release() { return std::move(exceptions_); } + VecExceptionPtr release() && { return std::move(exceptions_); } private: VecExceptionPtr exceptions_; diff --git a/src/corecel/sys/ScopedMem.cc b/src/corecel/sys/ScopedMem.cc index bc850ccbc4..265b4ed463 100644 --- a/src/corecel/sys/ScopedMem.cc +++ b/src/corecel/sys/ScopedMem.cc @@ -60,6 +60,7 @@ MemResult get_cpu_mem() result.resident = tinfo.resident_size; } #elif defined(__linux__) + // NOLINTBEGIN(cppcoreguidelines-pro-type-union-access) struct rusage usage; usage.ru_maxrss = 0; if (!getrusage(RUSAGE_SELF, &usage)) @@ -67,6 +68,7 @@ MemResult get_cpu_mem() // Units are kiB! result.hwm = usage.ru_maxrss * 1024u; } + // NOLINTEND(cppcoreguidelines-pro-type-union-access) #elif defined(_WIN32) // Units are B PROCESS_MEMORY_COUNTERS info; @@ -116,7 +118,10 @@ ScopedMem::ScopedMem(std::string_view label, MemRegistry* registry) /*! * Register data on destruction. */ -ScopedMem::~ScopedMem() +// bugprone-exception-escape shouldn't be needed after we upgrade to +// clang-tidy-18 +// NOLINTNEXTLINE(bugprone-exception-escape,performance-noexcept-destructor) +ScopedMem::~ScopedMem() noexcept(!CELERITAS_DEBUG) { if (registry_.value() != nullptr) { diff --git a/src/corecel/sys/ScopedMem.hh b/src/corecel/sys/ScopedMem.hh index c854c199bf..68af7c1049 100644 --- a/src/corecel/sys/ScopedMem.hh +++ b/src/corecel/sys/ScopedMem.hh @@ -9,6 +9,8 @@ #include +#include "corecel/Config.hh" + #include "corecel/cont/InitializedValue.hh" #include "MemRegistry.hh" @@ -56,7 +58,7 @@ class ScopedMem } // Register data on destruction - ~ScopedMem(); + ~ScopedMem() noexcept(!CELERITAS_DEBUG); //! Prevent copying but allow moving CELER_DEFAULT_MOVE_DELETE_COPY(ScopedMem); diff --git a/src/corecel/sys/ScopedMpiInit.cc b/src/corecel/sys/ScopedMpiInit.cc index 69455a18bf..1f139d95ea 100644 --- a/src/corecel/sys/ScopedMpiInit.cc +++ b/src/corecel/sys/ScopedMpiInit.cc @@ -26,6 +26,8 @@ namespace celeritas { //---------------------------------------------------------------------------// +// False positive with clang-tidy-15, need cleanup +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) ScopedMpiInit::Status ScopedMpiInit::status_ = ScopedMpiInit::Status::uninitialized; diff --git a/src/corecel/sys/ScopedSignalHandler.cc b/src/corecel/sys/ScopedSignalHandler.cc index 524503aadb..531b227f9a 100644 --- a/src/corecel/sys/ScopedSignalHandler.cc +++ b/src/corecel/sys/ScopedSignalHandler.cc @@ -21,6 +21,7 @@ namespace { //---------------------------------------------------------------------------// // Bitset of signals that have been called +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) sig_atomic_t volatile g_celer_signal_bits_ = 0; //---------------------------------------------------------------------------// diff --git a/src/corecel/sys/Stream.cc b/src/corecel/sys/Stream.cc index cd63e27a2b..4f424939c6 100644 --- a/src/corecel/sys/Stream.cc +++ b/src/corecel/sys/Stream.cc @@ -198,7 +198,6 @@ Stream::~Stream() * Move construct. */ Stream::Stream(Stream&& other) noexcept - : memory_resource_{other.memory_resource_} { this->swap(other); } diff --git a/src/corecel/sys/TracingSession.cc b/src/corecel/sys/TracingSession.cc index 5566470ad5..e45d7773dd 100644 --- a/src/corecel/sys/TracingSession.cc +++ b/src/corecel/sys/TracingSession.cc @@ -48,7 +48,7 @@ initialize_session(TracingMode mode) noexcept case TracingMode::in_process: return perfetto::kInProcessBackend; case TracingMode::system: - return perfetto::kSystemBackend; + [[fallthrough]]; default: return perfetto::kSystemBackend; } @@ -113,6 +113,7 @@ TracingSession::TracingSession(std::string_view filename) noexcept { if (!filename.empty()) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) fd_ = open(filename.data(), O_RDWR | O_CREAT | O_TRUNC, 0660); } session_->Setup(configure_session(), fd_); diff --git a/src/corecel/sys/TypeDemangler.cc b/src/corecel/sys/TypeDemangler.cc index 95644cf211..a6ead7979f 100644 --- a/src/corecel/sys/TypeDemangler.cc +++ b/src/corecel/sys/TypeDemangler.cc @@ -28,6 +28,7 @@ std::string demangled_typeid_name(char const* typeid_name) std::string result(status == 0 ? demangled : typeid_name); // Free the returned memory + // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) std::free(demangled); #else // __GNUG__ std::string result(typeid_name); diff --git a/src/geocel/GeoParamsInterface.hh b/src/geocel/GeoParamsInterface.hh index 1c70207f77..fe25b59037 100644 --- a/src/geocel/GeoParamsInterface.hh +++ b/src/geocel/GeoParamsInterface.hh @@ -127,7 +127,7 @@ class GeoParamsSurfaceInterface : public GeoParamsInterface public: // Default destructor - virtual ~GeoParamsSurfaceInterface() = 0; + ~GeoParamsSurfaceInterface() override = 0; using GeoParamsInterface::id_to_label; diff --git a/src/geocel/GeoVolumeFinder.cc b/src/geocel/GeoVolumeFinder.cc index 8c5d3fd248..c8fa0b970f 100644 --- a/src/geocel/GeoVolumeFinder.cc +++ b/src/geocel/GeoVolumeFinder.cc @@ -16,7 +16,8 @@ namespace celeritas /*! * Perform the search. */ -VolumeId GeoVolumeFinder::operator()(Label const& label) const noexcept +VolumeId GeoVolumeFinder::operator()(Label const& label) const + noexcept(!CELERITAS_DEBUG) { if (auto id = vols_.find_exact(label)) { diff --git a/src/geocel/GeoVolumeFinder.hh b/src/geocel/GeoVolumeFinder.hh index cc28f5cf49..c37d906b30 100644 --- a/src/geocel/GeoVolumeFinder.hh +++ b/src/geocel/GeoVolumeFinder.hh @@ -7,6 +7,8 @@ //---------------------------------------------------------------------------// #pragma once +#include "corecel/Config.hh" + #include "GeoParamsInterface.hh" namespace celeritas @@ -33,7 +35,7 @@ class GeoVolumeFinder explicit inline GeoVolumeFinder(GeoParamsInterface const& geo); // Perform search - VolumeId operator()(Label const& label) const noexcept; + VolumeId operator()(Label const& label) const noexcept(!CELERITAS_DEBUG); private: VolumeMap const& vols_; diff --git a/src/geocel/ScopedGeantLogger.cc b/src/geocel/ScopedGeantLogger.cc index 81654c2dad..ea013fdc55 100644 --- a/src/geocel/ScopedGeantLogger.cc +++ b/src/geocel/ScopedGeantLogger.cc @@ -17,6 +17,8 @@ #include #include #include + +#include "corecel/Macros.hh" #if G4VERSION_NUMBER >= 1120 # include # define CELER_G4SSBUF 0 @@ -113,6 +115,7 @@ class GeantLoggerAdapter final : public G4coutDestination public: // Assign to Geant handlers on construction GeantLoggerAdapter(); + CELER_DEFAULT_COPY_MOVE(GeantLoggerAdapter); ~GeantLoggerAdapter() final; // Handle error messages @@ -187,6 +190,7 @@ G4int GeantLoggerAdapter::ReceiveG4cerr(G4String const& str) //---------------------------------------------------------------------------// //! Thread-local flag for "ownership" of the Geant4 logger +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) G4ThreadLocal bool g_adapter_active_{false}; //---------------------------------------------------------------------------// diff --git a/src/geocel/g4/GeantGeoParams.cc b/src/geocel/g4/GeantGeoParams.cc index bd02126f61..9a87d50f78 100644 --- a/src/geocel/g4/GeantGeoParams.cc +++ b/src/geocel/g4/GeantGeoParams.cc @@ -106,16 +106,15 @@ std::vector