Menu

#1139 Syntax error in input(3); when using '<' or '>' in enum

None
closed
nobody
parsing (146)
5
2021-09-30
2011-03-06
No

Using SWIG 2.0.2
When using the result of a comparison to define an enum value, in this case in a C++ template class, I get the following error "Error: Syntax error in input(3)."
I can work around it by copying the header and just leaving the enum values out, but SWIG should work with this. For reference, using '==', '!=", '>=', or '<=' all work, it's just '<' and '>' that produce the error.

This is a simple example that produces the error:
template<typename Tp>
struct SizeInfo {
enum {
isLarge = (sizeof(Tp)>sizeof(void*)),
isPointer = false
};
};

SWIG erros on the line "isLarge = (sizeof(Tp)>sizeof(void*)),", hover changing the line to "isLarge = (sizeof(Tp)>=sizeof(void*)+1)", or any operator other than '<' or '>' parses fine.

Discussion

  • Olly Betts

    Olly Betts - 2013-01-08

    This is a current limitation in the parser. There's a comment about it in Source/CParse/parser.y:

    /* Sadly this causes 2 reduce-reduce conflicts with templates.  FIXME resolve these.
               | expr GREATERTHAN expr {
                 $$.val = NewStringf("%s < %s", $1.val, $3.val);
                 $$.type = cparse_cplusplus ? T_BOOL : T_INT;
               }
               | expr LESSTHAN expr {
                 $$.val = NewStringf("%s > %s", $1.val, $3.val);
                 $$.type = cparse_cplusplus ? T_BOOL : T_INT;
               }
    */
    
     

    Last edit: Olly Betts 2013-01-08
  • Olly Betts

    Olly Betts - 2013-05-07
    • labels: code generation (general) --> parsing
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2021-09-29

    This is also in the github tracker:
    https://github.com/swig/swig/issues/80
    Closing this one as a duplicate.

     
  • Olly Betts

    Olly Betts - 2021-09-30
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB