public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/85580, wrong name class error with extern "C" locals
@ 2018-05-01 12:53 Jason Merrill
  2018-05-01 13:18 ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2018-05-01 12:53 UTC (permalink / raw)
  To: gcc-patches List; +Cc: Nathan Sidwell, Jakub Jelinek

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

It wasn't a problem before that we didn't check for namespace scope,
because we were only looking at functions.  Now that we look at
variables as well, we need to consider their scope.

Tested x86_64-pc-linux-gnu, applying to trunk.  Jakub, this looks like
a P1, should it go into 8.1 as well?

[-- Attachment #2: 85580.diff --]
[-- Type: text/x-patch, Size: 1215 bytes --]

commit a97af841718779b615bd0a599cac956396c8c85a
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Apr 30 17:37:20 2018 -0400

            PR c++/85580 - extern "C" and local variables
    
            * name-lookup.c (check_extern_c_conflict): Ignore local decls.

diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 2af2462825c..64c7b6f006e 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -2527,6 +2527,10 @@ check_extern_c_conflict (tree decl)
   if (DECL_ARTIFICIAL (decl) || DECL_IN_SYSTEM_HEADER (decl))
     return;
 
+  /* This only applies to decls at namespace scope.  */
+  if (!DECL_NAMESPACE_SCOPE_P (decl))
+    return;
+
   if (!extern_c_decls)
     extern_c_decls = hash_table<named_decl_hash>::create_ggc (127);
 
diff --git a/gcc/testsuite/g++.dg/parse/extern-C-2.C b/gcc/testsuite/g++.dg/parse/extern-C-2.C
new file mode 100644
index 00000000000..d8a4e14b4b7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/extern-C-2.C
@@ -0,0 +1,22 @@
+// PR c++/85580
+
+extern "C"
+{
+
+  void f1()
+  {
+    union some_type{
+      char a[2];
+      int b;
+    } variable;
+  }
+
+  void f2()
+  {
+    union some_type{
+      char a[2];
+      int b;
+    } variable;
+  }
+
+}

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

* Re: C++ PATCH for c++/85580, wrong name class error with extern "C" locals
  2018-05-01 12:53 C++ PATCH for c++/85580, wrong name class error with extern "C" locals Jason Merrill
@ 2018-05-01 13:18 ` Jakub Jelinek
  2018-05-01 13:54   ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2018-05-01 13:18 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List, Nathan Sidwell

On Tue, May 01, 2018 at 08:52:42AM -0400, Jason Merrill wrote:
> It wasn't a problem before that we didn't check for namespace scope,
> because we were only looking at functions.  Now that we look at
> variables as well, we need to consider their scope.
> 
> Tested x86_64-pc-linux-gnu, applying to trunk.  Jakub, this looks like
> a P1, should it go into 8.1 as well?

I think this should be safe even without another rc, please check it into
8.1.

Thanks.

> commit a97af841718779b615bd0a599cac956396c8c85a
> Author: Jason Merrill <jason@redhat.com>
> Date:   Mon Apr 30 17:37:20 2018 -0400
> 
>             PR c++/85580 - extern "C" and local variables
>     
>             * name-lookup.c (check_extern_c_conflict): Ignore local decls.
> 
> diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
> index 2af2462825c..64c7b6f006e 100644
> --- a/gcc/cp/name-lookup.c
> +++ b/gcc/cp/name-lookup.c
> @@ -2527,6 +2527,10 @@ check_extern_c_conflict (tree decl)
>    if (DECL_ARTIFICIAL (decl) || DECL_IN_SYSTEM_HEADER (decl))
>      return;
>  
> +  /* This only applies to decls at namespace scope.  */
> +  if (!DECL_NAMESPACE_SCOPE_P (decl))
> +    return;
> +
>    if (!extern_c_decls)
>      extern_c_decls = hash_table<named_decl_hash>::create_ggc (127);
>  
> diff --git a/gcc/testsuite/g++.dg/parse/extern-C-2.C b/gcc/testsuite/g++.dg/parse/extern-C-2.C
> new file mode 100644
> index 00000000000..d8a4e14b4b7
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/parse/extern-C-2.C
> @@ -0,0 +1,22 @@
> +// PR c++/85580
> +
> +extern "C"
> +{
> +
> +  void f1()
> +  {
> +    union some_type{
> +      char a[2];
> +      int b;
> +    } variable;
> +  }
> +
> +  void f2()
> +  {
> +    union some_type{
> +      char a[2];
> +      int b;
> +    } variable;
> +  }
> +
> +}

	Jakub

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

* Re: C++ PATCH for c++/85580, wrong name class error with extern "C" locals
  2018-05-01 13:18 ` Jakub Jelinek
@ 2018-05-01 13:54   ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2018-05-01 13:54 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches List, Nathan Sidwell

On Tue, May 1, 2018 at 9:18 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Tue, May 01, 2018 at 08:52:42AM -0400, Jason Merrill wrote:
>> It wasn't a problem before that we didn't check for namespace scope,
>> because we were only looking at functions.  Now that we look at
>> variables as well, we need to consider their scope.
>>
>> Tested x86_64-pc-linux-gnu, applying to trunk.  Jakub, this looks like
>> a P1, should it go into 8.1 as well?
>
> I think this should be safe even without another rc, please check it into
> 8.1.

Done.

Jason

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

end of thread, other threads:[~2018-05-01 13:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-01 12:53 C++ PATCH for c++/85580, wrong name class error with extern "C" locals Jason Merrill
2018-05-01 13:18 ` Jakub Jelinek
2018-05-01 13:54   ` 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).