Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8853773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:43:52+00:00 2026-06-14T13:43:52+00:00

I am seeing a strange issue where by member methods aren’t getting inlined if

  • 0

I am seeing a strange issue where by member methods aren’t getting inlined if I define a destructor.

Example code:

#include <cstdio>

class Foo
{
public:
    Foo(int arg) : data(arg) {}
    ~Foo(void) {}

    Foo bar(void) const { return Foo(7); }

    int data;
};

int main(void)
{
        Foo a(3);
        Foo b = a.bar();

        printf ("%i", b.data);
}

If using the default destructor, I get something like this:

main:
 sub         rsp,28h  
 lea         rcx,[string "%i" (013FB8ADA0h)]  
 mov         edx,7  
 call        printf (013FB81068h)  
 xor         eax,eax  
 add         rsp,28h  
 ret  

But if I define my own blank destructor, as in the code above:

Foo::bar:
 mov         dword ptr [rdx],7  
 mov         rax,rdx  
 ret  

main:
 sub         rsp,28h  
 lea         rdx,[b]  
 call        Foo::bar (013FA11000h)  
 mov         edx,dword ptr [b]  
 lea         rcx,[string "%i" (013FA1ADA0h)]  
 call        printf (013FA11088h)  
 xor         eax,eax  
 add         rsp,28h  
 ret  

Compiled as a release build using Visual Studio 2012 (v110), though also tried Visual Studio 2010 (v100). I tried setting /Ob2 to help persuade it to inline the method with no luck.

I’m not familiar enough with assembly to know exactly what it’s trying to do, maybe tomorrow I’ll try to figure that out to see it if gives any hints. Can anyone shed any light on why defining an empty destructor would prevent the method being inlined?

EDIT [17/11/2012]

I updated the code above to be much simpler (originally I was working on my Vector class).

Returning a primitive type from a member method seems to get inlined correctly, it’s only an issue when I return an instance of my class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:43:53+00:00Added an answer on June 14, 2026 at 1:43 pm

    Visual Studio treats classes with destructors (empty or not) as “complex” and they will be more likely to abandon certain optimizations. If your class is simple and speed sensitive, use the default destructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm seeing a very strange issue with a .NET webservice being consumed by Flex.
I'm seeing a strange issue on a phone and I'm trying to come up
having a strange issue, must be something I'm just not seeing. I set up
i'm seeing a really strange issue with asp.net rendering. i have EXACTLY this in
I am seeing a bit of a strange issue on webkit browsers where when
I am seeing a strange issue in flex. I need to reset all text
I'm seeing a really strange issue with JPopupMenu's and JComboBox's. When the application is
I am seeing a very strange issue with a simple controller method. Either I
I'm seeing strange errors when my C++ code has min() or max() calls. I'm
We're seeing a very strange issue when running the following application from a network

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.