From c504e56d0c7fafba4f8c15997e3927b5ca02adc5 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> Date: Tue, 1 Sep 2015 14:34:29 +0200 Subject: [PATCH] C++: Fix MSVC assert in std::isspace() ...when dealing with UTF8 bytes. std::isspace() expects unsigned char, not char. Change-Id: I3f9b5e347d79cf94015cc99f8797d5feab406151 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com> --- src/libs/cplusplus/pp-engine.cpp | 2 +- .../preprocessor/tst_preprocessor.cpp | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index fa96c54176d..93a6e451b4d 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -2129,7 +2129,7 @@ void Preprocessor::maybeStartOutputLine() // If previous line ends with \ (possibly followed by whitespace), add another \n const char *start = buffer.constData(); const char *ch = start + buffer.length() - 2; - while (ch > start && (*ch != '\n') && std::isspace(*ch)) + while (ch > start && (*ch != '\n') && pp_isspace(*ch)) --ch; if (*ch == '\\') buffer.append('\n'); diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp index 376716a9e78..47eb297ded2 100644 --- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp +++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp @@ -409,6 +409,7 @@ private slots: void undef(); void concat(); void excessive_nesting(); + void multi_byte_code_point_in_expansion(); }; // Remove all #... lines, and 'simplify' string, to allow easily comparing the result @@ -2064,6 +2065,26 @@ void tst_Preprocessor::excessive_nesting() QCOMPARE(prep, output); } +void tst_Preprocessor::multi_byte_code_point_in_expansion() +{ + Environment env; + Preprocessor preprocess(0, &env); + const QByteArray input = + "#define FOO(x) x\n" + "FOO(arg" UC_U00FC "\n)\n"; + + const QByteArray actual = preprocess.run(QLatin1String("<stdin>"), input); + + const QByteArray expected = + "# 1 \"<stdin>\"\n" + "\n" + "# expansion begin 17,3 2:4\n" + "arg" UC_U00FC "\n" + "# expansion end\n" + "# 4 \"<stdin>\"\n"; + QCOMPARE(actual, expected); +} + void tst_Preprocessor::compare_input_output(bool keepComments) { QFETCH(QByteArray, input); -- GitLab