Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 0 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,7 @@ int main(int argc, char **argv)
break;
case simplecpp::Output::PORTABILITY_BACKSLASH:
case simplecpp::Output::PORTABILITY_LINE_DIRECTIVE:
std::cerr << "portability: ";
break;
case simplecpp::Output::PORTABILITY_NO_EOF_NEWLINE:
if (simplecpp::getCStd(dui.std) == simplecpp::CUnknown) {
// Only UB for c code, suppress for c++ code
// If no standard is specified then prefer to have a false negative
continue;
}
std::cerr << "portability: ";
break;
case simplecpp::Output::UNHANDLED_CHAR_ERROR:
Expand Down
4 changes: 2 additions & 2 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,11 +1022,11 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
location.adjust(currentToken);
}

if (!trailing_nl && outputList) {
if ((cstd != CUnknown || (cstd == CUnknown && cppstd == CPPUnknown)) && !trailing_nl && outputList) {
Comment thread
glankk marked this conversation as resolved.
Outdated
Output err{
Output::PORTABILITY_NO_EOF_NEWLINE,
location,
"No newline at end of file."
"No newline at end of file is undefined behavior in C."
};
outputList->emplace_back(std::move(err));
}
Expand Down
18 changes: 13 additions & 5 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3480,13 +3480,21 @@ static void readfile_no_eof_newline()
const char code[] = "\\\n";
simplecpp::OutputList outputList;
readfile(code, sizeof(code)-1, {}, &outputList);
ASSERT_EQUALS("file0,1,portability_no_eof_newline,No newline at end of file.\n", toString(outputList));
ASSERT_EQUALS("file0,1,portability_no_eof_newline,No newline at end of file is undefined behavior in C.\n", toString(outputList));
}
{
const char code[] = "\\\n";
simplecpp::DUI dui;
dui.std = "c++03";
simplecpp::OutputList outputList;
readfile(code, sizeof(code)-1, dui, &outputList);
ASSERT_EQUALS("", toString(outputList));
}
{
const char code[] = "#define A";
simplecpp::OutputList outputList;
readfile(code, sizeof(code)-1, {}, &outputList);
ASSERT_EQUALS("file0,1,portability_no_eof_newline,No newline at end of file.\n", toString(outputList));
ASSERT_EQUALS("file0,1,portability_no_eof_newline,No newline at end of file is undefined behavior in C.\n", toString(outputList));
}
{
const char code[] = "#define A\n";
Expand All @@ -3498,13 +3506,13 @@ static void readfile_no_eof_newline()
const char code[] = "#define A\\";
simplecpp::OutputList outputList;
readfile(code, sizeof(code)-1, {}, &outputList);
ASSERT_EQUALS("file0,1,portability_no_eof_newline,No newline at end of file.\n", toString(outputList));
ASSERT_EQUALS("file0,1,portability_no_eof_newline,No newline at end of file is undefined behavior in C.\n", toString(outputList));
}
{
const char code[] = "// comment";
simplecpp::OutputList outputList;
readfile(code, sizeof(code)-1, {}, &outputList);
ASSERT_EQUALS("file0,1,portability_no_eof_newline,No newline at end of file.\n", toString(outputList));
ASSERT_EQUALS("file0,1,portability_no_eof_newline,No newline at end of file is undefined behavior in C.\n", toString(outputList));
}
{
const char code[] = "// comment\n";
Expand All @@ -3516,7 +3524,7 @@ static void readfile_no_eof_newline()
const char code[] = "/* comment \n comment */";
simplecpp::OutputList outputList;
readfile(code, sizeof(code)-1, {}, &outputList);
ASSERT_EQUALS("file0,2,portability_no_eof_newline,No newline at end of file.\n", toString(outputList));
ASSERT_EQUALS("file0,2,portability_no_eof_newline,No newline at end of file is undefined behavior in C.\n", toString(outputList));
}
{
const char code[] = "/* comment \n comment */\n";
Expand Down
Loading