This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

preprocessor/9764: Varargs macro extension incorrectly expands if the varargs argument is the macro itself


>Number:         9764
>Category:       preprocessor
>Synopsis:       Varargs macro extension incorrectly expands if the varargs argument is the macro itself
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 19 22:15:59 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     rpm31 at student dot canterbury dot ac dot nz
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
SunOS 5.9 Generic sun4u sparc

Reading specs from /usr/local/gnu/pkg/gcc/2.95.2/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /usr/local/gnu/pkg/gcc/2.95.2/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/cpp -lang-c -v -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(svr4) -D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) -
GNU CPP version 2.95.2 19991024 (release) (sparc)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/gnu/pkg/gcc/2.95.2/include
 /usr/local/gnu/pkg/gcc/2.95.2/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../sparc-sun-solaris2.7/include
 /usr/local/gnu/pkg/gcc/2.95.2/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/local/gnu/pkg/gcc/2.95.2/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../include/g++-3
End of omitted list.
>Description:
When using the varargs macro extension, the preprocessor incorrectly expands the macro if one of the variable arguments is the macro name itself. The problem does not occur if the macro name is used as one of the other arguments or if another macro definition is used as one of the varargs arguments. The problem does not occur if the token paste (for allowing no variable arguments) is ommitted.
>How-To-Repeat:
<code>
#define func(a, varargs...) _func(a, ##b)

func(a, func(a, b));
</code>

Expands as: _func(a, func(a, b))
>Fix:
Workaround hacks include using two macros (one for the call and one for the argument), removing the token paste operator (this reduces flexibility however) and preprocessing twice (yuck).
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]