Wrong or misleading rule asking to use std::byte

See godbolt Compiler Explorer

    std::ifstream file{"somefile.data", std::ios::binary};

    std::array<std::byte, 2048> buf;

    while (file.peek() != EOF){
        [[maybe_unused]] const auto c = file.readsome(reinterpret_cast<char*>(buf.data()), buf.size());

        // Using buf and c
    }

There is a reported issue on the reinterpret_cast<char*> where sonar trigger C++ static code analysis which asks me to use std::byte. Except, as far as I can tell, this is me trying to use std::byte, and there’s no meaningful way to read data directly into this type. I found this paper https://open-std.org/JTC1/SC22/WG21/docs/papers/2020/p2146r2.pdf but it appears that the author declared a loss of interest.

In general, it seems like this rule should have exceptions for calls into standard library functions that don’t support std::byte. Alternatively, the rule should help using APIs that are more friendly to using std::byte.

Hi @torgeir.skogen,
Thanks for raising this point and for adding all the useful information. I agree with you that this is a FP and I created a ticket to follow this up.