Skip to content

Commit cf532f8

Browse files
authored
Explicitly delete copy constructor and assignment in Timer (#665)
## Summary `Timer::~Timer()` calls `Report()`, logging the elapsed time to a tracer or stdout. With no explicit copy policy, a copied `Timer` would produce a second `Report()` on its own destruction — silently logging a duplicate timing entry for the same measured interval. `tag_` and `t_` are non-owning pointers (no `delete` in the destructor), so there is no memory-safety risk. The issue is purely semantic, but it is a real hazard for callers who pass or store `Timer` by value. Explicitly `= delete` the copy constructor and copy assignment to make the non-copyable intent clear. ## Test plan - [x] `basic/gpu` builds cleanly in debug mode - [x] Full debug build passes with no errors
1 parent 6c7a332 commit cf532f8

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

source/src/basic/gpu/Timer.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public:
3838
Timer(basic::Tracer::TracerProxy& t, const char *tag =nullptr);
3939
Timer();
4040
~Timer();
41+
42+
// ~Timer() calls Report(), so a copy would fire a second Report() on its
43+
// own destruction, silently logging a duplicate timing entry.
44+
Timer(Timer const &) = delete;
45+
Timer & operator=(Timer const &) = delete;
4146
void Report(const char *tag =nullptr);
4247
void Reset();
4348
double GetTime();

0 commit comments

Comments
 (0)