From 67254b50a63b1a1095762fefef801a6a53ccece5 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 10 May 2019 18:00:52 +0000 Subject: [PATCH] decl.c (grokvardecl): Use an accurate location in error message about main as a global variable. /cp 2019-05-10 Paolo Carlini * decl.c (grokvardecl): Use an accurate location in error message about main as a global variable. /testsuite 2019-05-10 Paolo Carlini * g++.dg/diagnostic/main1.C: New. From-SVN: r271070 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl.c | 3 ++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/diagnostic/main1.C | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/main1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4b245a2f604..33614ef49ec 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-05-10 Paolo Carlini + + * decl.c (grokvardecl): Use an accurate location in error message + about main as a global variable. + 2019-05-10 Paolo Carlini * call.c (build_call_a): Use FUNC_OR_METHOD_TYPE_P. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 300c2dbbbb1..a776f8fcd98 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -9477,7 +9477,8 @@ grokvardecl (tree type, if (DECL_NAME (decl) && MAIN_NAME_P (DECL_NAME (decl)) && scope == global_namespace) - error ("cannot declare %<::main%> to be a global variable"); + error_at (DECL_SOURCE_LOCATION (decl), + "cannot declare %<::main%> to be a global variable"); /* Check that the variable can be safely declared as a concept. Note that this also forbids explicit specializations. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ac85d094f42..165df1311ad 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-05-10 Paolo Carlini + + * g++.dg/diagnostic/main1.C: New. + 2019-05-10 Marek Polacek PR c++/78010 - bogus -Wsuggest-override warning on final function. diff --git a/gcc/testsuite/g++.dg/diagnostic/main1.C b/gcc/testsuite/g++.dg/diagnostic/main1.C new file mode 100644 index 00000000000..6bb0d78ff14 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/main1.C @@ -0,0 +1 @@ +int main __attribute__((unused)); // { dg-error "5:cannot declare" } -- 2.30.2