Bug 609213 - instantiate a function
instantiate a function
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: gcc (Show other bugs)
6.2
All Linux
medium Severity medium
: rc
: ---
Assigned To: Jakub Jelinek
qe-baseos-tools
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2010-06-29 12:51 EDT by Issue Tracker
Modified: 2011-12-16 14:39 EST (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2011-12-16 14:39:15 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Issue Tracker 2010-06-29 12:51:59 EDT
Escalated to Bugzilla from IssueTracker
Comment 1 Issue Tracker 2010-06-29 12:52:01 EDT
Event posted on 2010-06-28 06:21 PDT by woodard

From: 	keasler1@llnl.gov
To: 	woodard9@llnl.gov
Subject: 	g++ __attribute__ ((used))
Date: 	06/25/2010 01:28:59 PM



Hi,

I have a templated class-static member function that I need to compile  
into my code for use in the debugger.  I tried adding "__attribute__  
((used))" to the function declaration in the hope that would force  
template instantiation of the function whenever the user made an  
instantitation of the class (i.e. they called a constructor for the  
class with a given template signature somewhere in their code).   
Unfortunately, the "used" attribute is not being honored in this case.

My workaround has been to add the following code to all my constructors:

     if (this == NULL)
        func(this) ;

But this is very messy since each of my classes has tens of constructors.

Any comments or suggestions?

Thanks,
-Jeff

From: 	Ben Woodard <bwoodard@llnl.gov>
To: 	keasler1@llnl.gov
Cc: 	woodard9@llnl.gov
Subject: 	Re: g++ __attribute__ ((used))
Date: 	06/25/2010 03:10:04 PM


So first of all I need to make sure that I understand.

You want a particular static member function in a templated class to be
available so that you can call it from the debugger but it is never
called from the actual program. So the compiler eliminates it as dead
code. 

You want to prevent the function from ever being eliminated and you
hoped that "__attribute__ ((used))" would do that for you but it doesn't
seem to work.

-ben

From: 	keasler1@llnl.gov
To: 	Ben Woodard <bwoodard@llnl.gov>
Subject: 	Re: g++ __attribute__ ((used))
Date: 	06/25/2010 03:21:09 PM

Right.  However, I don't expect the static member function to be  
instantiated unless the templated class it is attached to is  
instantiated.

If you are on-site and can get into B453, I'd be happy to show you why  
this is important to not just me.

-Jeff

This event sent from IssueTracker by woodard  [LLNL (HPC)]
 issue 1070613
Comment 4 Ben Woodard 2011-05-13 09:19:26 EDT
Per customer request. Please make this BZ public.
Comment 10 Jakub Jelinek 2011-12-16 14:39:15 EST
I believe this is already fixed in RHEL 6.2, under:
* Wed Aug 24 2011 Jakub Jelinek <jakub@redhat.com> 4.4.6-3
...
- support used attribute on template class methods and static data
  members for forced instantiation (#722587, PR c++/43125)

Note You need to log in before you can comment on or make changes to this bug.