C++: fix-it hint for missing parentheses
commit6639e73519514a80a7fb37de774ac3692c6a467d
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 30 Nov 2018 22:51:18 +0000 (30 22:51 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 30 Nov 2018 22:51:18 +0000 (30 22:51 +0000)
treead4f9748a8f41861298cd65458deb892776a9643
parent22ec1044c196b8bfb47a990c2470b3c8517187d9
C++: fix-it hint for missing parentheses

Consider:

  class t1
  {
  public:
    double length () const { return m_length; }
  private:
    double m_length;
  };

missing-parens-fixit.C: In function 'bool test_1(const t1&)':
missing-parens-fixit.C:14:15: error: invalid use of member function
  'double t1::length() const' (did you forget the '()' ?)
   14 |   return inst.length > 0.0;
      |          ~~~~~^~~~~~

This patch adds a fix-it hint for the case where the member function
takes no parameters, suggesting the addition of the parentheses:

   14 |   return inst.length > 0.0;
      |          ~~~~~^~~~~~
      |                     ()

so that an IDE can potentially apply the fix.

gcc/cp/ChangeLog:
* typeck2.c: Include "gcc-rich-location.h".
(cxx_incomplete_type_diagnostic): When complaining about possibly
missing parens, add a fix-it hint if the member function takes no
additional params.

gcc/ChangeLog:
* diagnostic-core.h (emit_diagnostic): New decl.
* diagnostic.c (emit_diagnostic): New overload, taking a
rich_location *.

gcc/testsuite/ChangeLog:
* g++.dg/parse/missing-parens-fixit.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@266696 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/diagnostic-core.h
gcc/diagnostic.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/missing-parens-fixit.C [new file with mode: 0644]