public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 67065 ("Missing diagnostics for ill-formed program with main variable instead of function")
@ 2015-08-19 20:27 Ville Voutilainen
  2015-08-19 20:28 ` Paolo Carlini
  0 siblings, 1 reply; 16+ messages in thread
From: Ville Voutilainen @ 2015-08-19 20:27 UTC (permalink / raw)
  To: gcc-patches, Paolo Carlini, Jason Merrill

>submitter noticed that, in violation of [basic.start.main], we don't reject
>as ill-formed the declaration of a 'main' variable in the global namespace.
>Not a big deal IMHO, but the below simple check works well for me on x86_64-linux.

Just fyi, gcc accepts

decltype(main) x;

decltype(sizeof(decltype(main)*)) x;

which are "uses" of main and also violate [basic.start.main]/3.

^ permalink raw reply	[flat|nested] 16+ messages in thread
* [C++ Patch] PR 67065 ("Missing diagnostics for ill-formed program with main variable instead of function")
@ 2015-08-19 19:52 Paolo Carlini
  2015-08-20  2:35 ` Jason Merrill
  2015-08-21  6:30 ` Markus Trippelsdorf
  0 siblings, 2 replies; 16+ messages in thread
From: Paolo Carlini @ 2015-08-19 19:52 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 291 bytes --]

Hi,

submitter noticed that, in violation of [basic.start.main], we don't 
reject as ill-formed the declaration of a 'main' variable in the global 
namespace. Not a big deal IMHO, but the below simple check works well 
for me on x86_64-linux.

Thanks,
Paolo.

//////////////////////////////

[-- Attachment #2: CL_67065 --]
[-- Type: text/plain, Size: 245 bytes --]

/cp
2015-08-19  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/67065
	* decl.c (grokvardecl): Reject 'main' as global variable.

/testsuite
2015-08-19  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/67065
	* g++.dg/other/pr67065.C: New.

[-- Attachment #3: patch_67065 --]
[-- Type: text/plain, Size: 866 bytes --]

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 227003)
+++ cp/decl.c	(working copy)
@@ -8355,6 +8355,11 @@ grokvardecl (tree type,
   else
     DECL_INTERFACE_KNOWN (decl) = 1;
 
+  if (DECL_NAME (decl)
+      && MAIN_NAME_P (DECL_NAME (decl))
+      && CP_DECL_CONTEXT (decl) == global_namespace)
+    error ("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.  */
   if (conceptp)
Index: testsuite/g++.dg/other/pr67065.C
===================================================================
--- testsuite/g++.dg/other/pr67065.C	(revision 0)
+++ testsuite/g++.dg/other/pr67065.C	(working copy)
@@ -0,0 +1,3 @@
+// PR c++/67065
+
+int main;  // { dg-error "cannot declare" }

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-08-21 17:31 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-19 20:27 [C++ Patch] PR 67065 ("Missing diagnostics for ill-formed program with main variable instead of function") Ville Voutilainen
2015-08-19 20:28 ` Paolo Carlini
2015-08-19 20:37   ` Ville Voutilainen
2015-08-19 20:42     ` Paolo Carlini
2015-08-19 21:46       ` Ville Voutilainen
  -- strict thread matches above, loose matches on Subject: below --
2015-08-19 19:52 Paolo Carlini
2015-08-20  2:35 ` Jason Merrill
2015-08-21  6:30 ` Markus Trippelsdorf
2015-08-21  7:47   ` Markus Trippelsdorf
2015-08-21  9:07     ` Paolo Carlini
2015-08-21  9:22       ` Paolo Carlini
2015-08-21  9:29         ` Markus Trippelsdorf
2015-08-21 12:57           ` Paolo Carlini
2015-08-21 15:44         ` Jason Merrill
2015-08-21 17:22           ` Paolo Carlini
2015-08-21 17:37             ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).