Skip to content

Empty macro expansion from inside another macro causes incorrect placement of expanded macro #18859

@llvmbot

Description

@llvmbot
Bugzilla Link 18485
Version unspecified
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @DougGregor

Extended Description

Empty macro expansion from inside another macro causes incorrect placement of expanded macro.
Consider the example:

#define B

#define A(type) B unsigned type
/*
empty lines
...
...
...
...*/
A(int) foo()
{}

The clang preprocessor (-E option) will output the following:

#line 1 "D:/home/paul/sample.c"
#line 1 "<built-in>"
#line 1 "<built-in>"
#line 156 "<built-in>"
#line 1 "<command line>"
#line 1 "<built-in>"
#line 1 "D:/home/paul/sample.c" unsigned int
#line 10 "D:/home/paul/sample.c"
       foo()
{}

Take a note, that the return type of the foo function is placed before #line 10, meaning that it is placed before the whitespace, thus incorrectly pointing the start position of the foo to line 1 instead of line 10.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions