diff mbox series

[C++] Fix locations of two "typedef is initialized" errors

Message ID 6e6ead42-9946-a758-c24e-3cb1f83bb688@oracle.com
State New
Headers show
Series [C++] Fix locations of two "typedef is initialized" errors | expand

Commit Message

Paolo Carlini Jan. 13, 2019, 11:33 p.m. UTC
Hi,

I think we need this patch too in order to have consistent locations for 
the set of error messages about invalid initializers - most of which I 
changed in patch 23 of this series - and also in order to have 
consistent locations for the two cases - in class, out of class - of 
ill-formed initialized typedefs. Note that when we'll consistently have 
precise locations stored in the initializers we'll have to revisit the 
already mentioned check in check_methods and the one changed here, in 
start_decl, which currently both don't have readily available the 
initializer itself. Also note that this patch relies on the patch I sent 
earlier today, that is relies on a more accurate location stored in the 
TYPE_DECL.

Tested x86_64-linux.

Thanks, Paolo.

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

	* decl.c (start_decl): Improve error location.
	* decl2.c (grokfield): Likewise.

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

	* g++.dg/diagnostic/typedef-initialized.C: New.

Comments

Jason Merrill Jan. 14, 2019, 8:08 p.m. UTC | #1
On 1/13/19 6:33 PM, Paolo Carlini wrote:
> Hi,
> 
> I think we need this patch too in order to have consistent locations for 
> the set of error messages about invalid initializers - most of which I 
> changed in patch 23 of this series - and also in order to have 
> consistent locations for the two cases - in class, out of class - of 
> ill-formed initialized typedefs. Note that when we'll consistently have 
> precise locations stored in the initializers we'll have to revisit the 
> already mentioned check in check_methods and the one changed here, in 
> start_decl, which currently both don't have readily available the 
> initializer itself. Also note that this patch relies on the patch I sent 
> earlier today, that is relies on a more accurate location stored in the 
> TYPE_DECL.

OK.

Jason
diff mbox series

Patch

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 267887)
+++ cp/decl.c	(working copy)
@@ -5059,7 +5059,8 @@  start_decl (const cp_declarator *declarator,
   if (initialized
       && TREE_CODE (decl) == TYPE_DECL)
     {
-      error ("typedef %qD is initialized (use decltype instead)", decl);
+      error_at (DECL_SOURCE_LOCATION (decl),
+		"typedef %qD is initialized (use decltype instead)", decl);
       return error_mark_node;
     }
 
Index: cp/decl2.c
===================================================================
--- cp/decl2.c	(revision 267887)
+++ cp/decl2.c	(working copy)
@@ -820,7 +820,8 @@  grokfield (const cp_declarator *declarator,
 
   if (TREE_CODE (value) == TYPE_DECL && init)
     {
-      error ("typedef %qD is initialized (use decltype instead)", value);
+      error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (value)),
+		"typedef %qD is initialized (use decltype instead)", value);
       init = NULL_TREE;
     }
 
Index: testsuite/g++.dg/diagnostic/typedef-initialized.C
===================================================================
--- testsuite/g++.dg/diagnostic/typedef-initialized.C	(nonexistent)
+++ testsuite/g++.dg/diagnostic/typedef-initialized.C	(working copy)
@@ -0,0 +1,6 @@ 
+struct S
+{
+  typedef int i __attribute__((unused)) = 1;  // { dg-error "15:typedef .i. is initialized" }
+};
+
+typedef int i __attribute__((unused)) = 1;  // { dg-error "13:typedef .i. is initialized" }