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

  • Home
  • SEARCH
  • 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 7758865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:28:40+00:00 2026-06-01T13:28:40+00:00

using VS 2010 with full optimization /Ox look at the following two function calls:

  • 0

using VS 2010 with full optimization /Ox look at the following two function calls:

static string test1(const string& input)
{
    return input;
}

static void test2(const string& input, string& output)
{
    output = input;
}

If I use the latter test2 then the function is always optimized out and the code inlined. However test1 is not inlined unless I turn off exceptions. Does anyone know why this is?

Additionally I would expect the compiler to be able to do as an efficient a job in test1 as test2 if it uses return value optimization but it seems not to be doing that. This also is puzzling me.

The reason I want to use the first function signature would be that I have two compilable versions of the function. I want to have the calling code always call test1 and when a certain compile flag is set I want it to append the input to a copy and return it, when the compile flag is not set I want it to get as close to being a no-op as possible.

  • 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-01T13:28:42+00:00Added an answer on June 1, 2026 at 1:28 pm

    Visual Studio can’t inline functions that return objects with non-trivial destructors:

    In some cases, the compiler will not inline a particular function for mechanical reasons. For example, the compiler will not inline:

    • A function if it would result in mixing both SEH and C++ EH.
    • Some functions with copy constructed objects passed by value when -GX/EHs/EHa is on.
    • Functions returning an unwindable object by value when -GX/EHs/EHa is on.
    • Functions with inline assembly when compiling without -Og/Ox/O1/O2.
    • Functions with a variable argument list.
    • A function with a try (C++ exception handling) statement.

    http://msdn.microsoft.com/en-us/library/a98sb923.aspx

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

Sidebar

Related Questions

I have a test application using the Lync 2010 SDK in full UI suppressed
When using the DATETIME function to do some arithmetic, I've found the following behaviour:
I am using Visual Studio 2010 ultimate edition and i install it with full
I have HTML view using 2010 .NET, which I am generating in the report
Using Delphi 2010 and a patched version of the BDE I run into a
Using VS 2010, with ASP.NET, and .NET 3.0, and C#... When I use a
I'm using VS 2010, and I'm wondering how I can get my c++ program
I am using VS 2010 RTM and trying to perform some basic validation on
I'm using Office 2010 interop and C# 4. How can I convert just the
We are using TFS 2010 with gated checkins. I've got some question about what

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.