[C++] Improve handle_nodiscard_attribute location

Message ID 7186eef2-74f6-c687-6328-e660a43660a7@oracle.com
State New
Headers show
Series
  • [C++] Improve handle_nodiscard_attribute location
Related show

Commit Message

Paolo Carlini Jan. 2, 2019, 9:26 p.m.
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.carlini@oracle.com>

	* tree.c (handle_nodiscard_attribute): Improve warning location.

/testsuite
2019-01-02  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/cpp1z/nodiscard3.C: Test locations too.

Comments

Jason Merrill Jan. 2, 2019, 9:44 p.m. | #1
On 1/2/19 4:26 PM, Paolo Carlini wrote:
> it seems we can easily improve this location by using 

> DECL_SOURCE_LOCATION in the standard way. Tested x86_64-linux.


OK.

Jason

Patch

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);