Message ID | 55D6EA2C.2090400@oracle.com |
---|---|
State | New |
Headers | show |
On 2015.08.21 at 11:06 +0200, Paolo Carlini wrote:
> ... I'm testing the below. So far appears to work well for me.
Yes for me, too. Firefox now builds without any issues.
So emitting an error (like clang) is fine after all.
Thanks.
Hi, On 08/21/2015 11:23 AM, Markus Trippelsdorf wrote: > On 2015.08.21 at 11:06 +0200, Paolo Carlini wrote: >> ... I'm testing the below. So far appears to work well for me. > Yes for me, too. Firefox now builds without any issues. > So emitting an error (like clang) is fine after all. Excellent. Testing completed successfully. Thus, unless Jason disagrees, I mean to commit it as an obvious follow up later today. Paolo.
On 08/21/2015 05:06 AM, Paolo Carlini wrote: > if (DECL_NAME (decl) > && MAIN_NAME_P (DECL_NAME (decl)) > - && CP_DECL_CONTEXT (decl) == global_namespace) > + && CP_DECL_CONTEXT (decl) == global_namespace > + && !at_function_scope_p ()) How about looking at the "scope" local variable instead of CP_DECL_CONTEXT? Jason
Hi, On 08/21/2015 05:37 PM, Jason Merrill wrote: > On 08/21/2015 05:06 AM, Paolo Carlini wrote: >> if (DECL_NAME (decl) >> && MAIN_NAME_P (DECL_NAME (decl)) >> - && CP_DECL_CONTEXT (decl) == global_namespace) >> + && CP_DECL_CONTEXT (decl) == global_namespace >> + && !at_function_scope_p ()) > > How about looking at the "scope" local variable instead of > CP_DECL_CONTEXT? Ah nice. Simply checking: scope == global_namespace appears to work great. Shall I go with that if testing is fine? Thanks! Paolo.
On 08/21/2015 01:11 PM, Paolo Carlini wrote: > Ah nice. Simply checking: > > scope == global_namespace > > appears to work great. Shall I go with that if testing is fine? Please. Jason
Index: cp/decl.c =================================================================== --- cp/decl.c (revision 227054) +++ cp/decl.c (working copy) @@ -8357,7 +8357,8 @@ grokvardecl (tree type, if (DECL_NAME (decl) && MAIN_NAME_P (DECL_NAME (decl)) - && CP_DECL_CONTEXT (decl) == global_namespace) + && CP_DECL_CONTEXT (decl) == global_namespace + && !at_function_scope_p ()) error ("cannot declare %<::main%> to be a global variable"); /* Check that the variable can be safely declared as a concept. Index: testsuite/g++.dg/other/pr67065.C =================================================================== --- testsuite/g++.dg/other/pr67065.C (revision 227054) +++ testsuite/g++.dg/other/pr67065.C (working copy) @@ -1,3 +1,5 @@ // PR c++/67065 int main; // { dg-error "cannot declare" } + +void foo() { int main; }