<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Actually, most of the time there is actually an option 3. Add yet another overload, this time for int. This will match the 0 literal without any conversion, and we can then just call the nullptr overload inside. Unfortunately, C++20 still does not have constexpr
 parameters, else we could ensure at compile time that only 0 is allowed. Currently, we can only add a runtime assert as far as I can see.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
The described technique  does of course only work when there is no need for a useful int overload, but at least for QByteArray that is not an issue as far as I can see. Also, it might be a good idea to delete the char overload, else  calling QByteArray::prepend
 with a character literal will "work" but it would have unexpected behaviour.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
See <a href="https://godbolt.org/z/e6OinY" id="LPlnk733762">https://godbolt.org/z/e6OinY</a> for how this would look for a trivial function.</div>
<div id="LPBorder_GTaHR0cHM6Ly9nb2Rib2x0Lm9yZy96L2U2T2luWQ.." class="LPBorder543237" contenteditable="false" style="width: 100%; margin-top: 16px; margin-bottom: 16px; position: relative; max-width: 800px; min-width: 424px;">
<table id="LPContainer543237" role="presentation" style="padding: 12px 36px 12px 12px; width: 100%; border-width: 1px; border-style: solid; border-color: rgb(200, 200, 200); border-radius: 2px;">
<tbody>
<tr valign="top" style="border-spacing: 0px;">
<td>
<div id="LPImageContainer543237" style="position: relative; margin-right: 12px; height: 160px; overflow: hidden; width: 240px;">
<a target="_blank" id="LPImageAnchor543237" href="https://godbolt.org/z/e6OinY"><img id="LPThumbnailImageId543237" alt="" height="160" style="display: block;" width="156" src="https://github.com/mattgodbolt/compiler-explorer-image/blob/master/logo/favicon.png?raw=true"></a></div>
</td>
<td style="width: 100%;">
<div id="LPTitle543237" style="font-size: 21px; font-weight: 300; margin-right: 8px; font-family: wf_segoe-ui_light, "Segoe UI Light", "Segoe WP Light", "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; margin-bottom: 12px;">
<a target="_blank" id="LPUrlAnchor543237" href="https://godbolt.org/z/e6OinY" style="text-decoration: none; color: var(--themePrimary);">Compiler Explorer - C++</a></div>
<div id="LPDescription543237" style="font-size: 14px; max-height: 100px; color: rgb(102, 102, 102); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; margin-bottom: 12px; margin-right: 8px; overflow: hidden;">
auto test(const char* c) -> int { return 0; } auto test(const char8_t* u) -> int { return 1; } static_assert(std::is_same_v<decltype(0), int>); [[deprecated("This overload is only meant to cover nullpointers passed as 0/NULL, please use nullptr instead")]]
 int test(int n) { assert(n == 0); return 2; } int test(std::nullptr_t) {return 3;} int test(char) = delete; // not required, but might be a good idea int main() { // test('c'); deleted assert( test(nullptr) + test("Hallo!") + test(u8"Ça va?") + test(0) ==
 6); return 0; }</div>
<div id="LPMetadata543237" style="font-size: 14px; font-weight: 400; color: rgb(166, 166, 166); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif;">
godbolt.org</div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Fabian</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>--<br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div>Fabian Kosmale<br>
</div>
<div>Software Engineer</div>
<div><br>
</div>
<div>The Qt Company GmbH<br>
</div>
<div><span style="background-color: var(--white);">Erich-Thilo-Str. 10</span></div>
<div><span style="background-color: var(--white);">D-12489 Berlin</span><br>
</div>
<div>fabian.kosmale@qt.io<br>
</div>
<div>+49 1638686070<br>
</div>
<div>http://qt.io<br>
</div>
<div><br>
</div>
<div>Geschäftsführer: Mika Pälsi,<br>
</div>
<div>Juha Varelius, Mika Harjuaho<br>
</div>
<div>Sitz der Gesellschaft: Berlin,<br>
</div>
<div>Registergericht: Amtsgericht<br>
</div>
<div>Charlottenburg, HRB 144331 B<br>
</div>
<span>--</span><br>
</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Von:</b> Development <development-bounces@qt-project.org> im Auftrag von Mutz, Marc via Development <development@qt-project.org><br>
<b>Gesendet:</b> Samstag, 6. Juli 2019 12:43<br>
<b>An:</b> development@qt-project.org<br>
<b>Betreff:</b> [Development] Oslo, we have a problem</apollo 13> [char8_t]</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hi,<br>
<br>
C++20 is coming along, and it brings a disruptive change, one that far <br>
surpasses the C++17 noexcept break: u8"Hello" is now const char8_t[], no <br>
longer const char[].<br>
<br>
To estimate the amount of breakage this will cause, assuming that using <br>
u8"" is good practice today, to indicate that a string is in UTF-8. I've <br>
tried to have at least QByteArray not break... and failed.<br>
<br>
The initial idea is simple enough: add const char8_t* overloads for <br>
const char* functions. This breaks passing nullptr, so you also add <br>
std::nullptr_t overloads. This, however, still doesn't fix the case <br>
where a 0 is passed. I've expected that the std::nullptr_t overload is a <br>
preferred match over the const char[8_t]* ones, but GCC 9.1 disagrees, <br>
and tells me it's still ambiguous.<br>
<br>
So, if GCC is right, we have no way of adapting our API to not break in <br>
C++20. So we need to decide what to break:<br>
<br>
a) using 0 for nullptr, or<br>
b) using u8"Hello" at all<br>
<br>
The forward-looking choice would be to break (a) and support (b).<br>
<br>
Opinions?<br>
<br>
Thanks,<br>
Marc<br>
_______________________________________________<br>
Development mailing list<br>
Development@qt-project.org<br>
<a href="https://lists.qt-project.org/listinfo/development">https://lists.qt-project.org/listinfo/development</a><br>
</div>
</span></font></div>
</body>
</html>