This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch]: Fix [Bug c++/34749]: Incorrect warning when applying dllimport to friend function
- From: "Danny Smith" <dansmister at gmail dot com>
- To: "GCC Patches" <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 19 Jan 2008 21:23:47 +1300
- Subject: [Patch]: Fix [Bug c++/34749]: Incorrect warning when applying dllimport to friend function
The problem here is that do_friend in friend.c calls
pushdecl_maybe_friend (names_lookup.c), before it calls
cplus_decl_attritubes. When pushdecl_maybe_friend checks for
duplicate_decls, the attribute list of the friend decl is still empty, so
the dllimport version of merge_decl_attributes finds apparent
inconsistency in dllimport linkage
This can be fixed by moving the call to cplus_decl_attributes so that
it precedes the call to pushdecl_maybe_friend.
Tested on i686-pc-mingw32
configured with: ../src/configure --enable-libgomp --host=mingw32
--build=mingw32 --target=mingw32 --with-arch=i486 --with-cpu=generic
--disable-werror --prefix=/mingw --enable-threads --disable-nls
--enable-languages=c,c++,fortran,ada --disable-win32-registry
--enable-libstdcxx-debug --enable-cxx-flags='-fno-function-sections
-fno-data-sections' --enable-version-specific-runtime-libs
--disable-sjlj-exceptions --enable-shared --disable-symvers
--disable-bootstrap
with no new regressions.
Danny
:ADDPATCH C++:
ChangeLog
2008-01-19 Danny Smith <dannysmith@users.sourceforge.net>
cp
PR c++/34749
* friend.c (do_friend): Call cplus_decl_attributes earlier.
testsuite
PR c++/34749
* g++.dg.ext/dllimport13.C: New test.
Index: cp/friend.c
===================================================================
--- cp/friend.c (revision 131650)
+++ cp/friend.c (working copy)
@@ -413,6 +413,13 @@
/* Every decl that gets here is a friend of something. */
DECL_FRIEND_P (decl) = 1;
+ /* Unfortunately, we have to handle attributes here. Normally we would
+ handle them in start_decl_1, but since this is a friend decl start_decl_1
+ never gets to see it. */
+
+ /* Set attributes here so if duplicate decl, will have proper attributes. */
+ cplus_decl_attributes (&decl, attrlist, 0);
+
if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR)
{
declarator = TREE_OPERAND (declarator, 0);
@@ -568,12 +575,5 @@
DECL_FRIEND_P (decl) = 1;
}
- /* Unfortunately, we have to handle attributes here. Normally we would
- handle them in start_decl_1, but since this is a friend decl start_decl_1
- never gets to see it. */
-
- /* Set attributes here so if duplicate decl, will have proper attributes. */
- cplus_decl_attributes (&decl, attrlist, 0);
-
return decl;
}
*** /dev/null Sat Jan 19 21:07:40 2008
--- testsuite/g++.dg/ext/dllimport13.C Sat Jan 19 21:07:38 2008
***************
*** 0 ****
--- 1,14 ----
+ // PR c++/34749
+ // Ensure dllimport is handled correctly for friends.
+
+ // { dg-do compile { target i?86-*-cygwin* i?86-*-mingw*} }
+
+ int __declspec (dllimport) bar();
+ int __declspec (dllimport) baz();
+
+ class Foo
+ {
+ // MS requires that the dllimport attribute be specified on each declaration
+ friend int __declspec (dllimport) bar();
+ friend int baz(); // { dg-warning "dllimport ignored" }
+ };