Add a -Wunmapped-char warning for characters not in the charmap (#1023)

Fixes #1022
This commit is contained in:
Rangi
2022-08-28 15:12:43 -04:00
committed by GitHub
parent d29057e747
commit 8207dc57b7
14 changed files with 58 additions and 11 deletions

View File

@@ -242,6 +242,7 @@ size_t charmap_ConvertNext(char const **input, uint8_t **output)
return 1;
} else if (**input) { // No match found, but there is some input left
int firstChar = **input;
// This will write the codepoint's value to `output`, little-endian
size_t codepointLen = readUTF8Char(output ? *output : NULL,
*input);
@@ -254,6 +255,12 @@ size_t charmap_ConvertNext(char const **input, uint8_t **output)
if (output)
*output += codepointLen;
// Check if the character map is not the default "main" one, or if
// it has any mappings defined
if (strcmp(charmap->name, "main") || charmap->usedNodes > 1)
warning(WARNING_UNMAPPED_CHAR,
"Unmapped character %s\n", printChar(firstChar));
return codepointLen;
} else { // End of input

View File

@@ -38,6 +38,7 @@ static const enum WarningState defaultWarnings[ARRAY_SIZE(warningStates)] = {
[WARNING_OBSOLETE] = WARNING_ENABLED,
[WARNING_SHIFT] = WARNING_DISABLED,
[WARNING_SHIFT_AMOUNT] = WARNING_DISABLED,
[WARNING_UNMAPPED_CHAR] = WARNING_ENABLED,
[WARNING_USER] = WARNING_ENABLED,
[WARNING_NUMERIC_STRING_1] = WARNING_ENABLED,
@@ -85,6 +86,7 @@ static const char * const warningFlags[NB_WARNINGS] = {
"obsolete",
"shift",
"shift-amount",
"unmapped-char",
"user",
// Parametric warnings
@@ -160,6 +162,7 @@ static uint8_t const _wallCommands[] = {
WARNING_LONG_STR,
WARNING_NESTED_COMMENT,
WARNING_OBSOLETE,
WARNING_UNMAPPED_CHAR,
WARNING_NUMERIC_STRING_1,
META_WARNING_DONE
};
@@ -191,6 +194,7 @@ static uint8_t const _weverythingCommands[] = {
WARNING_OBSOLETE,
WARNING_SHIFT,
WARNING_SHIFT_AMOUNT,
WARNING_UNMAPPED_CHAR,
WARNING_NUMERIC_STRING_1,
WARNING_NUMERIC_STRING_2,
WARNING_TRUNCATION_1,