decl.c (grokvardecl): Use an accurate location in error message about main as a globa...
authorPaolo Carlini <paolo.carlini@oracle.com>
Fri, 10 May 2019 18:00:52 +0000 (18:00 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 10 May 2019 18:00:52 +0000 (18:00 +0000)
/cp
2019-05-10  Paolo Carlini  <paolo.carlini@oracle.com>

* decl.c (grokvardecl): Use an accurate location in error message
about main as a global variable.

/testsuite
2019-05-10  Paolo Carlini  <paolo.carlini@oracle.com>

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

From-SVN: r271070

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/main1.C [new file with mode: 0644]

index 4b245a2f6044b1be68dfa9fb8f9179634125b845..33614ef49ecf88542ae6968a753d80951ff38a7f 100644 (file)
@@ -1,3 +1,8 @@
+2019-05-10  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * decl.c (grokvardecl): Use an accurate location in error message
+       about main as a global variable.
+
 2019-05-10  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * call.c (build_call_a): Use FUNC_OR_METHOD_TYPE_P.
index 300c2dbbbb1610266e76f38b171a50743922fb34..a776f8fcd98e34ac711a8a61df5025e83e0ec1e0 100644 (file)
@@ -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.  */
index ac85d094f428e93030a3605699c045c735d1be61..165df1311adac544ba8e6688caaed4ee42a0aa7e 100644 (file)
@@ -1,3 +1,7 @@
+2019-05-10  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * g++.dg/diagnostic/main1.C: New.
+
 2019-05-10  Marek Polacek  <polacek@redhat.com>
 
        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 (file)
index 0000000..6bb0d78
--- /dev/null
@@ -0,0 +1 @@
+int main __attribute__((unused));  // { dg-error "5:cannot declare" }