Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ class TestPreprocessor : public TestFixture {
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") {
Expand Down Expand Up @@ -2294,6 +2296,19 @@ class TestPreprocessor : public TestFixture {
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)