<div dir="auto"><div>Hello, Richard and thank you for answering. In my codebase this warning ensures compatibility of my codebase with C++20 standard (at the moment I compile it with C++14 because of legacy part, but all new code needs to be C++20 compatible). </div><div dir="auto">I agree that the main reason is to avoid change in behavior, however the given approaches address exactly this and there is no way to explain that to the compiler at the same time. E.g. if I have an overloaded function which takes std::u8string argument instead of std::string, clang doesn't seem to have any facilities to tell if that was done to address the warning or these are two distinct functions.</div><div dir="auto"><br></div><div dir="auto">Am I correct to say that removing all u8 literals is the only portable way to fulfill the warning requirements?</div><div dir="auto"><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Mon, Nov 8, 2021, 09:07 Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr">On Sun, 7 Nov 2021 at 07:29, Aleksandr Medvedev via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" rel="noreferrer">cfe-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello, folks! (And sorry in advance if i'm writing to the wrong address with my question.)<br><br>Recently i've come across a clang warning next to this simple line of code:<br><pre style="font-size:13px;margin-top:0px;padding:12px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:1.30769;vertical-align:baseline;box-sizing:inherit;width:auto;max-height:600px;overflow:auto;border-radius:5px"><code style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;box-sizing:inherit;background-color:transparent;white-space:inherit"><span style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;box-sizing:inherit">auto</span> message = <span style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;box-sizing:inherit">u8"Текст"</span>;</code></pre>which says as follows:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="color:rgb(82,89,96);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Liberation Sans",sans-serif;font-size:15px">type of UTF-8 string literal will change from array of const char to array of const char8_t in C++20</span></blockquote><br>That is a warning which comes <font face="arial, sans-serif">with <span style="color:rgb(35,38,41)"> </span><a href="https://clang.llvm.org/docs/DiagnosticsReference.html#wc-20-compat" rel="nofollow noreferrer noreferrer" style="margin:0px;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit" target="_blank">-W-c++20-compat flag</a><span style="color:rgb(35,38,41)"> and the answer I'm looking for is how to properly make this warning disappear (without suppressing or disabling it).</span></font></div></blockquote><div><br></div><div>Why do you want this warning enabled? Depending on why you want this warning to appear, the answer for how to handle it will be different.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><font face="arial, sans-serif"><span style="color:rgb(35,38,41)">I tried a few approaches from th</span></font><span style="color:rgb(35,38,41);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Liberation Sans",sans-serif">e </span><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1423r2.html#remediation" rel="nofollow noreferrer noreferrer" style="margin:0px;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Liberation Sans",sans-serif;vertical-align:baseline;box-sizing:inherit" target="_blank">P1423R2</a><span style="color:rgb(35,38,41)"><font face="-apple-system, BlinkMacSystemFont, Segoe UI, Liberation Sans, sans-serif"> document, including:</font><br><ul style="font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Liberation Sans",sans-serif"><li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1423r2.html#conversion_fns" rel="nofollow noreferrer noreferrer" style="margin:0px;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Liberation Sans",sans-serif;vertical-align:baseline;box-sizing:inherit" target="_blank">explicit conversion function approach</a><span style="color:rgb(35,38,41);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Liberation Sans",sans-serif"><br></span></li><li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1423r2.html#emulate" rel="nofollow noreferrer noreferrer" style="margin:0px;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Liberation Sans",sans-serif;vertical-align:baseline;box-sizing:inherit" target="_blank">emulation with macroses</a><span style="color:rgb(35,38,41);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Liberation Sans",sans-serif"><br></span></li><li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1423r2.html#reinterpret_cast" target="_blank" rel="noreferrer">reinterpret_cast u8 literals to char</a><br></li></ul><div><font face="-apple-system, BlinkMacSystemFont, Segoe UI, Liberation Sans, sans-serif">Unfortunately neither seems to work. The warning persists probably just because of the fact of having </font><font face="monospace">u8</font><font face="-apple-system, BlinkMacSystemFont, Segoe UI, Liberation Sans, sans-serif"> literal no matter whether i have overloaded functions, wrap it with macroses or try to cast it to "standard" </font><font face="monospace">char</font><font face="-apple-system, BlinkMacSystemFont, Segoe UI, Liberation Sans, sans-serif">. I wonder if i'm missing something? Or the only suitable solution for this warning to vanish is to not use </font><font face="monospace">u8</font><font face="-apple-system, BlinkMacSystemFont, Segoe UI, Liberation Sans, sans-serif"> literals in my code?</font></div></span></div></blockquote><div><br></div><div>The diagnostic also says:</div><div><br></div><div><source>:1:16: note: remove 'u8' prefix to avoid a change of behavior; Clang encodes unprefixed narrow string literals as UTF-8<br></div><div><br></div><div>... so that's one potential option to ensure the code doesn't change meaning in C++20 mode, if you don't need portability to compilers that don't assume UTF-8.</div><div><br></div><div>Another option is to pre-adopt this C++20 feature with -fchar8_t. That again is non-portable, but is available in at least Clang and -- if memory serves -- GCC.</div></div></div>
</blockquote></div></div></div>