Here after we complained about the extern "C" we continued to try and
merge the two definitions even though for a simple redefinition we give
up. In this case it seems to make most sense to treat the two functions
as different since they have different signatures; they just clash
because both are extern "C".
Tested x86_64-pc-linux-gnu, applying to trunk.
commit c19c0c71499dd74230061f186f40cd2a00dc6ed5
Author: Jason Merrill <ja...@redhat.com>
Date: Wed Mar 16 17:00:26 2011 -0400
PR c++/46336
* decl.c (duplicate_decls): Return NULL_TREE for clashing
C functions.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 3139ad8..17b3163 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -1456,6 +1456,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool
newdecl_is_friend)
error ("declaration of C function %q#D conflicts with",
newdecl);
error ("previous declaration %q+#D here", olddecl);
+ return NULL_TREE;
}
else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-46336.C
b/gcc/testsuite/g++.dg/cpp0x/constexpr-46336.C
new file mode 100644
index 0000000..3c51c2c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-46336.C
@@ -0,0 +1,14 @@
+// PR c++/46336
+// { dg-options -std=c++0x }
+
+extern "C" {
+ enum A { };
+ inline constexpr A
+ f(A a, A b) // { dg-error "previous declaration" }
+ { return A(static_cast<int>(a) & static_cast<int>(b)); }
+ enum B { };
+ inline constexpr B
+ f(B a, B b) // { dg-error "C function" }
+ { return B(static_cast<int>(a) & static_cast<int>(b)); }
+}
+
diff --git a/gcc/testsuite/g++.dg/parse/friend5.C
b/gcc/testsuite/g++.dg/parse/friend5.C
index ec134c2..bf1e6bf 100644
--- a/gcc/testsuite/g++.dg/parse/friend5.C
+++ b/gcc/testsuite/g++.dg/parse/friend5.C
@@ -4,5 +4,4 @@ extern "C" struct A
{
friend void foo(int) {} // { dg-error "declaration" }
friend void foo() {} // { dg-error "foo" "err" }
- // { dg-warning "already a friend" "warn" { target *-*-* } 6 }
};