Skip to content

-Wcharacter-conversion warns about explicit cast with {} #164220

@marcmutz

Description

@marcmutz

I don't think this is intended:

void fun(char32_t);
const char16_t c16 = ~~~'
fun(c16); // warning: implicit conversion from 'const char16_t' to 'char32_t' may change the meaning of the represented code unit (OK)
fun(char32_t{c16}); // SAME warning (incl. "implicit conversion")

I explicitly convert, why is it still complaining?

This particular warning was, of course, removed by #163927, but I guess the same still applies for, say, char8_t -> char32_t.

Using parentheses instead of braces fixes the issue, but I'd like to use braces for their static narrowing prevention.

Another thing I noted is that the warning, for the same code, isn't emitted if I make the function containing it constexpr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions