<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Concatenation with empty macro argument does not prevent recursive expansion of macro"
href="http://llvm.org/bugs/show_bug.cgi?id=15661">15661</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Concatenation with empty macro argument does not prevent recursive expansion of macro
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.2
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>harald@gigawatt.nl
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>