public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* segfault when functions are defined in headers or inlined
@ 2015-07-10  9:50 achkan
  2015-07-10 10:33 ` Jonathan Wakely
  0 siblings, 1 reply; 8+ messages in thread
From: achkan @ 2015-07-10  9:50 UTC (permalink / raw)
  To: gcc-help

Hi,

Being from the computer vision community, I'm not sure who to turn to when
it comes to compiler problems, so I apologize in advance in case this is not
the most appropriate place to post this question.

The library that I'm trying to compile segfaults whenever an inlined member
function returns. Inspecting the code with gdb shows that the following
happens for all inline member functions (I'm really sorry, the code is
proprietary but I will post code as close as possible to the original one) : 

//in the header of an given class
ret & some_class::get_some_member()
{
   return this->_some_member;* //the address of some member is the same it
was when the this instance was created
}

//where the call is made
var=some_class_instance.get_some_member();//the address of the variable
changes. The function actually returns a new
                                                                    
//instance of _some_member, using its default constructor
                                                                     //which
later results in segfaults

The only solution that I have found is to remove the function definition
from the headers to the .cpp files. That way, the adress that function
returns is correct, and execution continues until the next inlined function
and the next segfault. Given that the library is quite large, removing
definition from headers is not an option. Furthermore, it seems to me that
g++ ignores the -fno-inline flag even though I have removed every
optimization flag. Is this a known issue? 

I'm working on Ubuntu 14.04 64bit, with g++ version g++ (Ubuntu
4.8.4-2ubuntu1~14.04) 4.8.4.

 Any help will greatly be appreciated.
 
Achkan SALEHI
achkan.salehi@cea.fr
ashsalehi4133@gmail.com



--
View this message in context: http://gcc.1065356.n5.nabble.com/segfault-when-functions-are-defined-in-headers-or-inlined-tp1167297.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: segfault when functions are defined in headers or inlined
@ 2015-07-10 14:28 johnsfine
  0 siblings, 0 replies; 8+ messages in thread
From: johnsfine @ 2015-07-10 14:28 UTC (permalink / raw)
  To: ashsalehi4133, gcc-help

 Even if the function returns a ref, the assignment (as you showed it) would not capture the ref.  It would assign the value.

I think you probably wanted
ret& var=some_class_instance.get_some_member();

I think the problem with inlining, that you think you are seeing, is just what I always call "stirring the pot".  When you have a serious bug, the symptoms may be hidden.  When you make an irrelevant change the symptoms might appear or disappear creating the illusion that the irrelevant change was relevant.  You haven't added or removed the bug, just stirred things to change the appearance of the bug.

I don't think there is a real chance of a gcc bug in all this, so this is likely the wrong forum for a serious discussion of the problem.  In the right forum, you would need to post more detail of the relevant declarations to get better help.


 

On 07/10/15, achkan wrote:


ret & some_class::get_some_member()
...
var=some_class_instance.get_some_member();//the address of the variable

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

end of thread, other threads:[~2015-07-10 15:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-10  9:50 segfault when functions are defined in headers or inlined achkan
2015-07-10 10:33 ` Jonathan Wakely
2015-07-10 11:04   ` achkan
2015-07-10 11:10     ` Jonathan Wakely
2015-07-10 11:21       ` achkan
2015-07-10 14:32         ` Ángel González
2015-07-10 15:32           ` achkan
2015-07-10 14:28 johnsfine

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