Ticket #7912: Properly preprocess files with decreasing line numbers, due to #line directives.

This commit is contained in:
Simon Martin 2017-03-05 16:46:43 +01:00
parent 6c1096bf71
commit 43e4364675
2 changed files with 16 additions and 1 deletions

View File

@ -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) {

View File

@ -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<std::string, std::string>& 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)