public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "b07584 at freescale dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug preprocessor/35010] preprocessor loses leading whitespace
Date: Wed, 08 Apr 2009 17:46:00 -0000 [thread overview]
Message-ID: <20090408174620.1778.qmail@sourceware.org> (raw)
In-Reply-To: <bug-35010-6809@http.gcc.gnu.org/bugzilla/>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2813 bytes --]
------- Comment #3 from b07584 at freescale dot com 2009-04-08 17:46 -------
(In reply to comment #0)
> This testcase:
>
> #define debug(format, ...) format, ## __VA_ARGS__)
> debug(X);
> debug(Y, 1, 2);
> debug(Y, 1, 2 );
> debug(Z, );
> debug(W,);
>
> Should preprocess to:
>
> X);
> Y, 1, 2);
> Y, 1, 2);
> Z, );
> W, );
>
> not:
>
> X);
> Y, 1, 2);
> Y, 1, 2);
> Z,);
> W,);
>
>
> Z/W should have spaces.
>
Chris, I want to make sure I understand what you are saying. With:
#define debug(format, ...) format, ## __VA_ARGS__)
For the the invocation:
debug(X);
- the argument is omitted and hence the comma preceeding ## in the body is
removed in accordance with GNU CPP's extended semantics, yielding:
X);
In contrast, for the invocations:
debug(Z, );
debug(W,);
when you say, the output ought to be:
Z, );
W, );
- is it because a space preceeds the ## in the macro definition (i.e. body)?
So, if the definition were to be:
#define debug(format, ...) format,## __VA_ARGS__)
instead, then:
debug(Z, );
debug(W,);
preprocessing to:
Z,);
W,);
would be OK? This reasoning about the appearance (or non-appearance) of space
is similar to Neil's explanation in the Cpplib Internals manual (for GCC
version 4.4.0) in the section Token Spacing:
#define add(x, y, z) x + y +z
sum = add (1,2, 3)
preprocesses to:
sum = 1 + 2 +3
However in the case at hand, per ISO/IEC 9899:TC2 Committee Draft May 6,
2005 WG14/N1124, 6.10.3.3 "The ## operator", constraint 2: "... however, if an
argument consists of no preprocessing tokens, the parameter is replaced by a
placemarker preprocessing token instead." Further, in constraint 3:
"... concatenation of a placemarker with a non-placemarker preprocessing token
results in the non-placemarker preprocessing token."
By that, the expansion sequence for (say):
debug(Z, );
(with the first definition - i.e. the one with a space before the ##) would
be:
debug(Z, );
->
format, ## __VA_ARGS__)
(CPP_COMMA gets the PASTE_LEFT flag set, and <placemarker> is only conceptually
depicted per constraint 2)
->
CPP_NAME CPP_COMMA[PASTE_LEFT] <placemarker> CPP_CLOSE_PAREN CPP_SEMICOLON
(per constraint 3, CPP_COMMA and <placemarker> concatenate to CPP_COMMA)
->
CPP_NAME CPP_COMMA CPP_CLOSE_PAREN CPP_SEMICOLON
So, the space before the ## does not make it to the expansion because this is
the paste operation in operation - as it proceeds normally.
Or perhaps, I am missing something? Kindly explain. Thanks.
--
b07584 at freescale dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |b07584 at freescale dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35010
next prev parent reply other threads:[~2009-04-08 17:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-29 9:33 [Bug preprocessor/35010] New: " sabre at nondot dot org
2008-05-15 2:55 ` [Bug preprocessor/35010] " neil at gcc dot gnu dot org
2008-05-15 2:57 ` neil at gcc dot gnu dot org
2009-04-08 17:46 ` b07584 at freescale dot com [this message]
2009-04-27 1:31 ` sabre at nondot dot org
2009-04-27 1:32 ` sabre at nondot dot org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090408174620.1778.qmail@sourceware.org \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).