Temporary objects are deleted incorrectly

The temporary objects are deleted (their destructors called) when they are leaving the scope of the expression due to wich they were created. But the Standard says that a temporary object should be deleted when the full expression due to wich it was created is completely evaluated (if no reference to it was created).
Consider the following example:
#include <iostream>
using namespace std;
class A
public:
A() {
  cout << "A constructor" << endl;
~A() {
  cout << "A destructor" << endl;
A foo() {
cout << "foo has been called" << endl;
return A();
void foo2(A const& a) {
cout << "foo2 has been called" << endl;
int main(int argc, char *argv[], char *envp[])
cout << "main started" << endl;
foo2(foo()); // BUG
cout << "main continued execution" << endl;
return 0;
}This test makes the following output:
main started
foo has been called
A constructor
foo2 has been called
main continued execution
A destructor
As you may see, the temporary object of type A created as a return value of function foo() is deleted on main() exit, not on finishing evaluation of the expression "foo2(foo());".
The expected output is:
main started
foo has been called
A constructor
foo2 has been called
A destructor
main continued execution
Actually, if the line marked as BUG is enclosed in {} brackets the desired output is achieved.

For compatibility with older compilers, the compiler by default destroys temporary objects at the end of the block in which they are destroyed.
To get standard-conforming behavior, use the compiler option
-features=tmplife
on each module where temporary lifetime makes a difference.

Similar Messages

  • How to trace if objects are deleted from a scenario

    Hi Experts,
    Can you please tell me if some of my objects get deleted from my scenario how can I trace? like by which user this is done or any log is there from where we can find this one?
    Thanks
    Sugata B

    Just run the scenario if you are aware of the entire process by disabling target system adapter (if needed)
    then you can easily trace it out.
    If you know details about mapping go to SXI_CACHE and chk there, for  objects of your scenario
    Rajesh

  • Vector objects are displayed incorrectly

    Hi!
    I am using Flash CS6. I need to draw a small vector icons (about 14x14).
    Simple example: I draw a rounded rectangle with corner radius  "2". Here is a resulting image from Flash (14x14, 100% scale):
    As you can see, top corners are not drawed correctly, and bottom corners looks like radius is "1", not "2".
    And here is what I expect (from Photoshop):
    The same thing happens after importing icon from Illustrator to Flash as editable path - icon is distorted. But when I impoting it as bitmap - it looks exactly the same as in Illustrator. Only vector shapes showing incorrectly.
    How can I fix it?

    Neither of those appear to be vector objects as evidenced by the presence of pixels.  I don't understand why you label them as 14x14 at 100%.  If anything they are signicantly magnified.  Below is a 14x14 vector rectangle with a corner rounding of 2 shown at 800% drawn in Flash CS3. 

  • Temporary objects deleted to soon?

    bash-3.2$ uname -a
    SunOS solaris 5.11 snv_86 i86pc i386 i86pc
    bash-3.2$ CC -V
    CC: Sun C++ 5.9 SunOS_i386 2007/11/15
    I believe that the C++ compiler is producing incorrect results with respect
    to the creation and destruction of temporary variables when using operator
    overloading.
    The code sample below is compiled using:
    bash-3.2$ CC -o huh6.exe huh6.C -features=tmplife -features=strictdestrorder
    // begin code: huh6.C
    #include  <stdio.h>
    #include  <stdlib.h>
    class AClass {
    public:
        double *a;
        AClass( double x = 0 );
        ~AClass( void ) {
            //printf("<<<AClass variable deleted>>>\n");
            delete [] a;
        AClass& operator=( const AClass &right );
        friend AClass operator+( const AClass &left, const AClass &right );
    AClass::AClass( double x ) {
        a = new double[1];
        a[0] = x;
        //printf("***AClass variable created***\n");
    AClass& AClass::operator=( const AClass &right ) {
        a[0] = right.a[0];
        return( *this );
    AClass operator+( const AClass &left, const AClass &right ) {
        AClass tmp;
        tmp.a[0] = left.a[0] + right.a[0];
        return( tmp );
    int main() {
        AClass f, g, x, y, z;
        x.a[0] = 1.0; 
        y.a[0] = 2.0;
        z.a[0] = 3.0;
        f = x + y + z;
        printf("(1) f.a = %e\n", f.a[0]);
        g = x + y;
        g = g + z;
        printf("(2) g.a = %e\n", g.a[0]);
        return(0);
    // end code huh6.C
    Execution of the program yields:
    bash-3.2$ ./huh6.exe
    (1) f.a = 3.000000e+00
    (2) g.a = 6.000000e+00
    The expected result is
    (1) f.a = 6.000000e+00
    (2) g.a = 6.000000e+00
    By uncommenting the printf statements it will be noted that the temporary
    variables are deleted too soon.
    Is there a compiler option that I am missing?
    Thanks in advance.
    ===================================
    The g++ compiler (using Linux/Mac OS X/OpenBSD/FreeBSD) produces:
    (1) f.a = 6.000000e+00
    (2) g.a = 6.000000e+00

    The code involves copying AClass objects to create temps, and you don't have a copy constructor. The compiler-generated copy constructor copies the pointer 'a' in the class, and when one of the copies is destroyed, the data in the other copy is also destroyed.
    Add a copy constructor similar to the one below and your code should behave as you expect.
    AClass::AClass( const AClass &c ) {
        a = new double[1];
        a[0] = c.a[0];
        // printf("copy    from %p to %p\n", &c, this);
    }

  • Objects for deletion included in support package are not deleted

    Hi experts,
    How can i create a support package using Add-on Assembly Kit that deletes several objects?
    This is the case:
    We have DEV, QA and PROD systems. The objects are deleted on DEV and the transports are released. The transports are automatically imported on QA and the objects are deleted -checked they are gone. A support package of the product is created on QA including the transports that delete the objects. The SP is released successfully and imported on PROD successfully. The objects that should be deleted still exist on PROD. I've checked the logs for errors - no errors found.
    Do you have any idea what could be the reason?
    Best regards,
    Petar

    Note number 1581093.
    As mentioned in the symptom. Version 2 of the note is created to extend the functionality provided in the Version 1. Version 3 of the note is created to correct the error in Version 2.
    Information from SPAM
    SAP_HR     600     0054     SAPKE60054     Human Resources
    How can I find the information required if neeed?
    WHen I try to reset the implementation I get the message
    No correction instructions implemented for SAP
    Note 0001581093
    Edited by: Wojciech Walczak ITMAXI.COM on May 25, 2011 12:00 PM

  • Account assignment objects are incorrect. No substitution is possible

    Account assignment objects are incorrect. No substitution is possible.
    Message no. 3G209
    Diagnosis
    The account assignment object check showed that, from the point of view of CO, the specified account assignment is not valid, and cannot be replaced by the employee's master cost center or a substitute cost center. This item cannot be posted.

    delete the previous results and run the live pay roll run and accounting run

  • Temporary object deleted too late...

    #include <string>
    #include <memory>
    class A{
    pubilc:
       const std::string& getId() const{ return i_id;}
    private:
       const std::string i_id;
    namespace{
    std::auto_ptr<A>
    return_autoptr_object(const char* arg)
      A* const ret = new A(/*arg*/);
      return std::auto_ptr<A>(ret);
    int main()
        const std::string myID=return_autoptr_object("test_autoptr")->getId();
        typedef void end_of_block_scope;
        std::cout << "*** out of scope here ****" << std::endl;
      return 0;
    }The code above shows that a temporary object(returned by return_autoptr_object(..)) is deleted only AFTER(?) "out of scope here" line being printed. I expected it should be deleted right after it's being assigned its' id to "myID", where the checkpoint for that function exists, and NOT when it goes out of scope (of the block).
    I tested it with other two compilers(gcc and visual age c++), both yield to the same expected result, only sun CC had diff result.
    Possibly it's a bug?

    Just a quick remark: It is with sunstudio 12 that lifetimes become standard. SunStudio 11 still has the same old behavior.
    #include <iostream>
    struct testerClass
            testerClass() {}
            ~testerClass() {std::cout << "Destructor for testerClass" << std::endl;}
            void doit() {std::cout << "doit invoked" << std::endl;}
    int main()
            testerClass().doit();
            std::cout << "Out of scope by now" << std::endl;
    }a) /opt/SUNWspro/v11/bin/CC main.cc
    doit invoked
    Out of scope by now
    Destructor for testerClass
    b) /opt/SUNWspro/v11/bin/CC -features=tmplife main.cc
    doit invoked
    Destructor for testerClass
    Out of scope by now
    version of "/opt/SUNWspro/v11/prod/bin/../../bin/cc": Sun C 5.8 Patch 121015-04 2007/01/10

  • Account assignment objects are incorrect

    I have assigned the Cost Center at Employee Level in IT0001.But still at the Time of posting for Expense account,it is taking Blank Cost Center  & i am getting below error.
    "Account assignment objects are incorrect. No substitution is poss
    No substitute cost center maintained
    No master cost center is possible as replacement for direct acct
    Enter a true account assignment relevant to cost accounting."
    Please help me out with this problem.
    Please tell me is thr anywhere i have to assign the Costcenters.We want that Posting should go with Employees Cost Center only for Expnse accounts.
    Thanx,
    Viru.

    System is asking alternative cost centre for your company code.
    Please create the a new cost centre, then assign to your company code in the table of TKA3G.
    Or else go to path:
    Payroll-> Payroll india or singapore or usa->Posting to financial accounting->Activities in the AC-System->Set up fixed cost postings and substitute cost centers->Set up substitute cost centers .
    For each country text will vary. but fixed substitute cost center name will be appear.
    Ask to your FI guys then they will create a new cost centre.
    For fixed cost centre assign cost centre to your cost element.(V_TKA30)

  • How to delete unreleased transport request where the objects are locked

    Hi Experts,
      I was created a transport request, but I am facing some probelms with taht request, now I want to delete transport request. I tried to delete them in SE10, I am getting message that the objects are locked. Please tell me how to delete unreleased transport requests where the objects belong to this transport request are locked.

    Hi,
    First go to transaction se03 Choose "Unlock Objects (Expert Tool)" option under "Requests/Tasks" and unlock your task,
    Than go to se10 and delete what you want.
    I hope it helps.
    Bulent

  • Some objects are no longer available in the universe.(Error: WIS 00001)

    We are in the process of upgrading BOXI R2 to R3.1 SP3. Setup, configuration of BOXI R3 on new machine is done. And migrated the reports,  universes, users, groups and all repository objects with Import Wizard. everything seems good except few Webi reports pointing to wrong universes and getting the below error message.
    "Some objects are no longer available in the universe. See your Business Objects administrator. (Error: WIS 00001)"
    1) I deleted the particular report from destination and re imported it but still same issue.
    2) deleted the file from Input file store and re imported it still same error I'm getting.
    Gurus, Please help me..
    Thanks,

    if the issues is with one or two reports i would've tried manually editing each report, but here we've this issue with 20+ reports so far..
    Just pointing it to right universe won't work, I've to add the missing objects as well. So Its like developing new report.
    Thanks!

  • Catalog objects are not found sometimes.

    Sometimes we hit an error that our catalog objects are not found. We find that the relevant column views in the schema _SYS_BIC are missing. So it should be the root cause. But we don't know why these views are removed.  Could you give us some explanation?
    Thanks,
    Li

    Hi Li,
    I think maybe they are deleted by someone manually.
    BR,
    Phoebe

  • Y in java objects are created on heap only and not on stack ??

    Hi ,
    I need a answer to the question " why all the objects are created on heap only in java and not on stack " ?
    In java a object is created when we specify new i.e. for example,
    consider the following cases.
    1.
    Vector v = new Vector();
    here object is created and the reference to this object is assigned to variable v. okie.
    2.
    when i write something like
    Vector vec ;
    Here i am creating reference variable for Vector. No object is created and no seperate memory is allocated for it. Reference variablesa are stored along with other primitive variables on the java stack.
    My question is, in C++ by writing case 2 i can create an object and it is creating this object on stack. So why in java object is not created on stack while i do like this ? Why in java objects are created on heap only ?
    If my question is out of interest of this forum i apologize for it. But if somebody can throw some light on it, it would be of great help.
    Cheers !!
    Dipesh

    Hi
    I asked this question just to understand how compiler and jvm cud have been designed......i.e. to know the philosophy behind designing language.......
    now what i cud surmise is that if objects were to be stored in stack then on calling garbage colllector , it may delete some unused obj and unreferenced object(unreachable object) and this in turn may give rise to non-contagious areas in stack, thus nullifying the garbage collector's objective of freeing the the memory. Again deallocating that intersperse spaces into one free block of space will be bit troublesome task.....
    So considering above factor the designer of jvm and java compiler have opted for storing objects on heap rather than stack.....
    If u have something to say bout this.......pls go ahead.......
    Cheers !!
    Dipesh

  • Copy constructor and temporary objects in C++

    I'd need some clarification on how constructor works when the argument is  a temporary object. I defined a dummy MyVect class with operator+ and copy constructor:
    class MyVect {
    public:
    MyVect() {
    cout << "Constructor" << endl;
    MyVect(const MyVect &vect){
    cout << "Copy Constructor" << endl;
    ~MyVect() {
    cout << "Destructor" << endl;
    MyVect operator+(const MyVect &v) const {
    cout << "operator+" << endl;
    MyVect result
    return result;
    Then I test it with this very simple code pattern:
    MyVect v1;
    MyVect v2;
    MyVect v3(v1 + v2);
    The output is:
    Constructor
    Constructor
    operator+
    Constructor
    Destructor
    Destructor
    Destructor
    The first two constructor calls are for v1 and v2, then operator+ for  v1+v2 is called, and  inside it there is a constructor call for result object. But then no copy constructor (nor constructor) for v3 is called. In my limited understanding of C++, I guessed that once the temporary object resulting from v1+v2 has been created, then it would be the argument of the copy constructor call. Instead it looks like the compiler transforms the temporary into v3, since v3 is correctly initialized as the sum of v1 and v2 (I tried with a more complicated version of MyVect to verify this). This behavior reminds me of the move semantics introduced with C++11, but I'm not using the -std=c++11 flag (and in fact if I try to define a move constructor the compilation fails).
    Can anyone please help me to understand what's happening under the hood? Thanks.
    Last edited by snack (2013-02-13 10:44:28)

    wikipedia wrote:The following cases may result in a call to a copy constructor:
    When an object is returned by value
    When an object is passed (to a function) by value as an argument
    When an object is thrown
    When an object is caught
    When an object is placed in a brace-enclosed initializer list
    These cases are collectively called copy-initialization and are equivalent to:[2] T x = a;
    It is however, not guaranteed that a copy constructor will be called in these cases, because the C++ Standard allows the compiler to optimize the copy away in certain cases, one example being the return value optimization (sometimes referred to as RVO).
    Last edited by Lord Bo (2013-02-13 13:58:47)

  • How can I find out what objects are in a datafile???

    My database is 8.1.7...
    I have a tablespace with multiple datafiles. How can I find out what objects are in a specific datafile???
    Thanks in advance...

    DBA_SEGMENTS
    DBA_SEGMENTS describes the storage allocated for all segments in the database.
    Related View
    USER_SEGMENTS describes the storage allocated for the segments owned by the current user's objects. This view does not display the OWNER, HEADER_FILE, HEADER_BLOCK, or RELATIVE_FNO columns.
    Column Datatype NULL Description
    OWNER
    VARCHAR2(30)
    Username of the segment owner
    SEGMENT_NAME
    VARCHAR2(81)
    Name, if any, of the segment
    PARTITION_NAME
    VARCHAR2(30)
    Object Partition Name (Set to NULL for non-partitioned objects)
    SEGMENT_TYPE
    VARCHAR2(17)
    Type of segment: INDEX PARTITION, TABLE PARTITION, TABLE, CLUSTER, INDEX, ROLLBACK, DEFERRED ROLLBACK, TEMPORARY, CACHE, LOBSEGMENT and LOBINDEX
    TABLESPACE_NAME
    VARCHAR2(30)
    Name of the tablespace containing the segment
    HEADER_FILE
    NUMBER
    ID of the file containing the segment header
    HEADER_BLOCK
    NUMBER
    ID of the block containing the segment header
    BYTES
    NUMBER
    Size in bytes, of the segment
    BLOCKS
    NUMBER
    Size, in Oracle blocks, of the segment
    EXTENTS
    NUMBER
    Number of extents allocated to the segment
    INITIAL_EXTENT
    NUMBER
    Size in bytes requested for the initial extent of the segment at create time. (Oracle rounds the extent size to multiples of 5 blocks if the requested size is greater than 5 blocks.)
    NEXT_EXTENT
    NUMBER
    Size in bytes of the next extent to be allocated to the segment
    MIN_EXTENTS
    NUMBER
    Minimum number of extents allowed in the segment
    MAX_EXTENTS
    NUMBER
    Maximum number of extents allowed in the segment
    PCT_INCREASE
    NUMBER
    Percent by which to increase the size of the next extent to be allocated
    FREELISTS
    NUMBER
    Number of process freelists allocated to this segment
    FREELIST_GROUPS
    NUMBER
    Number of freelist groups allocated to this segment
    RELATIVE_FNO
    NUMBER
    Relative file number of the segment header
    BUFFER_POOL
    VARCHAR2(7)
    Default buffer pool for the object
    This view with this another viwe can help you to identify where the object is:
    DBA_DATA_FILES
    DBA_DATA_FILES describes database files.
    Column Datatype NULL Description
    FILE_NAME
    VARCHAR2(513)
    Name of the database file
    FILE_ID
    NUMBER
    NOT NULL
    File identifier number of the database file
    TABLESPACE_NAME
    VARCHAR2(30)
    NOT NULL
    Name of the tablespace to which the file belongs
    BYTES
    NUMBER
    Size of the file in bytes
    BLOCKS
    NUMBER
    NOT NULL
    Size of the file in Oracle blocks
    STATUS
    VARCHAR2(9)
    File status: AVAILABLE or INVALID (INVALID means that the file number is not in use, for example, a file in a tablespace that was dropped)
    RELATIVE_FNO
    NUMBER
    Relative file number
    AUTOEXTENSIBLE
    VARCHAR2(3)
    Autoextensible indicator
    MAXBYTES
    NUMBER
    Maximum file size in bytes
    MAXBLOCKS
    NUMBER
    Maximum file size in blocks
    INCREMENT_BY
    NUMBER
    Autoextension increment
    USER_BYTES
    NUMBER
    Corresponding number of bytes
    USER_BLOCKS
    NUMBER
    Number of blocks which can be used by the data
    Joel Pérez
    http://otn.oracle.com/experts

  • I want to delete the last 2 sheets in a Pages document.  I select them in the thumbnails. But I can't delete them.  The 1st pages, the ones I want to keep, are the ones that are deleted.  What do I do?

    I want to delete the last 2 sheets in a Pages document.  I select them in the thumbnails, but can't delete them.
    When I choose delete, the 1st five pages are deleted.
    What do I do?

    "2) The last page, p 6,  is not in a Section.  When I delete p 6 ....pages 2 - 6 are deleted.
    Only page 1 remains."
    Every page in a Pages word processing document is "in a section". It may be the only page in its section, or it may be in the same section as several other pages. From the behaviour you are describing, I'd suspect your document has two sections: section 1 contains only Page 1, section 2 contains pages 2 to 6.
    When you click on the Page 6 icon in the sidebar to the left of the page, you'll see a yellow border around all or part of that page icon.
    If the yellow border contains only page 6, then Page 6 is in a section by itself, and pressing delete will delete only page 6.
    If the yellow border contains page 6 AND any other pages, then all of the pages within that yellow border are in the same section, and pressing delete (while the icons are selected) will delete all of the pages in that section.
    To delete only page 6 (the last page in the document) you need to either:
    Delete any text content (including invisible characters, and preferably including any other objects) on that page, following the suggestions by Peter above,
    OR
    Click immediately after the last text character on Page 5, then go Insert > Section Break to place Page 6 into a section of its own. Then click on the Page 6 icon in the sidebar, check that the yellow border encloses only page 6, and press delete.
    Regards,
    Barry
    PS: It's pretty easy to add extra pages to a document without seeing the invisible characters that cause the page to appear. Not as easy as it was in Appleworks, fortunately where the personal record for one of my Grade 5 students was a 3 page document with over 1000 extra blank pages sent to a printer. AppleWorks read the enter key as a column break (which acts like a page break on a single column document). On a keyboard with a number pad, enter is in a very convenient location to rest a book (or an arm) while thinking about your writing (or chatting with your neighbor).

Maybe you are looking for

  • Issue with webservice data control while invokin bpel process from ADF side

    Hello Experts, we are creating webservice data control to invoke bpel process from ADF side. When I run the application and inovoke the bpel every thing is working fine. But when we are changeing the instances from DEV to SIT the bpel url(hostname an

  • Macbook Pro won't eject CD

    When I press eject, it begins to eject, you see the slightest millimeter of the disc pop out, then it immediately gets pulled back in. I have tried everything (the keyboard button, dragging the desktop symbol into the trash, ejecting through disc uti

  • Creating a Single Page Peel Interactive Online Brochure

    I'm new to InDesign CS4. Could someone help me in explaining how I can create a single turning page peel interactive online book. I have the job done in InDesign using spread pages format.... and I'm looking to try and output to SWF format as single

  • Spry formatting help

    I just made a 4 item Spry menu for a website I am building. I can't seem to get it to format properly. 2 of the items have sub menus, but the pop-down portion of the sub menus isn't as wide as the main menu it pops down from. I have changed the sizes

  • FF 13 on Win7 -- history does not show

    No history showing for FF13/Win7 ... all settings under options are to allow History. But history totally blank. Bookmarks are fine.