Skip to content

C/C++: a documentation or comment line ending in \ splices the next line of code into the comment, so the output fails to compile #148

Closed

Description

@matt-edmondson

What's wrong

LanguageGeneratorBase.WriteComment (Coder/Languages/LanguageGeneratorBase.cs:234-245) writes each comment line as {prefix} {line}. It is reached from WritePreamble (:293) for documentation, notes and written-down annotations. CFamilyGenerator does not override it.

In C and C++, a backslash at the very end of a line is a line splice. The preprocessor joins it to the next physical line before it strips comments. So a // comment whose text ends in \ swallows the following line of generated code.

Reproduction (gcc / g++, HEAD ad68d48)

A function with Documentation = ["Reads files under C:\\data\\"] generates:

/// Reads files under C:\data\
int describe(void)
{
  • gcc: error: expected identifier or '(' before '{' token
  • g++: error: expected unqualified-id before '{' token

This affects every documentation line, note and annotation comment in the C and C++ generators. Windows paths and regex examples are the obvious triggers. The other five targets don't splice lines, so they're fine.

This is distinct from #107 (trigraphs inside string literals) and #133 (a line break inside a comment escaping it).

Suggested fix / acceptance criteria

  • Override WriteComment in CFamilyGenerator so that a comment line ending in \ gets a non-whitespace terminator, for example by appending a character such as .. A trailing space alone doesn't work: gcc still splices it, with only a warning.
  • Add C and C++ compile tests with a documentation line ending in \, asserting that the generated source compiles and the following declaration survives.

Activity

  1. matt-edmondson commented on Oct 5, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions