decl.c (start_decl): Improve error location.
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 15 Jan 2019 09:36:43 +0000 (09:36 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 15 Jan 2019 09:36:43 +0000 (09:36 +0000)
/cp
2019-01-15  Paolo Carlini  <paolo.carlini@oracle.com>

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

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

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

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

* decl.c (grokdeclarator): Move further up the location_t loc
declaration and use the location when building a TYPE_DECL for
a typedef name.
* decl2.c (grokbitfield): Use DECL_SOURCE_LOCATION in the error
about an ill-formed bit-field as typedef.

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

* g++.dg/diagnostic/bitfld3.C: New.

From-SVN: r267932

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/bitfld3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/typedef-initialized.C [new file with mode: 0644]

index a99ddb5313dca1a0a6439e7a4f506fe382dbdf6b..35eec34fca5c32294a9b33bf5ae90a9bbc6c0410 100644 (file)
@@ -1,3 +1,16 @@
+2019-01-15  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * decl.c (start_decl): Improve error location.
+       * decl2.c (grokfield): Likewise.
+
+2019-01-15  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * decl.c (grokdeclarator): Move further up the location_t loc
+       declaration and use the location when building a TYPE_DECL for
+       a typedef name.
+       * decl2.c (grokbitfield): Use DECL_SOURCE_LOCATION in the error
+       about an ill-formed bit-field as typedef.
+
 2019-01-14  Marek Polacek  <polacek@redhat.com>
 
        PR c++/88830 - ICE with abstract class.
index 41972aa09553ae2846dfc78f8eeb8f7db363ec29..8e1d12d8feb3f28fbaadc7f08858128cc615286b 100644 (file)
@@ -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;
     }
 
@@ -11935,6 +11936,8 @@ grokdeclarator (const cp_declarator *declarator,
        }
     }
 
+  location_t loc = declarator ? declarator->id_loc : input_location;
+
   /* If this is declaring a typedef name, return a TYPE_DECL.  */
   if (typedef_p && decl_context != TYPENAME)
     {
@@ -11980,9 +11983,9 @@ grokdeclarator (const cp_declarator *declarator,
        }
 
       if (decl_context == FIELD)
-       decl = build_lang_decl (TYPE_DECL, unqualified_id, type);
+       decl = build_lang_decl_loc (loc, TYPE_DECL, unqualified_id, type);
       else
-       decl = build_decl (input_location, TYPE_DECL, unqualified_id, type);
+       decl = build_decl (loc, TYPE_DECL, unqualified_id, type);
 
       if (decl_context != FIELD)
        {
@@ -12223,7 +12226,6 @@ grokdeclarator (const cp_declarator *declarator,
 
   {
     tree decl = NULL_TREE;
-    location_t loc = declarator ? declarator->id_loc : input_location;
 
     if (decl_context == PARM)
       {
index 0869fd3082472c64205545cbf9fb76a9f5e8eaf6..5da5beb778424729dd9960116b853d89966dd1fc 100644 (file)
@@ -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;
     }
 
@@ -1038,7 +1039,8 @@ grokbitfield (const cp_declarator *declarator,
 
   if (TREE_CODE (value) == TYPE_DECL)
     {
-      error ("cannot declare %qD to be a bit-field type", value);
+      error_at (DECL_SOURCE_LOCATION (value),
+               "cannot declare %qD to be a bit-field type", value);
       return NULL_TREE;
     }
 
index 810c45780a78d3713aae0a2e996499fa531026fd..999810a1c897ca31c6093d78fada0e3a2c81aa62 100644 (file)
@@ -1,3 +1,11 @@
+2019-01-15  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * g++.dg/diagnostic/typedef-initialized.C: New.
+
+2019-01-15  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * g++.dg/diagnostic/bitfld3.C: New.
+
 2019-01-15  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/88775
diff --git a/gcc/testsuite/g++.dg/diagnostic/bitfld3.C b/gcc/testsuite/g++.dg/diagnostic/bitfld3.C
new file mode 100644 (file)
index 0000000..516e776
--- /dev/null
@@ -0,0 +1,5 @@
+struct S
+{
+  typedef int i : 3;  // { dg-error "15:cannot declare .i." }
+  typedef int : 3;  // { dg-error "cannot declare" }
+};
diff --git a/gcc/testsuite/g++.dg/diagnostic/typedef-initialized.C b/gcc/testsuite/g++.dg/diagnostic/typedef-initialized.C
new file mode 100644 (file)
index 0000000..143134b
--- /dev/null
@@ -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" }