From d87835cc9003f43841cce88be499aaf88d431c68 Mon Sep 17 00:00:00 2001 From: Leandro Melo Date: Wed, 29 Aug 2012 13:21:22 +0200 Subject: [PATCH] C++: Always skip unknown preprocessor "directives" Task-number: QTCREATORBUG-7780 Change-Id: Ie93704feff17ad8229e50fb1133048f2c7598dea Reviewed-by: Orgad Shaneh Reviewed-by: hjk --- src/libs/cplusplus/pp-engine.cpp | 4 +-- .../preprocessor/tst_preprocessor.cpp | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index f71ba47c142..377e8c8e94e 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -1417,9 +1417,9 @@ void Preprocessor::handlePreprocessorDirective(PPToken *tk) handleElseDirective(tk, poundToken); else if (directive == ppElif) handleElifDirective(tk, poundToken); - - skipPreprocesorDirective(tk); } + + skipPreprocesorDirective(tk); } diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp index 015fffc153a..d3777d1998a 100644 --- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp +++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp @@ -338,6 +338,8 @@ private slots: void multitokens_argument_data(); void multiline_strings(); void multiline_strings_data(); + void skip_unknown_directives(); + void skip_unknown_directives_data(); }; // Remove all #... lines, and 'simplify' string, to allow easily comparing the result @@ -1394,6 +1396,30 @@ void tst_Preprocessor::multiline_strings_data() QTest::newRow("case 1") << original << expected; } +void tst_Preprocessor::skip_unknown_directives() +{ + compare_input_output(); +} + +void tst_Preprocessor::skip_unknown_directives_data() +{ + QTest::addColumn("input"); + QTest::addColumn("output"); + + QByteArray original; + QByteArray expected; + + // We should skip "weird" things when preprocessing. Particularly useful when we preprocess + // a particular expression from a document which has already been processed. + + original = "# foo\n" + "# 10 \"file.cpp\"\n" + "# ()\n" + "#\n"; + expected = "# 1 \"\"\n"; + QTest::newRow("case 1") << original << expected; +} + void tst_Preprocessor::compare_input_output(bool keepComments) { QFETCH(QByteArray, input);