[LLVMbugs] [Bug 15661] New: Concatenation with empty macro argument does not prevent recursive expansion of macro

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Apr 3 11:19:37 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=15661

            Bug ID: 15661
           Summary: Concatenation with empty macro argument does not
                    prevent recursive expansion of macro
           Product: clang
           Version: 3.2
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: harald at gigawatt.nl
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Prompted by a bug report to GCC:

#define foo(x, y) x ## y
1
foo(f,oo(,))
2
foo(,foo(,))
3
foo(a,foo(,))
4

is preprocessed to

$ clang -std=c99 -E bug.c
# 1 "bug.c"
# 1 "bug.c" 1
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 152 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "bug.c" 2

1
foo(,)
2

3
afoo(,)
4

The expansion between 1 and 2 is correct, and shows that as the inner foo only
appears after concatenation, it is not expanded because it is seen in the
context of another foo macro expansion.

The expansion between 3 and 4 is correct, and shows that as the macro argument
is used as an operand to ##, it is not expanded.

The expansion between 2 and 3 is wrong, I believe: the inner foo should not be
expanded during argument substitution because it is used as an operand of ##,
and it should not be expanded after argument substitution because that happens
in the context of the outer foo macro expansion. There are no other moments
when it could be expanded.

This happens with Fedora 18's clang 3.2:
$ clang -v
clang version 3.2 (tags/RELEASE_32/final)
Target: x86_64-redhat-linux-gnu
Thread model: posix

Apologies if this is fixed already, but I cannot find a bugreport about this,
closed or open.

gcc and mcpp both give the expected output:

$ gcc -std=c99 -E bug.c
# 1 "bug.c"
# 1 "<command-line>"
# 1 "bug.c"

1
foo(,)
2
foo(,)
3
afoo(,)
4

$ mcpp bug.c
#line 1 "/home/harald/bug.c"

1
foo (,)
2
foo (,)
3
afoo (,)
4

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130403/31172db2/attachment.html>


More information about the llvm-bugs mailing list