simonmar/alex — pull request #33 by coreyoconnor (2013-10-31 06:38:20+00:00)
Title: macros expanding into preprocessor directives violates C standard?

The macros ALEX_IF.., ALEX_ENDIF, ALEX_ELIF etc cause failures using alex using GCC 4.2. I'm not sure if this is an actual issue with alex, or an issue using gcc 4.2.

This patch removes the macros that expand to preprocessor directives.

I suspect this is an issue with alex because of 1973 in 6.10.3.4 of the C0x spec. The same section has a similar restriction for C99.

"The resulting completely macro-replaced preprocessing token sequence is not processed as a preprocessing directive even if it resembles one[...]"

EG: The "resulting" sequence this is referring to is, AFAIK, would be the "#if __GLASGOW_HASKELL__ > 500" for the ALEX_IF_GHC_GT_500 macro.

http://c0x.coding-guidelines.com/6.10.3.4.html

An example failure when building yi:

{{{
Preprocessing library yi-0.7.0...

src/library/Yi/Core.hs:2:14: Warning:
-XDoRec is deprecated: use -XRecursiveDo or pragma {-# LANGUAGE RecursiveDo #-} instead
line-map.c: file "templates/GenericTemplate.hs" left but not entered

dist/build/Yi/Lexer/Abella.hs:130:0: error: #else without #if

dist/build/Yi/Lexer/Abella.hs:131:0: warning: "GTE" redefined

dist/build/Yi/Lexer/Abella.hs:128:0:
warning: this is the location of the previous definition

dist/build/Yi/Lexer/Abella.hs:132:0: warning: "EQ" redefined

dist/build/Yi/Lexer/Abella.hs:129:0:
warning: this is the location of the previous definition

dist/build/Yi/Lexer/Abella.hs:133:0: error: #endif without #if

dist/build/Yi/Lexer/Abella.hs:184:0: error: #else without #if

dist/build/Yi/Lexer/Abella.hs:187:0: error: #endif without #if
}}}