From 43e4364675d4d47125b0d919039ba73dd4f6376e Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sun, 5 Mar 2017 16:46:43 +0100 Subject: [PATCH] Ticket #7912: Properly preprocess files with decreasing line numbers, due to #line directives. --- lib/preprocessor.cpp | 2 +- test/testpreprocessor.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index e33073b9b..1e7533942 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -615,7 +615,7 @@ std::string Preprocessor::getcode(const simplecpp::TokenList &tokens1, const std line = tok->location.line; } - if (tok->previous && line == tok->location.line) + if (tok->previous && line >= tok->location.line) // #7912 ret << ' '; bool newline = false; while (tok->location.line > line) { diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 05a2bbb53..1eb540988 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -240,6 +240,8 @@ private: TEST_CASE(testDirectiveIncludeTypes); TEST_CASE(testDirectiveIncludeLocations); TEST_CASE(testDirectiveIncludeComments); + + TEST_CASE(testSameLine); // #7912 } void preprocess(const char* code, std::map& actual, const char filename[] = "file.c") { @@ -2294,6 +2296,19 @@ private: ASSERT_EQUALS(dumpdata, ostr.str()); } + void testSameLine() { // Ticket #7912 + const char code[] = "#line 1 \"bench/btl/libs/BLAS/blas_interface_impl.hh\" \n" + "template < > class blas_interface < float > : public c_interface_base < float > \n" + "{ } ;\n" + "#line 1 \"bench/btl/libs/BLAS/blas_interface_impl.hh\" \n" + "template < > class blas_interface < double > : public c_interface_base < double > \n" + "{ } ;"; + const char exp[] = "template < > class blas_interface < float > : public c_interface_base < float >\n" + "{ } ; template < > class blas_interface < double > : public c_interface_base < double > { } ;"; + Preprocessor preprocessor(settings0, this); + ASSERT_EQUALS(exp, preprocessor.getcode(code, "", "test.cpp")); + } + }; REGISTER_TEST(TestPreprocessor)