public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Danny Smith" <dansmister@gmail.com>
To: "GCC Patches" <gcc-patches@gcc.gnu.org>
Subject: [Patch]: Fix [Bug c++/34749]: Incorrect warning when applying dllimport to friend function
Date: Sat, 19 Jan 2008 15:10:00 -0000	[thread overview]
Message-ID: <9c03c2dd0801190023t5e4df954r2d349ad41444aefc@mail.gmail.com> (raw)

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

             reply	other threads:[~2008-01-19  8:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-19 15:10 Danny Smith [this message]
2008-02-19  3:03 ` Mark Mitchell
2008-02-24  9:38   ` Danny Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9c03c2dd0801190023t5e4df954r2d349ad41444aefc@mail.gmail.com \
    --to=dansmister@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).