From 73075e06b7591dacd413e2e9a944d9fe6722dde9 Mon Sep 17 00:00:00 2001
From: Paolo Carlini <paolo.carlini@oracle.com>
Date: Wed, 9 Jan 2019 08:52:38 +0000
Subject: [PATCH] decl.c (grok_reference_init): Improve error location.

/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.

From-SVN: r267756
---
 gcc/cp/ChangeLog                             |  5 +++++
 gcc/cp/decl.c                                | 13 ++++++++-----
 gcc/testsuite/ChangeLog                      |  5 +++++
 gcc/testsuite/g++.dg/diagnostic/constexpr2.C |  8 ++++++++
 gcc/testsuite/g++.dg/diagnostic/ref3.C       |  1 +
 5 files changed, 27 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/constexpr2.C
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/ref3.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 91465daea613..3167b49b6e02 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2019-01-08  Paolo Carlini  <paolo.carlini@oracle.com>
+
+	* decl.c (grok_reference_init): Improve error location.
+	(grokdeclarator): Likewise, improve two locations.
+
 2019-01-08  Marek Polacek  <polacek@redhat.com>
 
 	PR c++/88538 - braced-init-list in template-argument-list.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7e4e93c42013..267303e0b706 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5357,7 +5357,8 @@ grok_reference_init (tree decl, tree type, tree init, int flags)
       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;
 	  }
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3d7023f18c05..47b6116845ff 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-01-08  Paolo Carlini  <paolo.carlini@oracle.com>
+
+	* g++.dg/diagnostic/constexpr2.C: New.
+	* g++.dg/diagnostic/ref3.C: Likewise.
+
 2019-01-08  Marek Polacek  <polacek@redhat.com>
 
 	PR c++/88538 - braced-init-list in template-argument-list.
diff --git a/gcc/testsuite/g++.dg/diagnostic/constexpr2.C b/gcc/testsuite/g++.dg/diagnostic/constexpr2.C
new file mode 100644
index 000000000000..7afb5a23bdff
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/constexpr2.C
@@ -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." }
+};
diff --git a/gcc/testsuite/g++.dg/diagnostic/ref3.C b/gcc/testsuite/g++.dg/diagnostic/ref3.C
new file mode 100644
index 000000000000..f43f5a3f6d53
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/ref3.C
@@ -0,0 +1 @@
+int& i __attribute__((unused));  // { dg-error "6:.i. declared as reference" }
-- 
GitLab