Perceptual Color

staticasserts.cpp
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4/** @internal @file staticasserts.cpp
5 *
6 * This file defines various static asserts for compiling this
7 * library. */
8
9#include <qglobal.h>
10
11static_assert(
12 // Test if the compiler treats the source code actually as UTF-8.
13 // We use the character “🖌” who’s code point is U+1F58C.
14 // We create a string literal in the form U"🖌" which creates a UTF-32
15 // encoded Unicode string. So we expect the first code unit of this string
16 // to be 0x1F58C, which is the correct UTF-32 representation. We do
17 // a static_assert to control if the compiler has actually correctly
18 // interpreted the source code.
19 (*(U"🖌")) == 0x1F58C,
20 "Compiler must use UTF-8 as input character set.\n"
21 "(The source code has to be interpreted as UTF-8 by the compiler.)");
22
23static_assert(
24 // Check if actually the narrow execution character set is UTF-8.
25 // Character 1, first code unit
26 (static_cast<quint8>(*(("🖌") + 0)) == 0xF0)
27 // Character 1, second code unit
28 && (static_cast<quint8>(*(("🖌") + 1)) == 0x9F)
29 // Character 1, third code unit
30 && (static_cast<quint8>(*(("🖌") + 2)) == 0x96)
31 // Character 1, fourth code unit
32 && (static_cast<quint8>(*(("🖌") + 3)) == 0x8C)
33 // Character 2
34 && (static_cast<quint8>(*(("🖌") + 4)) == 0x00),
35 // Provide an error message:
36 "Compiler must use UTF-8 as narrow execution character set.\n"
37 "(char* must contain UTF-8 encoded data.)\n"
38 "Example: gcc -fexec-charset=UTF-8");
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:36 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.