Cpp Core Guidelines: "const char *" to "const uint8_t *" without reinterpret_cast and C-style cast?

177 Views Asked by At

For code like this:

#include <cstdint>

extern const char *f();
extern void g(const uint8_t *);

int main()
{
    const char *p = f();
    g(reinterpret_cast<const uint8_t *>(p));
}

clang-tidy -checks='cppcoreguidelines-*' generates warning:

do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast]

and indeed there is such paragraph in CppCoreGuidelines.

But how it is possible to avoid reinterpret_cast or C-style cast for case like const char * -> const uint8_t *?

Is this bug in CppCoreGuidelines ?

0

There are 0 best solutions below