PATCH: In -traditional mode, ignore token pasting and stringification (PR16371)
aseipp at pobox.com
Fri Jul 5 15:44:03 PDT 2013
Attached is a patch that makes the preprocessor ignore token pasting
(##) and stringification (#) when in -traditional mode. This makes it
behave more like GCC.
This change fixes PR16371, and is needed for Clang to function
properly as a preprocessor for Haskell (in the Glasgow Haskell
Compiler.) If you're curious and look at the bug, I made some
incorrect assumptions about the behavior of -traditional for GCC (and
attached a bad patch,) but this fixes the problem in the principled
way. And the patch is simpler, which is good too.
There is something this patch does not handle compared to GCC. For
traditional macros, GCC will expand parameter identifiers *inside*
string bodies. This allows you to imitate these operators. So this
#define foo(a) test(#a)
would become the following under -traditional:
#define foo(a) test("a")
and 'a' would be expanded to '123' inside the string. This would even
occur in a case like:
#define foo(a) test("this is a test")
under -traditional mode.
This patch does not attempt to implement this behavior; we don't need
it in GHC, and Clang's -traditional is already a subset of what GCC
supports anyway, and as a result it's pretty simple. So I don't think
this is a huge deal. There are also some testsuite additions too for
Preprocessor's -traditional-cpp test. Feedback would be appreciated if
I missed something.
 From http://gcc.gnu.org/onlinedocs/cpp/Traditional-macros.html#Traditional-macros:
"The ISO stringification operator ‘#’ and token paste operator ‘##’
have no special meaning. As explained later, an effect similar to
these operators can be obtained in a different way..."
Austin - PGP: 4096R/0x91384671
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 1938 bytes
Desc: not available
More information about the cfe-commits