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 921069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:48:58+00:00 2026-05-15T18:48:58+00:00

My program has this function: vector<itemPtr> Level::getItemsAt(const Point& pt) { vector<itemPtr> vect(items.size()); // copy

  • 0

My program has this function:

    vector<itemPtr> Level::getItemsAt(const Point& pt)
    {
        vector<itemPtr> vect(items.size());
        // copy all items at pt's position to vect
        remove_copy_if(items.begin(), items.end(), vect.begin(),
                       boost::bind(matchesPosition<itemPtr>, _1, pt));

        // update LevelMap and return
        map.setHasItem(pt, false);
        return vect;
    }

This compiles fine (I’m using g++, my gcc version is 4:4.4.1-1ubuntu2), but when I run the program it skips right over the return statement.

I stepped through with gdb, setting a breakpoint at the previous line, and got this:

Breakpoint 1, yarl::level::Level::getItemsAt (this=0x80d4d58, pt=...)
at src/Level.cpp:519
519                 map.setHasItem(pt, false);
(gdb) next
521             }
(gdb) 

I’ve tried recompiling from scratch several times, erasing the executable and all the object files beforehand, and it still does it.

Strangely, if I comment out the return statement and try to compile, it only gives warning: no return statement in function returning non-void. I would have thought not providing a return statement in a function that returns something would be a compiler error, but I guess not.

I realize this is not much to go on, but does anyone have an idea why this is happening? What to check for? At this point I don’t even know where to start looking.

EDIT: for clarification, I’m compiling with -O0.

According to tjm, my version of gcc will still use RVO even with a -O0 compiler flag, so that was the problem after all. Thanks for your help, guys.

  • 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-05-15T18:48:58+00:00Added an answer on May 15, 2026 at 6:48 pm

    C++ source code does not have to correspond to resulting object code one-to-one as long as the behavior is preserved. What’s happening here is that the compiler rearranges the code, and probably invokes Return Value Optimization.

    Edit:

    Add this to the GCC options: -fdump-tree-nrv to see NRVO applications by the compiler (you’ll get a file with .nrv extension). This only works with optimization level greater then -O0.

    Without optimization, replacing the return statement with copy constructor or copy assignment operator call is still a C++ front-end transformation, which is not gracefully handled by the gdb.

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

Sidebar

Ask A Question

Stats

  • Questions 495k
  • Answers 496k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer from wikipedia: A data file is a computer file which… May 16, 2026 at 11:30 am
  • Editorial Team
    Editorial Team added an answer It is sent from your server; if it's Linux, Linux… May 16, 2026 at 11:30 am
  • Editorial Team
    Editorial Team added an answer I had a similar issue when porting a Web Test… May 16, 2026 at 11:30 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

My program has a class with a vector of Level objects named levels .
This program has the user input name / age pairs and then outputs them,
What is wrong with this program? #include <memory> #include <vector> int main() { std::vector<std::unique_ptr<int>>
i'm lost in this , i have a class that has three vector objects
I'm using Visual Studio 2008. I'm aware that std::vector has bounds checking with the
I'm using openURL to send an email w/some links. The function looks like this:
this is my code snippet, where the program doesn't enter the foreach loop: var
I have two files. main.py that has main program logic and functions.py that has
I have a class Message that has a std::string as a data member, defined
My program uses a NetworkOutput object which can be used to write data to

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.