antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

C++ warning + fix

Open JoD opened this issue 1 year ago • 3 comments

Using g++ (Ubuntu 13.2.0-23ubuntu4) 13.2.0 gives

antlr4/tree/ParseTree.h:50:18: warning: ‘virtual bool antlr4::tree::ParseTree::operator==(const antlr4::tree::ParseTree&) const’ was hidden [-Woverloaded-virtual=]
   50 |     virtual bool operator == (const ParseTree &other) const;
      |                  ^~~~~~~~
antlr4/RuleContext.h:135:10: note:   by ‘bool antlr4::RuleContext::operator==(const antlr4::RuleContext&)’
  135 |     bool operator == (const RuleContext &other) { return this == &other; } // Simple address comparison.

The operator== in RuleContext seems redundant, as the virtual one in ParseTree performs the same check?

Proposed fix: remove this line: https://github.com/antlr/antlr4/blob/1855d9aa4c5ebb15284b95a07048b6260304629c/runtime/Cpp/runtime/src/RuleContext.h#L135

JoD avatar May 01 '24 22:05 JoD

Have you solved that? I face the same problem.

xu20160924 avatar May 11 '24 12:05 xu20160924

Yes, just remove the line above (135 in Rulecontext.h) as it does nothing different from the virtual method it reimplements.

JoD avatar May 12 '24 07:05 JoD