File indexing completed on 2024-05-12 04:44:35

0001 // SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
0002 // SPDX-License-Identifier: BSD-2-Clause OR MIT
0003 
0004 /** @internal @file staticasserts.cpp
0005  *
0006  * This file defines various static asserts for compiling this
0007  * library. */
0008 
0009 #include <qglobal.h>
0010 
0011 static_assert(
0012     // Test if the compiler treats the source code actually as UTF-8.
0013     // We use the character “🖌” who’s code point is U+1F58C.
0014     // We create a string literal in the form U"🖌" which creates a UTF-32
0015     // encoded Unicode string. So we expect the first code unit of this string
0016     // to be 0x1F58C, which is the correct UTF-32 representation. We do
0017     // a static_assert to control if the compiler has actually correctly
0018     // interpreted the source code.
0019     (*(U"🖌")) == 0x1F58C,
0020     "Compiler must use UTF-8 as input character set.\n"
0021     "(The source code has to be interpreted as UTF-8 by the compiler.)");
0022 
0023 static_assert(
0024     // Check if actually the narrow execution character set is UTF-8.
0025     // Character 1, first code unit
0026     (static_cast<quint8>(*(("🖌") + 0)) == 0xF0)
0027         // Character 1, second code unit
0028         && (static_cast<quint8>(*(("🖌") + 1)) == 0x9F)
0029         // Character 1, third code unit
0030         && (static_cast<quint8>(*(("🖌") + 2)) == 0x96)
0031         // Character 1, fourth code unit
0032         && (static_cast<quint8>(*(("🖌") + 3)) == 0x8C)
0033         // Character 2
0034         && (static_cast<quint8>(*(("🖌") + 4)) == 0x00),
0035     // Provide an error message:
0036     "Compiler must use UTF-8 as narrow execution character set.\n"
0037     "(char* must contain UTF-8 encoded data.)\n"
0038     "Example: gcc -fexec-charset=UTF-8");