Skip to content

Commit 19a1942

Browse files
Fix BIOIMAGE_PROFILE_SCOPE to generate unique identifiers
`_bp_##__LINE__` does not expand __LINE__ (token-paste suppresses operand expansion), so every BIOIMAGE_PROFILE_SCOPE declared the same identifier `_bp___LINE__`. It compiled only because each call site happened to wrap its scope in its own block; two scopes in one block (the documented per-phase pattern) would be a redefinition error in BIOIMAGE_PROFILE=ON builds. Add the standard two-level concat indirection so __LINE__ is expanded first. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 38d395e commit 19a1942

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

include/bioimage_cpp/detail/profile.hxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ inline ProfileTimerNull make_profile_timer(NullProfiler &profiler, const char *n
8989
} // namespace bioimage_cpp::detail
9090

9191
#define BIOIMAGE_PROFILE_INIT(var) ::bioimage_cpp::detail::Profiler var;
92-
#define BIOIMAGE_PROFILE_SCOPE(var, name) auto _bp_##__LINE__ = ::bioimage_cpp::detail::make_profile_timer(var, name);
92+
// Two-level indirection so __LINE__ is expanded before the token paste; without
93+
// it every BIOIMAGE_PROFILE_SCOPE in a translation unit would declare the same
94+
// identifier `_bp___LINE__`, breaking two scopes in one block.
95+
#define BIOIMAGE_PROFILE_CONCAT_(a, b) a##b
96+
#define BIOIMAGE_PROFILE_CONCAT(a, b) BIOIMAGE_PROFILE_CONCAT_(a, b)
97+
#define BIOIMAGE_PROFILE_SCOPE(var, name) auto BIOIMAGE_PROFILE_CONCAT(_bp_, __LINE__) = ::bioimage_cpp::detail::make_profile_timer(var, name);
9398
#define BIOIMAGE_PROFILE_REPORT(var) (var).report();
9499

95100
#else

0 commit comments

Comments
 (0)