public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch]: Fix [Bug c++/34749]: Incorrect warning when applying dllimport to friend function
@ 2008-01-19 15:10 Danny Smith
  2008-02-19  3:03 ` Mark Mitchell
  0 siblings, 1 reply; 3+ messages in thread
From: Danny Smith @ 2008-01-19 15:10 UTC (permalink / raw)
  To: GCC Patches

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" }
+ };

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

* Re: [Patch]: Fix [Bug c++/34749]: Incorrect warning when applying  dllimport to friend function
  2008-01-19 15:10 [Patch]: Fix [Bug c++/34749]: Incorrect warning when applying dllimport to friend function Danny Smith
@ 2008-02-19  3:03 ` Mark Mitchell
  2008-02-24  9:38   ` Danny Smith
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Mitchell @ 2008-02-19  3:03 UTC (permalink / raw)
  To: Danny Smith; +Cc: GCC Patches

Danny Smith wrote:

> 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.

OK for 4.3 and 4.4.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

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

* Re: [Patch]: Fix [Bug c++/34749]: Incorrect warning when applying dllimport to friend function
  2008-02-19  3:03 ` Mark Mitchell
@ 2008-02-24  9:38   ` Danny Smith
  0 siblings, 0 replies; 3+ messages in thread
From: Danny Smith @ 2008-02-24  9:38 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: GCC Patches

On Tue, Feb 19, 2008 at 3:55 PM, Mark Mitchell <mark@codesourcery.com> wrote:
> Danny Smith wrote:
>
>  > 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.
>
>  OK for 4.3 and 4.4.
>
Thanks,
I have committed to 4.4 and will commit to 4.3 branch when reopen.
Danny.

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

end of thread, other threads:[~2008-02-24  9:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-19 15:10 [Patch]: Fix [Bug c++/34749]: Incorrect warning when applying dllimport to friend function Danny Smith
2008-02-19  3:03 ` Mark Mitchell
2008-02-24  9:38   ` Danny Smith

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).