decl.c (start_decl): Improve error location.

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

	* decl.c (start_decl): Improve error location.
	(grokdeclarator): Likewise, improve two locations.

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

	* g++.dg/diagnostic/extern-initialized.C: New.
	* g++.dg/ext/dllimport-initialized.C: Likewise.

From-SVN: r267830
This commit is contained in:
Paolo Carlini 2019-01-11 09:02:43 +00:00 committed by Paolo Carlini
parent 7dc3df082b
commit a8766179a7
5 changed files with 25 additions and 3 deletions

View File

@ -1,3 +1,8 @@
2019-01-11 Paolo Carlini <paolo.carlini@oracle.com>
* decl.c (start_decl): Improve error location.
(grokdeclarator): Likewise, improve two locations.
2019-01-09 Sandra Loosemore <sandra@codesourcery.com>
PR other/16615

View File

@ -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 %<dllimport%>", decl);
error_at (DECL_SOURCE_LOCATION (decl),
"definition of %q#D is marked %<dllimport%>", 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 %<extern%>", name);
warning_at (DECL_SOURCE_LOCATION (decl), 0,
"%qs initialized and declared %<extern%>", name);
}
else
{
error ("%qs has both %<extern%> and initializer", name);
error_at (DECL_SOURCE_LOCATION (decl),
"%qs has both %<extern%> and initializer", name);
return error_mark_node;
}
}

View File

@ -1,3 +1,8 @@
2019-01-11 Paolo Carlini <paolo.carlini@oracle.com>
* g++.dg/diagnostic/extern-initialized.C: New.
* g++.dg/ext/dllimport-initialized.C: Likewise.
2019-01-11 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/59345

View File

@ -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" }
}

View File

@ -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." }