-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: should avoid implicit conversions in pushKV
params
#5719
fix: should avoid implicit conversions in pushKV
params
#5719
Conversation
should fix compilation errors like ``` masternode/meta.cpp:43:9: error: call to member function 'pushKV' is ambiguous ret.pushKV("lastOutboundAttemptElapsed", now - lastOutboundAttempt); ^~ masternode/meta.cpp:45:9: error: call to member function 'pushKV' is ambiguous ret.pushKV("lastOutboundSuccessElapsed", now - lastOutboundSuccess); ^~ ``` on FreeBSD + clang-15 kudos to MrDefacto for finding the issue and testing the fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK; that's a simpler solution than I figured out!
I had figured out this "fix" but this is simplier
Subject: [PATCH] fix: conceptize univalue
---
Index: src/univalue/include/univalue.h
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h
--- a/src/univalue/include/univalue.h (revision 76a086f3e8414a7b1953ee0b879d45e579edb4fc)
+++ b/src/univalue/include/univalue.h (date 1700371705464)
@@ -23,18 +23,9 @@
typ = initialType;
val = initialStr;
}
- UniValue(uint64_t val_) {
- setInt(val_);
- }
- UniValue(int64_t val_) {
- setInt(val_);
- }
UniValue(bool val_) {
setBool(val_);
}
- UniValue(int val_) {
- setInt(val_);
- }
UniValue(double val_) {
setFloat(val_);
}
@@ -45,6 +36,9 @@
std::string s(val_);
setStr(s);
}
+ UniValue(std::integral auto val_) {
+ setInt(val_);
+ }
void clear();
@@ -53,7 +47,12 @@
bool setNumStr(const std::string& val);
bool setInt(uint64_t val);
bool setInt(int64_t val);
- bool setInt(int val_) { return setInt((int64_t)val_); }
+ bool setInt(std::integral auto val_) {
+ if constexpr (std::is_unsigned_v<decltype(val)>) {
+ return setInt((uint64_t)val_);
+ }
+ return setInt((int64_t)val_);
+ }
bool setFloat(double val);
bool setStr(const std::string& val);
bool setArray();
@@ -122,26 +121,17 @@
std::string _val(val_);
return pushKV(key, _val);
}
- bool pushKV(const std::string& key, int64_t val_) {
+ template<class T>
+ bool pushKV(const std::string& key, T val_) {
+ static_assert(std::is_trivially_copy_constructible_v<T>, "Type is not trivially copy constructable");
UniValue tmpVal(val_);
return pushKV(key, tmpVal);
}
- bool pushKV(const std::string& key, uint64_t val_) {
- UniValue tmpVal(val_);
- return pushKV(key, tmpVal);
- }
- bool pushKV(const std::string& key, bool val_) {
- UniValue tmpVal(val_);
- return pushKV(key, tmpVal);
+ template<class T>
+ bool pushKV(const std::string& key, const std::atomic<T>& val_) {
+ return pushKV(key, val_.load());
}
- bool pushKV(const std::string& key, int val_) {
- UniValue tmpVal((int64_t)val_);
- return pushKV(key, tmpVal);
- }
- bool pushKV(const std::string& key, double val_) {
- UniValue tmpVal(val_);
- return pushKV(key, tmpVal);
- }
+
bool pushKVs(const UniValue& obj);
std::string write(unsigned int prettyIndent = 0,
## Issue being fixed or feature implemented Should fix compilation errors like ``` masternode/meta.cpp:43:9: error: call to member function 'pushKV' is ambiguous ret.pushKV("lastOutboundAttemptElapsed", now - lastOutboundAttempt); ^~ masternode/meta.cpp:45:9: error: call to member function 'pushKV' is ambiguous ret.pushKV("lastOutboundSuccessElapsed", now - lastOutboundSuccess); ^~ ``` on FreeBSD + clang-15 kudos to @MrDefacto for finding the issue and testing the fix ## What was done? Specify `now` variable type explicitly instead of relying on `auto` ## How Has This Been Tested? MrDefacto confirmed it compiles with no issues on FreeBSD now ## Breaking Changes n/a ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_
Issue being fixed or feature implemented
Should fix compilation errors like
on FreeBSD + clang-15
kudos to @MrDefacto for finding the issue and testing the fix
What was done?
Specify
now
variable type explicitly instead of relying onauto
How Has This Been Tested?
MrDefacto confirmed it compiles with no issues on FreeBSD now
Breaking Changes
n/a
Checklist: