Skip to content

#line takes effect inside skipped groups and does not expand macros #734

Open

Description

@danmar

simplecpp handles #line while the file is read (TokenList::readfile), before conditional inclusion and macros are processed. A
#line in a skipped group therefore still changes the line numbers, and a #line whose operands are macros is ignored.

#if 0
#line 100
#endif
__LINE__

gcc: 4. simplecpp: 101.

Inside a skipped group

Input gcc simplecpp
#if 0 / #line 100 / #endif / __LINE__ 4 101
#ifdef X / #line 100 / #endif / __LINE__ 4 101
#if 0 / #line 100 "x.c" / #endif / __FILE__ "c.c" "x.c"
#if 0 / #line -5 / #endif / int x; int x; error: Invalid character in line directive: '-'. (all output is lost)

Operands are macros

The standard says the tokens after #line are macro-expanded when they don't match one of the two forms directly (C11 §6.10.4p5, C++
[cpp.line]).

Input gcc simplecpp
#define L 200 / #line L / __LINE__ 200 3
#define F "y.c" / #line 10 F / __FILE__ __LINE__ "y.c" 10 "c.c" 10
#define LF 20 "z.c" / #line LF / __FILE__ __LINE__ "z.c" 20 "c.c" 3

Already correct, and must stay correct: #line 10 "f.c" and the GCC line marker # 10 "m.c" (used in preprocessed .i files).

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