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.carl...@oracle.com>
* decl.c (start_decl): Improve error location.
* decl2.c (grokfield): Likewise.
/testsuite
2019-01-13 Paolo Carlini <paolo.carl...@oracle.com>
* g++.dg/diagnostic/typedef-initialized.C: New.
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" }