You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PORTABILITY_NO_EOF_NEWLINE is reported for C++ headers because included files are tokenized with an empty DUI #769
In 1.10.0, PORTABILITY_NO_EOF_NEWLINE ("No newline at end of file is undefined behavior in C.") is reported for headers that are included from C++ code.
In C++11 and later, a missing trailing newline is well-defined.
Cause
TokenList::readfile() decides whether to warn based on the standard in the DUI:
When an included file is loaded, FileDataCache::tryload() creates its TokenList with an empty DUI:
auto *const data = new FileData {path, TokenList(path, filenames, {}, outputList)};
Because the DUI is empty, cstd and cppstd are both unknown, so the warning fires for every header without a trailing newline. It doesn't matter which
standard the caller passed.
Reproduce
main.cpp:
#include"h.h"
h.h (no newline at end of file):
int x;
Preprocess main.cpp with dui.std = "c++11". You get a PORTABILITY_NO_EOF_NEWLINE output for h.h. If main.cpp itself has no trailing newline, it
is correctly not warned about.
Activity
Fix #769 (PORTABILITY_NO_EOF_NEWLINE is reported for C++ headers beca…