Hi,
it seems we can easily improve this location by using
DECL_SOURCE_LOCATION in the standard way. Tested x86_64-linux.
Thanks, Paolo.
//////////////////
/cp
2019-01-02 Paolo Carlini <paolo.carl...@oracle.com>
* tree.c (handle_nodiscard_attribute): Improve warning location.
/testsuite
2019-01-02 Paolo Carlini <paolo.carl...@oracle.com>
* g++.dg/cpp1z/nodiscard3.C: Test locations too.
Index: cp/tree.c
===================================================================
--- cp/tree.c (revision 267507)
+++ cp/tree.c (working copy)
@@ -4372,8 +4372,9 @@ handle_nodiscard_attribute (tree *node, tree name,
if (TREE_CODE (*node) == FUNCTION_DECL)
{
if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
- warning (OPT_Wattributes, "%qE attribute applied to %qD with void "
- "return type", name, *node);
+ warning_at (DECL_SOURCE_LOCATION (*node),
+ OPT_Wattributes, "%qE attribute applied to %qD with void "
+ "return type", name, *node);
}
else if (OVERLOAD_TYPE_P (*node))
/* OK */;
Index: testsuite/g++.dg/cpp1z/nodiscard3.C
===================================================================
--- testsuite/g++.dg/cpp1z/nodiscard3.C (revision 267507)
+++ testsuite/g++.dg/cpp1z/nodiscard3.C (working copy)
@@ -13,8 +13,8 @@ typedef struct { char big[1024]; fnt fn; } C;
struct [[nodiscard]] D { int i; D(); ~D(); };
WUR E check1 (void);
-WUR void check2 (void); /* { dg-warning "nodiscard" } */
-WUR int foo; /* { dg-warning "nodiscard" } */
+WUR void check2 (void); /* { dg-warning "10:.nodiscard." } */
+WUR int foo; /* { dg-warning "9:.nodiscard." } */
int bar (void);
WURAI E check3 (void) { return (E)bar (); }
WUR A check4 (void);