util: make SourceLocation constructor explicit
What changed, and why it matters
This is a minor code-quality change that adds the C++ keyword 'explicit' to a constructor. It prevents the compiler from silently converting other types into a SourceLocation object, following a common C++ best-practice guideline. There is no security bug being fixed here.
No security action needed. This is a routine code-quality improvement. Reviewers may optionally verify that no existing code relied on implicit conversion from const char* to SourceLocation, though such reliance would be unusual.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit marks the SourceLocation constructor in src/util/log.h as explicit. This follows CppCoreGuidelines C.46, which recommends single-argument constructors (or constructors that can be called with one argument due to default parameters) be explicit to avoid unintended implicit conversions. The constructor takes a const char func and an optional std::source_location parameter. Without explicit, a const char could implicitly convert to a SourceLocation. The change is purely defensive coding style and does not address a known vulnerability.
Changed components
src/util/log.hInspect captured patch +3 / −2
diff --git a/src/util/log.h b/src/util/log.h
index 1bec49f2..641b81ff 100644
--- a/src/util/log.h
+++ b/src/util/log.h
@@ -23,8 +23,9 @@ public:
/// The func argument must be constructed from the C++11 __func__ macro.
/// Ref: https://en.cppreference.com/w/cpp/language/function.html#func
/// Non-static string literals are not supported.
- SourceLocation(const char* func,
- std::source_location loc = std::source_location::current())
+ explicit SourceLocation(
+ const char* func,
+ std::source_location loc = std::source_location::current())
: m_func{func}, m_loc{loc} {}
std::string_view file_name() const { return m_loc.file_name(); }
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.