Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clang-tidy checks, including some use-after-move #1352

Merged
merged 5 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ Checks: |
-cppcoreguidelines-pro-bounds-pointer-arithmetic
-cppcoreguidelines-init-variables
-cppcoreguidelines-pro-type-member-init
-cppcoreguidelines-avoid-do-while
sethrj marked this conversation as resolved.
Show resolved Hide resolved
-cppcoreguidelines-pro-type-const-cast
sethrj marked this conversation as resolved.
Show resolved Hide resolved
-cppcoreguidelines-pro-bounds-array-to-pointer-decay
sethrj marked this conversation as resolved.
Show resolved Hide resolved
-cppcoreguidelines-avoid-const-or-ref-data-members
sethrj marked this conversation as resolved.
Show resolved Hide resolved
-cppcoreguidelines-pro-bounds-constant-array-index
sethrj marked this conversation as resolved.
Show resolved Hide resolved
bugprone-*
-bugprone-sizeof-expression
-bugprone-narrowing-conversions
-bugprone-macro-parentheses
-bugprone-easily-swappable-parameters
sethrj marked this conversation as resolved.
Show resolved Hide resolved
-bugprone-implicit-widening-of-multiplication-result
sethrj marked this conversation as resolved.
Show resolved Hide resolved
CheckOptions:
cppcoreguidelines-macro-usage.CheckCapsOnly: true
cppcoreguidelines-avoid-do-while.IgnoreMacros: true
cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes: true
HeaderFilterRegex: ''
FormatStyle: file
...
6 changes: 3 additions & 3 deletions src/accel/LocalTransporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ LocalTransporter::LocalTransporter(SetupOptions const& options,
inp.num_track_slots = options.max_num_tracks;
inp.action_times = options.action_times;

// Set stream ID for finalizing
hit_manager_.finalizer(HMFinalizer{inp.stream_id});

if (celeritas::device())
{
step_ = std::make_shared<Stepper<MemSpace::device>>(std::move(inp));
Expand All @@ -113,9 +116,6 @@ LocalTransporter::LocalTransporter(SetupOptions const& options,
{
step_ = std::make_shared<Stepper<MemSpace::host>>(std::move(inp));
}

// Set stream ID for finalizing
hit_manager_.finalizer(HMFinalizer{inp.stream_id});
}

//---------------------------------------------------------------------------//
Expand Down
8 changes: 3 additions & 5 deletions src/celeritas/global/Stepper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ template<MemSpace M>
Stepper<M>::Stepper(Input input)
: params_(std::move(input.params))
, state_(*params_, input.stream_id, input.num_track_slots)
{
// Create action sequence
actions_ = [&] {
, actions_{[&] {
ActionSequence::Options opts;
opts.action_times = input.action_times;
return std::make_shared<ActionSequence>(*params_->action_reg(), opts);
}();

}()}
{
// Execute beginning-of-run action
ScopedProfiling profile_this{"begin-run"};
actions_->begin_run(*params_, state_);
Expand Down
5 changes: 3 additions & 2 deletions src/celeritas/global/Stepper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,12 @@ class Stepper final : public StepperInterface
CoreStateInterface const& state() const final { return state_; }

private:
// Params and call sequence
// Params data
std::shared_ptr<CoreParams const> params_;
std::shared_ptr<ActionSequence> actions_;
// State data
CoreState<M> state_;
// Call sequence
std::shared_ptr<ActionSequence> actions_;
};

//---------------------------------------------------------------------------//
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/grid/ValueGridBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ ValueGridXsBuilder::ValueGridXsBuilder(double emin,
CELER_EXPECT(xs_.size() >= 2);
CELER_EXPECT(
is_on_grid_point(log_eprime_, log_emin_, log_emax_, xs_.size() - 1));
CELER_EXPECT(is_nonnegative(make_span(xs)));
CELER_EXPECT(is_nonnegative(make_span(xs_)));
}

//---------------------------------------------------------------------------//
Expand Down
13 changes: 7 additions & 6 deletions src/celeritas/io/detail/ImportDataConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ namespace detail
/*!
* Construct with a unit system.
*/
ImportDataConverter::ImportDataConverter(UnitSystem usys) : usys_{usys}
ImportDataConverter::ImportDataConverter(UnitSystem usys)
: usys_{usys}
, len_(native_value_from(usys_, ImportUnits::len))
, numdens_(native_value_from(usys_, ImportUnits::inv_len_cb))
, time_(native_value_from(usys_, ImportUnits::time))
, xs_(native_value_from(usys_, ImportModelMaterial::xs_units))
, inv_pressure_(native_value_from(usys_, ImportUnits::len_time_sq_per_mass))
{
len_ = native_value_from(usys_, ImportUnits::len);
numdens_ = native_value_from(usys_, ImportUnits::inv_len_cb);
time_ = native_value_from(usys_, ImportUnits::time);
xs_ = native_value_from(usys_, ImportModelMaterial::xs_units);
inv_pressure_ = native_value_from(usys_, ImportUnits::len_time_sq_per_mass);
}

//---------------------------------------------------------------------------//
Expand Down
6 changes: 2 additions & 4 deletions src/corecel/io/OutputRegistry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ void OutputRegistry::output(JsonPimpl* j) const
if (is_global)
{
json_wrap.obj = std::move(cat_result);
}
kv.second->output(&json_wrap);
if (is_global)
{
kv.second->output(&json_wrap);
cat_result = std::move(json_wrap.obj);
}
else
{
kv.second->output(&json_wrap);
cat_result[kv.first] = std::move(json_wrap.obj);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/geocel/ScopedGeantLogger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ G4int log_impl(G4String const& str, LogLevel level)
/*!
* Send Geant4 log messages to Celeritas' world logger.
*/
class GeantLoggerAdapter : public G4coutDestination
class GeantLoggerAdapter final : public G4coutDestination
{
public:
// Assign to Geant handlers on construction
GeantLoggerAdapter();
~GeantLoggerAdapter();
~GeantLoggerAdapter() final;

// Handle error messages
G4int ReceiveG4cout(G4String const& str) final;
Expand Down
2 changes: 1 addition & 1 deletion src/orange/orangeinp/Solid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Solid<T>::Solid(std::string&& label,
, exclusion_{std::move(excluded)}
, enclosed_{std::move(enclosed)}
{
CELER_VALIDATE(exclusion_ || enclosed,
CELER_VALIDATE(exclusion_ || enclosed_,
<< "solid requires either an excluded region or a shape");
CELER_VALIDATE(!exclusion_ || interior_.encloses(*exclusion_),
<< "solid '" << this->label()
Expand Down
4 changes: 2 additions & 2 deletions src/orange/orangeinp/detail/ProtoBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ namespace detail
*/
ProtoBuilder::ProtoBuilder(OrangeInput* inp,
ProtoMap const& protos,
Options&& opts)
Options const& opts)
: inp_{inp}
, protos_{protos}
, save_json_{std::move(opts.save_json)}
, save_json_{opts.save_json}
, bboxes_{protos_.size()}
{
CELER_EXPECT(inp_);
Expand Down
2 changes: 1 addition & 1 deletion src/orange/orangeinp/detail/ProtoBuilder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ProtoBuilder

public:
// Construct with output pointer, geometry construction options, and protos
ProtoBuilder(OrangeInput* inp, ProtoMap const& protos, Options&& opts);
ProtoBuilder(OrangeInput* inp, ProtoMap const& protos, Options const& opts);

//! Get the tolerance to use when constructing geometry
Tol const& tol() const { return inp_->tol; }
Expand Down
Loading