Truncation warnings on UDLs #226
-
Problem statementTypical UDL definition for quantities: inline namespace literals {
constexpr auto operator"" _q_km(unsigned long long l) { return length<kilometre, std::int64_t>(l); }
constexpr auto operator"" _q_km(long double l) { return length<kilometre, long double>(l); }
} when compiled with Please vore on the below solutions |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
Solution 1 (current state)Disable the warning for the entire project: The downside is the fact that if a user has this warning enabled for his/her project the warning will appear and possibly will prevent the successful compilation (if |
Beta Was this translation helpful? Give feedback.
-
Solution 2Add explicit inline namespace literals {
constexpr auto operator"" _q_km(unsigned long long l) { return length<kilometre, std::int64_t>(static_cast<std::int64_t>(l)); }
constexpr auto operator"" _q_km(long double l) { return length<kilometre, long double>(static_cast<std::int64_t>(l)); }
} The downside is that it hides a possible issue from the user. |
Beta Was this translation helpful? Give feedback.
-
Solution 3Make them |
Beta Was this translation helpful? Give feedback.
Solution 3
Make them
consteval
, and add agsl_Expects(std::in_range<std::int64_t>(l));
contract statement.