No worries.  Thank you Malcolm.  If there's anything else I can gather to facilitate the fix let me know.<br><div class="gmail_quote"><div dir="ltr">On Sun, Jan 10, 2016 at 5:40 PM Malcolm Wallace <<a href="mailto:malcolm.wallace@me.com">malcolm.wallace@me.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks for the bug report, and for the detailed analysis.  I will try to look at and fix this soon.<br>
<br>
Regards,<br>
    Malcolm<br>
<br>
On 10 Jan 2016, at 20:09, Alain O'Dea wrote:<br>
<br>
> Got a clear answer about the handling of if defined.<br>
><br>
> Expanding macros within if defined is non-compliant if cpphs is trying to be a C99 preprocessor:<br>
> <a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf" rel="noreferrer" target="_blank">http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf</a><br>
> 6.10.1/1 Conditional Inclusion pg 148 indicates that the token after defined or within defined ( ) is an identifier, not a macro to be expanded.<br>
><br>
> I'm not sure what's involved in fixing this behavior in cpphs, but I'm happy to test fixes.<br>
><br>
> On Sun, Jan 10, 2016 at 3:53 PM Alain O'Dea <<a href="mailto:alain.odea@gmail.com" target="_blank">alain.odea@gmail.com</a>> wrote:<br>
> I've isolated the issue to the handling of if defined on multi-argument macros.<br>
><br>
> I took a crack at interpreting the cpphs source for this and I think it may be a bug in the conversion of defined expressions here in Language.Preprocessor.CppIfdef here:<br>
><br>
>     convert "defined" [arg] =<br>
>       case lookupST arg st of<br>
>         Nothing | all isDigit arg    -> return arg<br>
>         Nothing                      -> return "0"<br>
>         Just (a@AntiDefined{})       -> return "0"<br>
>         Just (a@SymbolReplacement{}) -> return "1"<br>
>         Just (a@MacroExpansion{})    -> return "1"<br>
><br>
> It looks like it will macro expand the contents of a defined expression which isn't what GCC does.  I don't know if GCC is wrong or if using parameterized macros within<br>
><br>
> if defined works on single-argument macros.<br>
><br>
> working1.hs:<br>
><br>
>     {-# LANGUAGE CPP #-}<br>
><br>
>     #define EXAMPLE_MACRO(arg) (\<br>
>                                    arg)<br>
><br>
>     #if defined(EXAMPLE_MACRO)<br>
>     #endif<br>
><br>
> preprocess it (it works!):<br>
><br>
>     $ cpphs --cpp working1.hs -o $tempfile<br>
>     $<br>
><br>
> ifdef works on multiple-argument macros.<br>
><br>
> working2.hs:<br>
><br>
>     {-# LANGUAGE CPP #-}<br>
><br>
>     #define EXAMPLE_MACRO(arg1,arg2) (\<br>
>                                    arg1 > arg2)<br>
><br>
>     #ifdef EXAMPLE_MACRO<br>
>     #endif<br>
><br>
> preprocess it (it works!):<br>
><br>
>     $ cpphs --cpp working2.hs -o $tempfile<br>
>     $<br>
><br>
> if defined fails on multi-argument macros.<br>
><br>
> broken2.hs:<br>
><br>
>     {-# LANGUAGE CPP #-}<br>
><br>
>     #define EXAMPLE_MACRO(arg1,arg2) (\<br>
>                                    arg1 > arg2)<br>
><br>
>     #if defined(EXAMPLE_MACRO)<br>
>     #endif<br>
><br>
> preprocess it (it fails!):<br>
><br>
>     $ cpphs --cpp broken2.hs -o $tempfile<br>
>     cpphs: macro EXAMPLE_MACRO expected 2 arguments, but was given 0<br>
>     $<br>
><br>
> I've posted a StackOverflow question to see if any of them know if this is undefined behavior:<br>
> <a href="http://stackoverflow.com/questions/34709769/is-cpphs-wrong-or-is-the-behavior-of-macros-with-arguments-in-if-defined-express" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/34709769/is-cpphs-wrong-or-is-the-behavior-of-macros-with-arguments-in-if-defined-express</a><br>
><br>
> If it is undefined behavior we should stop relying on it in GHC sources.  Either way the behavior is inconsistent with GCC which complicates things.<br>
><br>
> Best,<br>
> Alain<br>
><br>
> On Sun, Jan 10, 2016 at 2:04 PM Alain O'Dea <<a href="mailto:alain.odea@gmail.com" target="_blank">alain.odea@gmail.com</a>> wrote:<br>
> Hi Malcolm:<br>
><br>
> cpphs is under consideration as a replacement for GCC's C preprocessor in the GHC toolchain:<br>
> <a href="https://ghc.haskell.org/trac/ghc/wiki/Proposal/NativeCpp" rel="noreferrer" target="_blank">https://ghc.haskell.org/trac/ghc/wiki/Proposal/NativeCpp</a><br>
><br>
> GHC 7.10.3's build fails when cpphs is used as the C preprocessor (--with-hs-cpp=cpphs --with-hs-cpp-flags="--cpp").<br>
><br>
> It runs into this error when preprocessing libraries/base/GHC/Natural.hs:<br>
><br>
> cpphs: macro MIN_VERSION_integer_gmp expected 3 arguments, but was given 0<br>
><br>
> I've reproduced this issue on Ubuntu 14.04 x86-64 and SmartOS 15.3.0 x86-64.<br>
><br>
> Interestingly the error seems to arise only when preprocessing Natural.hs while the autogenerated cabal-macros.h is present.  Removing that include from the cpphs flags leads to a clean preprocessing run.<br>
><br>
> I have more details of this investigation here:<br>
> <a href="https://gist.github.com/AlainODea/bd5b3e0e6f7c4227f009" rel="noreferrer" target="_blank">https://gist.github.com/AlainODea/bd5b3e0e6f7c4227f009</a><br>
><br>
> Is this a bug?<br>
><br>
> Best,<br>
> Alain<br>
<br>
</blockquote></div>