Re: Why this results in Error: Syntax error in input(3).

William S Fulton <[email protected]> Fri, 31 Dec 2021 15:47:02 +0000
Newsgroups gmane.comp.programming.swig
Message-ID <CANGqftDuw1LyrvGyZaCSsx80-gLxNpAuawVuE=Fvc=pPoPD4hA@mail.gmail.com>
SWIG can parse the conversion operator to bool:
    explicit operator bool () const
but not the fallback conversion operator to a member function returning
Standard_Transient* (I think that is what it is!!):
    operator Standard_Transient* handle::* () const

I've never seen the latter which looks horrendous to parse and I can't see
it making much sense returning this for a language wrapper, so don't hold
your breath for it to be supported anytime soon in SWIG.  I suggest adding
SWIG to list of compilers that supports the bool conversion operator.

When you instantiate this class with %template, you'll get a warning:
  Warning 503: Can't wrap 'operator bool' unless renamed to a valid
identifier.

So add in something like the following if you want to wrap this conversion
operator:
  %rename(tobool) operator bool;

There is more info on conversion operator work we're looking at in
https://github.com/swig/swig/issues/2098.

William

On Fri, 31 Dec 2021 at 08:41, [email protected] <
[email protected]> wrote:

>
> Hi,
>
> in this file:
>
>
> https://github.com/nyholku/swig-experiments/blob/master/Patched_Standard_Handle.hxx
>
> if I uncomment lines 216-218 and delete line 219, ie if I change:
>
> #if 1
>
> to (as it was in the original un patched file):
>
> #if (defined(__clang__)) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER
> >= 1300) || \
>     (defined(_MSC_VER) && _MSC_VER >= 1800) || \
>     (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 &&
> __GNUC_MINOR__ >= 6)))
>
>
> I get
>
> ../Patched_Standard_Handle.hxx:229: Error: Syntax error in input(3).
>
> why SWIG chokes on that?
>
> This is even more weird to me because in lines 240-242 exactly same #if
> works (AFAIU).
>
> The whole problematic #if/#else#endif section from lines 216 to 235 is
> here for reference:
>
> //#if (defined(__clang__)) || (defined(__INTEL_COMPILER) &&
> __INTEL_COMPILER >= 1300) || \
> //    (defined(_MSC_VER) && _MSC_VER >= 1800) || \
> //    (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 &&
> __GNUC_MINOR__ >= 6)))
> #if 1
>
>     //! Conversion to bool for use in conditional expressions
>     explicit operator bool () const
>     {
>       return entity != nullptr;
>     }
>
> #else /* fallback version for compilers not supporting explicit conversion
> operators (VC10, VC11, GCC below 4.5) */
>
>     //! Conversion to bool-compatible type for use in conditional
> expressions
>     operator Standard_Transient* handle::* () const
>     {
>       return entity ? &handle::entity : 0;
>     }
>
> #endif
>
> wbr Kusti
>
>
>
> _______________________________________________
> Swig-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/swig-user
>

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user