I am using SonarQube server.
It reports an issue "Remove this "noexcept" clause on the function declaration as it can throw." in following code.
However in C++23, “throw” has a different meaning in a "if consteval" code block. In that case throw is never exercice at runtime. Either this statement will stop the compilation process immediately (case of consteval) or it is a no-op (runtime case, so noexcept is valid).
I suggest this check cpp:S3743 to not mark the throw statement as an issue in a if consteval code block.
template <size_t N>
class axstring
{
public:
constexpr explicit axstring(const char* src) noexcept
{
const size_t src_len = std::char_traits<char>::length(src);
if (src_len > N)
{
if consteval
{
throw std::out_of_range(message);
}
logging::error("Truncation occurred when copying {} bytes to axstring<{}>", src_len, N);
}
const size_t len = std::min(src_len, N);
std::char_traits<char>::copy(data_, src, len);
data_[len] = 0;
}
private:
char data_[N + 1]{}; // NOSONAR
};