aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-06-17 16:40:04 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2020-06-18 07:52:02 +0000
commit8eac3fba8093750f4dfe6b8ab01f7f998fcadd26 (patch)
tree12e173ea817c54e5ab6182c7cfce200cc4672dd5 /tests/auto
parent1b8c68f61727d6d04b1375b969b5f96688e67fde (diff)
CPlusPlus: Fix lexer crash
At some point in the preprocessing stage, some tokens get "squeezed", so their associated string no longer refers to the document content, but only to their own symbol. However, there is at least one context that operated under the assumption that the token's offset still pointed into the "global" string. As the token's offset is zero after parsing, this lead to the same piece of code being preprocessed in an infinite loop. Fixes: QTCREATORBUG-19525 Change-Id: I231ba51811cfa0b5c6dfe7f75fe0384472252c6f Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp
index 005ea5c1fa..6801240368 100644
--- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp
+++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp
@@ -405,6 +405,7 @@ private slots:
void multi_byte_code_point_in_expansion();
void trigraph();
void nested_arguments_expansion();
+ void preprocessorSymbolsAsMacroArguments();
};
// Remove all #... lines, and 'simplify' string, to allow easily comparing the result
@@ -2099,6 +2100,20 @@ void tst_Preprocessor::nested_arguments_expansion()
QVERIFY(prep.contains(output));
}
+void tst_Preprocessor::preprocessorSymbolsAsMacroArguments()
+{
+ Environment env;
+ Preprocessor preprocess(nullptr, &env);
+ const QByteArray input =
+ "#define IFGEN(if, endif) if (1 == 0) endif\n"
+ "int main()\n"
+ "{\n"
+ "IFGEN(#if, #endif)\n"
+ "return 0;\n"
+ "}\n";
+ QVERIFY(preprocess.run(QLatin1String("<stdin>"), input).startsWith("# 1 \"<stdin>\"\n"));
+}
+
void tst_Preprocessor::excessive_nesting()
{
Environment env;