PR c++/85580 - extern "C" and local variables
authorJason Merrill <jason@redhat.com>
Tue, 1 May 2018 12:45:49 +0000 (08:45 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 1 May 2018 12:45:49 +0000 (08:45 -0400)
* name-lookup.c (check_extern_c_conflict): Ignore local decls.

From-SVN: r259793

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/g++.dg/parse/extern-C-2.C [new file with mode: 0644]

index 65f556e..3453df8 100644 (file)
@@ -1,5 +1,8 @@
 2018-04-30  Jason Merrill  <jason@redhat.com>
 
+       PR c++/85580 - extern "C" and local variables
+       * name-lookup.c (check_extern_c_conflict): Ignore local decls.
+
        PR c++/84701 - unsigned typeof.
        * decl.c (grokdeclarator): Overhaul diagnostics for invalid use
        of long/short/signed/unsigned.
index 2af2462..64c7b6f 100644 (file)
@@ -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 (file)
index 0000000..d8a4e14
--- /dev/null
@@ -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;
+  }
+
+}