@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see
#include "stor-layout.h"
#include "varasm.h"
#include "intl.h"
+#include "gcc-rich-location.h"
static tree
process_init_constructor (tree type, tree init, int nested,
@@ -507,9 +508,16 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
if (DECL_FUNCTION_MEMBER_P (member)
&& ! flag_ms_extensions)
- emit_diagnostic (diag_kind, loc, 0,
- "invalid use of member function %qD "
- "(did you forget the %<()%> ?)", member);
+ {
+ gcc_rich_location richloc (loc);
+ /* If "member" has no arguments (other than "this"), then
+ add a fix-it hint. */
+ if (type_num_arguments (TREE_TYPE (member)) == 1)
+ richloc.add_fixit_insert_after ("()");
+ emit_diagnostic (diag_kind, &richloc, 0,
+ "invalid use of member function %qD "
+ "(did you forget the %<()%> ?)", member);
+ }
else
emit_diagnostic (diag_kind, loc, 0,
"invalid use of member %qD "
@@ -105,6 +105,8 @@ extern void inform_n (location_t, unsigned HOST_WIDE_INT, const char *,
extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern bool emit_diagnostic (diagnostic_t, location_t, int,
const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
+extern bool emit_diagnostic (diagnostic_t, rich_location *, int,
+ const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
extern bool emit_diagnostic_valist (diagnostic_t, location_t, int, const char *,
va_list *) ATTRIBUTE_GCC_DIAG (4,0);
extern bool seen_error (void);
@@ -1168,6 +1168,20 @@ emit_diagnostic (diagnostic_t kind, location_t location, int opt,
return ret;
}
+/* As above, but for rich_location *. */
+
+bool
+emit_diagnostic (diagnostic_t kind, rich_location *richloc, int opt,
+ const char *gmsgid, ...)
+{
+ auto_diagnostic_group d;
+ va_list ap;
+ va_start (ap, gmsgid);
+ bool ret = diagnostic_impl (richloc, opt, gmsgid, &ap, kind);
+ va_end (ap);
+ return ret;
+}
+
/* Wrapper around diagnostic_impl taking a va_list parameter. */
bool
new file mode 100644
@@ -0,0 +1,32 @@
+// { dg-options "-fdiagnostics-show-caret" }
+
+class t1
+{
+public:
+ double length () const { return m_length; }
+ double area (double width) const { return m_length * width; }
+
+private:
+ double m_length;
+};
+
+bool test_1 (const t1 &inst)
+{
+ return inst.length > 0.0; // { dg-error "did you forget the '\\(\\)'" }
+ /* We expect a fix-it hint. */
+ /* { dg-begin-multiline-output "" }
+ return inst.length > 0.0;
+ ~~~~~^~~~~~
+ ()
+ { dg-end-multiline-output "" } */
+}
+
+bool test_2 (const t1 &inst)
+{
+ return inst.area > 0.0; // { dg-error "did you forget the '\\(\\)'" }
+ /* "t1::area" has additional params, so we don't expect a fix-it hint. */
+ /* { dg-begin-multiline-output "" }
+ return inst.area > 0.0;
+ ~~~~~^~~~
+ { dg-end-multiline-output "" } */
+}