diff mbox series

[C++] Fix three additional locations

Message ID 4c8fc01d-e961-f267-339a-75d002d8116a@oracle.com
State New
Headers show
Series [C++] Fix three additional locations | expand

Commit Message

Paolo Carlini Jan. 8, 2019, 1:13 p.m. UTC
Hi,

a few additional easy to fix cases where we thought that a plain error 
was good enough. Tested x86_64-linux.

Thanks, Paolo.

////////////////////
/cp
2019-01-08  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl.c (grok_reference_init): Improve error location.
	(grokdeclarator): Likewise, improve two locations.

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

	* g++.dg/diagnostic/constexpr2.C: New.
	* g++.dg/diagnostic/ref3.C: Likewise.

Comments

Jason Merrill Jan. 8, 2019, 8:46 p.m. UTC | #1
On 1/8/19 8:13 AM, Paolo Carlini wrote:
> Hi,
> 
> a few additional easy to fix cases where we thought that a plain error 
> was good enough. Tested x86_64-linux.
> 
> Thanks, Paolo.
> 
> ////////////////////
> 
OK.
diff mbox series

Patch

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 267675)
+++ cp/decl.c	(working copy)
@@ -5357,7 +5357,8 @@  grok_reference_init (tree decl, tree type, tree in
       if ((DECL_LANG_SPECIFIC (decl) == 0
 	   || DECL_IN_AGGR_P (decl) == 0)
 	  && ! DECL_THIS_EXTERN (decl))
-	error ("%qD declared as reference but not initialized", decl);
+	error_at (DECL_SOURCE_LOCATION (decl),
+		  "%qD declared as reference but not initialized", decl);
       return NULL_TREE;
     }
 
@@ -12517,8 +12518,9 @@  grokdeclarator (const cp_declarator *declarator,
 			    unqualified_id);
 		else if (constexpr_p && !initialized)
 		  {
-		    error ("%<constexpr%> static data member %qD must have an "
-			   "initializer", decl);
+		    error_at (DECL_SOURCE_LOCATION (decl),
+			      "%<constexpr%> static data member %qD must "
+			      "have an initializer", decl);
 		    constexpr_p = false;
 		  }
 
@@ -12756,8 +12758,9 @@  grokdeclarator (const cp_declarator *declarator,
 	  }
 	else if (constexpr_p && DECL_EXTERNAL (decl))
 	  {
-	    error ("declaration of %<constexpr%> variable %qD "
-		   "is not a definition", decl);
+	    error_at (DECL_SOURCE_LOCATION (decl),
+		      "declaration of %<constexpr%> variable %qD "
+		      "is not a definition", decl);
 	    constexpr_p = false;
 	  }
 
Index: testsuite/g++.dg/diagnostic/constexpr2.C
===================================================================
--- testsuite/g++.dg/diagnostic/constexpr2.C	(nonexistent)
+++ testsuite/g++.dg/diagnostic/constexpr2.C	(working copy)
@@ -0,0 +1,8 @@ 
+// { dg-do compile { target c++11 } }
+
+extern constexpr int i __attribute__((unused));  // { dg-error "22:declaration of .constexpr. variable .i." }
+
+struct S
+{
+  constexpr static int i __attribute__((unused));  // { dg-error "24:.constexpr. static data member .i." }
+};
Index: testsuite/g++.dg/diagnostic/ref3.C
===================================================================
--- testsuite/g++.dg/diagnostic/ref3.C	(nonexistent)
+++ testsuite/g++.dg/diagnostic/ref3.C	(working copy)
@@ -0,0 +1 @@ 
+int& i __attribute__((unused));  // { dg-error "6:.i. declared as reference" }