Skip to content

PORTABILITY_NO_EOF_NEWLINE is reported for C++ headers because included files are tokenized with an empty DUI #769

Closed

Description

@danmar

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:

if ((cstd != CUnknown || cppstd == CPPUnknown) && !trailing_nl && outputList) {

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

  1. added a commit that references this issue on Nov 20, 2026
    fb1b3be
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions