Skip to content

[clang] Diagnostic message are incorrectly wrapped if colors are enabled #164933

@tbaederr

Description

@tbaederr

Because OS.tell() doesn't know about colors so the control characters count into the length as well, which means in

uint64_t StartOfLocationInfo = OS.tell();
// Emit the location of this particular diagnostic.
if (Loc.isValid())
emitDiagnosticLoc(Loc, PLoc, Level, Ranges);
if (DiagOpts.ShowColors)
OS.resetColor();
if (DiagOpts.ShowLevel)
printDiagnosticLevel(OS, Level, DiagOpts.ShowColors);
printDiagnosticMessage(OS,
/*IsSupplemental*/ Level == DiagnosticsEngine::Note,
Message, OS.tell() - StartOfLocationInfo,
DiagOpts.MessageLength, DiagOpts.ShowColors);
}

we calculate the value for CurrentColumn incorrectly. On my terminal $COLUMNS is currently 120 (and llvm figures that out correctly), but the diagnostic message is wrapped even though it would fit in to the previous line just fine (as proven by passing -fmessage-length=130 or -fno-color-diagnostics):

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions