From a8766179a75fd18a1636b80425f81c0cd54d6151 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 11 Jan 2019 09:02:43 +0000 Subject: [PATCH] decl.c (start_decl): Improve error location. /cp 2019-01-11 Paolo Carlini * decl.c (start_decl): Improve error location. (grokdeclarator): Likewise, improve two locations. /testsuite 2019-01-11 Paolo Carlini * g++.dg/diagnostic/extern-initialized.C: New. * g++.dg/ext/dllimport-initialized.C: Likewise. From-SVN: r267830 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl.c | 9 ++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/diagnostic/extern-initialized.C | 6 ++++++ gcc/testsuite/g++.dg/ext/dllimport-initialized.C | 3 +++ 5 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/extern-initialized.C create mode 100644 gcc/testsuite/g++.dg/ext/dllimport-initialized.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b3ee2a5db2f..4b9fa821d74 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-01-11 Paolo Carlini + + * decl.c (start_decl): Improve error location. + (grokdeclarator): Likewise, improve two locations. + 2019-01-09 Sandra Loosemore PR other/16615 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 267303e0b70..fe5403d5ab5 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5096,7 +5096,8 @@ start_decl (const cp_declarator *declarator, a definition. */ if (initialized && DECL_DLLIMPORT_P (decl)) { - error ("definition of %q#D is marked %", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "definition of %q#D is marked %", decl); DECL_DLLIMPORT_P (decl) = 0; } @@ -12791,11 +12792,13 @@ grokdeclarator (const cp_declarator *declarator, /* It's common practice (and completely valid) to have a const be initialized and declared extern. */ if (!(type_quals & TYPE_QUAL_CONST)) - warning (0, "%qs initialized and declared %", name); + warning_at (DECL_SOURCE_LOCATION (decl), 0, + "%qs initialized and declared %", name); } else { - error ("%qs has both % and initializer", name); + error_at (DECL_SOURCE_LOCATION (decl), + "%qs has both % and initializer", name); return error_mark_node; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 80e0b1ab742..11eddf7409c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-01-11 Paolo Carlini + + * g++.dg/diagnostic/extern-initialized.C: New. + * g++.dg/ext/dllimport-initialized.C: Likewise. + 2019-01-11 Thomas Koenig PR fortran/59345 diff --git a/gcc/testsuite/g++.dg/diagnostic/extern-initialized.C b/gcc/testsuite/g++.dg/diagnostic/extern-initialized.C new file mode 100644 index 00000000000..4138a377296 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/extern-initialized.C @@ -0,0 +1,6 @@ +extern int i __attribute__((unused)) = 0; // { dg-warning "12:.i. initialized and declared .extern." } + +void foo() +{ + extern int i __attribute__((unused)) = 0; // { dg-error "14:.i. has both .extern. and initializer" } +} diff --git a/gcc/testsuite/g++.dg/ext/dllimport-initialized.C b/gcc/testsuite/g++.dg/ext/dllimport-initialized.C new file mode 100644 index 00000000000..adc7e82dc1a --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/dllimport-initialized.C @@ -0,0 +1,3 @@ +// { dg-do compile { target i?86-*-cygwin* i?86-*-mingw* x86_64-*-mingw* } } + +__attribute__((dllimport)) int i __attribute__((unused)) = 0; // { dg-error "32:definition of .int i. is marked .dllimport." } -- 2.30.2