From 38dff92114f41914541fded07bee54c48b817ee2 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 1 May 2018 08:45:49 -0400 Subject: [PATCH] PR c++/85580 - extern "C" and local variables * name-lookup.c (check_extern_c_conflict): Ignore local decls. From-SVN: r259793 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/name-lookup.c | 4 ++++ gcc/testsuite/g++.dg/parse/extern-C-2.C | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 gcc/testsuite/g++.dg/parse/extern-C-2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 65f556e0c76..3453df8aa18 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2018-04-30 Jason Merrill + 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. 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::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; + } + +} -- 2.30.2