bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.46k stars 581 forks source link

Fix parsing of friend simple-type-specifier #681

Closed HGuillemet closed 1 year ago

HGuillemet commented 1 year ago
class B {
  friend bool operator<( B x, B y) { return true; }
}

Fails to parse with an Unexpected token 'EOF'.

In group, friend, not followed by class/struct/union, is assumed to be a C++11 friendship declaration with a simple-type-specifier. bool is skipped, probably taken for some attributes, and a call to type on operator < throws the exception because it looks for template arguments until end of file. This PR proposes a fix by never skipping the token after friend, so type will parse what is expected to be a type (bool in this case, instead of operator). I think that what needs to be skipped (attributes ?) only concerns non-friend declaration.

No changes in parsing for existing presets, but in Pytorch, where an addition declaration (ptr_to_first_element) is added in global.java. Without the PR, parsing of List.h ends prematurely because of a friend bool operator<.

Allows to parse intrusive_ptr.h in Pytorch.