diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2019-01-15 09:36:43 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2019-01-15 09:36:43 +0000 |
commit | 079a66801bfae16d282c9814266325569f91180d (patch) | |
tree | 3d7f4fc60e9207c6e391af734f1b77b06e0eafee | |
parent | 93aa3c4aca3647645cd5bce724f9d2126de4b5ea (diff) | |
download | gcc-079a66801bfae16d282c9814266325569f91180d.zip gcc-079a66801bfae16d282c9814266325569f91180d.tar.gz gcc-079a66801bfae16d282c9814266325569f91180d.tar.bz2 |
decl.c (start_decl): Improve error location.
/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
-rw-r--r-- | gcc/cp/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/cp/decl.c | 10 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/diagnostic/bitfld3.C | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/diagnostic/typedef-initialized.C | 6 |
6 files changed, 42 insertions, 6 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a99ddb5..35eec34 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 41972aa..8e1d12d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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) { diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 0869fd3..5da5beb 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 810c457..999810a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..516e776 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/bitfld3.C @@ -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 index 0000000..143134be --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/typedef-initialized.C @@ -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" } |