#887 Parse error on complex method definition

parsing (147)

SWIG 1.3.33 reports a parse error for the method in this example class (although the bug was encountered in similar "real-life" code):

class C
int *(*func_pointer)();

int *(*getFunctionPointer() const)()
return func_pointer;

I had to stare at the original code some time before I figured out what it actually expressed, isn't C++ wonderful (who needs templates to write hard-to-understand code)?

(getFunctionPointer is a method that takes no arguments, doesn't alter the instance of C it's called on and returns a pointer to [a function that takes no parameters and returns a pointer to an int])

PS This code does compile and gcc-xml concurs with my interpretation of getFunctionPointer ;-)


  • William Fulton

    William Fulton - 2011-02-17

    My best attempt at fixing this was to add

    notso_direct_declarator ...

    | notso_direct_declarator LPAREN parms RPAREN CONST_QUAL {
    SwigType_add_qualifier(t, "const");

    See patch. This adds one shift/reduce, but the additional const added to the type breaks numerous other tests, so a bigger rewrite in the parser is needed than I am willing to take on. We could use the patch without the extra SwigType_add_qualifier() which will result in the function pointer being parsed, but not necessarily handled correctly. This is too much of a hack for me.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks