Merge pull request #874 from simartin/ticket_7912

Ticket #7912: Properly preprocess files with decreasing line numbers, due to #line directives
This commit is contained in:
Daniel Marjamäki 2017-03-05 20:33:53 +01:00 committed by GitHub
commit 2daf7f5430
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; line = tok->location.line;
} }
if (tok->previous && line == tok->location.line) if (tok->previous && line >= tok->location.line) // #7912
ret << ' '; ret << ' ';
bool newline = false; bool newline = false;
while (tok->location.line > line) { while (tok->location.line > line) {

View File

@ -240,6 +240,8 @@ private:
TEST_CASE(testDirectiveIncludeTypes); TEST_CASE(testDirectiveIncludeTypes);
TEST_CASE(testDirectiveIncludeLocations); TEST_CASE(testDirectiveIncludeLocations);
TEST_CASE(testDirectiveIncludeComments); TEST_CASE(testDirectiveIncludeComments);
TEST_CASE(testSameLine); // #7912
} }
void preprocess(const char* code, std::map<std::string, std::string>& actual, const char filename[] = "file.c") { 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()); 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) REGISTER_TEST(TestPreprocessor)