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

Similar Messages

  • 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);
    }

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

  • I accidentally deleted part of an iphone (4s) note. Is there a way to restore the deleted text? I learned too late about being able to shake the iphone in order to undo my action, so is there any other way?

    I accidentally deleted part of an iphone (4s) note. Is there a way to restore the deleted text? I learned too late about being able to shake the iphone in order to undo my action, so is there any other way?

    Restoring a phone from a backup will put the device back to the state it was when the backup took place, i.e. all info that you had on that phone before using the backup will be gone.
    You could try to restore the phone, which will back up the actual data on the phone, including the passcode, and use this backup to set up a new phone with. The passcode will still be the same, because it is  part of the backup.
    More info here, iPhone and iPod touch: Wrong passcode results in red disabled screen
    Not being able to fill in the passcode is not much different from forgetting it.
    If you cannot remember the passcode, you will need to restore your device using the computer with which you last synced it. This allows you to reset your passcode and resync the data from the device (or restore from a backup). If you restore on a different computer that was never synced with the device, you will be able to unlock the device for use and remove the passcode, but your data will not be present. Refer to Updating and restoring iPhone, iPad and iPod touch software.
    Also have a look at this one: iTunes: About iOS backups

  • Is It Too Late to Create a Version Set?

    I have several photos that I edited and saved, but I did not save them as version sets.  Now I would like to convert each of them to a version set -- the edited photo on top of the original photo.  Is it too late to do that?
    Thanks for any suggestions.

    Sorry, I forgot to mention the details -- I'm using PSE8 on a laptop with Win7 (64bit).
    Yes, my terminology is confusing because I'm fairly new to this and not exactly sure what I'm doing.  I am following the example of an Adobe technician who led me through a process whereby I could move photos from one catalog to another.  I have 5 catalogs, two of which contain many thousands of photos each.  The other 3 catalogs are more specialized and thus smaller.  My Flower Catalog, for instance, contains a couple thousand pictures.
    This is my routine:  I download my photos into one of the larger catalogs (File>Get Photos from Card Reader).  If I have a photo of a flower in the group, I edit it and save it in a version set or stack.  Then, in order to "move" it to the Flower Catalog, I select and copy it (Ctrl+C).  Then, in Explorer, I open the Flower Catalog and paste it. Then, when I return to PSE8 and open the Flower Catalog (a watched folder), I get the message that a new photo has been found and do I want to add it to the browser. (This photo, unfortunately for me, is not the version set or stack but only the top, edited, photo.)  I add it to the browser.  The properties show that its location is now in the Flower Catalog.  Then I go back to the larger catalog and delete the flower photo from that catalog (not the hard disk).
    A convoluted system, but it works except for keeping the version set or stack intact.
    Does anyone have a better, foolproof way of moving a file from one catalog to another?  Especially a way that will keep the version set or stack together?

  • When I Googled MacKeeper, several items warned against downloading it. Too late! In order to reverse the process, I'm told I need to unencrypt anything that was encrypted. How do I unencrypt? Thanks so much.

    When I Googled the word MacKeeper, several items that appeared warned against downloading this item.  Too late!  I've already downloaded it.
    I was told that, before reversing the download, I needed to unencrypt anything that was encrypted.  How do I do this?

    Remove "MacKeeper" as follows. First, back up all data.
    "MacKeeper" has only one useful feature: it deletes itself.
    Note: These instructions apply to the version of the product that I downloaded and tested in early 2012. I can't be sure that they apply to other versions.
    IMPORTANT: "MacKeeper" has what the developer calls an “encryption” feature. In my tests, I didn't try to verify what this feature really does. If you used it to “encrypt” any of your files, “decrypt” them before you uninstall, or (preferably) restore the files from backups made before they were “encrypted.” As the developer is not trustworthy, you should assume that the "decrypted" files are corrupt unless proven otherwise.
    In the Finder, select
    Go ▹ Applications
    from the menu bar, or press the key combination shift-command-A. The "MacKeeper" application is in the folder that opens. Quit it if it's running, then drag it to the Trash. You'll be prompted for your login password. Then a dialog will pop up asking why you want to uninstall it. You don't have to provide that information. Enter anything you like in the text box, then click the Uninstall MacKeeper button. All the functional components of the software will be deleted. Reboot.
    Do not empty the Trash after dragging the MacKeeper application to it. Let the application delete itself.
    Do not try to uninstall by dragging the MacKeeper icon in the Dock or the LaunchPad to the Trash.
    Here are some general suggestions. If you want your computer to be usable, don't install crapware, such as “themes,” "haxies," “add-ons,” “toolbars,” “enhancers," “optimizers,” “accelerators,” "boosters," “extenders,” “cleaners,” "doctors," "tune-ups," “defragmenters,” “firewalls,” "barriers," “guardians,” “defenders,” “protectors,” most “plugins,” commercial "virus scanners,” "disk tools," or "utilities." With very few exceptions, this stuff is useless, or worse than useless.
    The more actively promoted the product, the more likely it is to be garbage. The most extreme example is the “MacKeeper” scam.
    The only software you should install is that which directly enables you to do the things you use a computer for — such as creating, communicating, and playing — and does not modify the way other software works. Never install any third-party software unless you know how to uninstall it.

  • Spring dependency injection too late

    I am using JavaFX 2 in conjunction with the Spring Framework, however the injection happens to late. My Controller is instanciated by the FXML-Loader, the Spring injection for member variables of this Controller works, but it works only too late, this means that in (1) injection yet didn't happen and in (2) injection did happen:
        public class MainController extends AbstractController
             @Autowired
             public StatusBarController statusbarController;
             // Implementing Initializable Interface no longer required according to
            // http://docs.oracle.com/javafx/2/fxml_get_started/whats_new2.htm:
             private void initialize() {
                BorderPane borderPane = (BorderPane)getView();       
                borderPane.setBottom(statusbarController.getView()); // (1) null exception!
             // Linked to a button in the view
            public void sayHello() {
                BorderPane borderPane = (BorderPane)getView();       
                borderPane.setBottom(statusbarController.getView()); // (2) works!
        }Any way to let Spring inject statusbarController in an earlier state? I can't let the user have to click a button to load my GUI ;-)
    My AppFactory is this:
        @Configuration
        public class AppFactory
             @Bean
             public MainController mainController() throws IOException
                  return (MainController) loadController("/main.fxml");
             protected Object loadController(String url) throws IOException
                InputStream fxmlStream = null;
                try
                    fxmlStream = getClass().getResourceAsStream(url);
                    FXMLLoader loader = new FXMLLoader();
                    Node view = (Node) loader.load(fxmlStream);
                    AbstractController controller = (AbstractController) loader.getController();
                    controller.setView(view);
                    return controller;           
                finally
                    if (fxmlStream != null)
                        fxmlStream.close();
        }Thanks for any hint!
    Edited by: srynoname on 12.02.2013 04:43

    It's a while since I used Spring, but if I remember correctly you can define a set method for injection. So you could do this:
    public class MainController extends AbstractController
             private StatusBarController statusbarController;
            @Autowired
            public void setStatusbarController(StatusBarController controller) {
               this.statusbarController = controller ;
               Platform.runLater(new Runnable() {
                 @Override public void run() {          
                    BorderPane borderPane = (BorderPane)getView();
                    if (borderPane != null) {
                      borderPane.setBottom(statusbarController.getView());
             // Implementing Initializable Interface no longer required according to
            // http://docs.oracle.com/javafx/2/fxml_get_started/whats_new2.htm:
             private void initialize() {
                BorderPane borderPane = (BorderPane)getView();
                if (statusbarController != null) { 
                  borderPane.setBottom(statusbarController.getView()); //
             // Linked to a button in the view
            public void sayHello() {
                BorderPane borderPane = (BorderPane)getView();       
                borderPane.setBottom(statusbarController.getView()); // (2) works!
        }I may not have remember Spring setter injection correctly, but it's something like that.

  • HT2417 my iphone 4s voice messages repeatedly disappear and reappear at random. When they do reappear, I cannot listen to them. Sometimes, they eventually come through but usually too late to respond

    I have an iphone 4s with Sprint. Ever since I switched from my iphone 3G with ATT, I have had incredible frustration with the voicemail system. Periodically, my voicemails on the new phone disappear; all messages old and new. This occurs out of the blue. Similarly they at times reappear, but the new messages have no content and all show up as 0.00minutes. Randomly, some messages retrieve their content and I can listen to them, often too late to respond to the caller. This is very annoying and almost questions why the voicemail exists at all. I have taken the phone to Sprint multiple times and performed countless resets with no recourse, hence they suggested contacting Apple. Has anyone else experienced this or know of a viable solution? iOS is up to date, phone only used in USA
    Thanks

    I have an iphone 4s with Sprint. Ever since I switched from my iphone 3G with ATT, I have had incredible frustration with the voicemail system. Periodically, my voicemails on the new phone disappear; all messages old and new. This occurs out of the blue. Similarly they at times reappear, but the new messages have no content and all show up as 0.00minutes. Randomly, some messages retrieve their content and I can listen to them, often too late to respond to the caller. This is very annoying and almost questions why the voicemail exists at all. I have taken the phone to Sprint multiple times and performed countless resets with no recourse, hence they suggested contacting Apple. Has anyone else experienced this or know of a viable solution? iOS is up to date, phone only used in USA
    Thanks

  • HT201272 When iTunes was upgraded to the lastest (11.0), many of of songs/music/audiobooks were deleted!  I tried syncing my phone to my computer to get them back, but many of those were deleted too!   How do I get my purchases back to play them???

    When iTunes was upgraded to the lastest (11.0), many of of songs/music/audiobooks were deleted!  I tried syncing my phone to my computer to get them back, but many of those were deleted too!   How do I get my purchases back to play them???
    It shows on iTunes SOME of my past purchases, but not all (looks like around 30-40% of purchases).    It shows on my apple id purchase history everything i have purchased; but in iTunes, some not all of these show up.    What does show up is kind of "greyed out", so NOTHING will actually play.   I have followed the steps in the iTunes support about how to redownload past purchases, but this dowsn't work, as the download button is also "greyed out". 
    I am extremly angry and upset about this issue.  Could someone please help / advise re how to fix????

    I'm hoping that this may be just a misunderstanding somewhere.
    Could you show an image showing these greyed out items?

  • When using Iphoto to import photo from existing folder, what happens if I delete the photo in Iphoto ? Will the original file in the folder be deleted too?

    When using Iphoto to import photo from existing folder to iphoto, what happens if:
    1. I delete that photo in iphoto? will the original file in the folder be deleted too ?
    2.  when importing, does the hard disk store 2 versions of the photo, hence occupying additional space in the harddisk?

    1 - no  --  iPhoto only manages fiel within the iPhoto library - it does not ever do anything with files outside the library
    2 - No idea what you are asking - by default (and strongly recommended) iPhoto copies the original to the iPhoto library and you delete the source file outside the iPhoto library - iPhoto alwasy has at least two versions of every photo and some times three - it always have the original, a thumbnail and once a photo is modified a preview - this is not optional - if it is not what you want then iPhoto is not the correct progrtam to be using for phopto management
    LN

  • Rep-1813:object r_supp_name too large to fix in matrix cell.

    hi all,
    im getting an issue while running orale report.
    i used layout model as matrix.
    im getting error as:
    rep-1813:object r_supp_name too large to fix in matrix cell.
    r_supp_name is repeating frame of supplier_name field.
    i had already set maximum number of records but still my issue not solved.
    im unable to rectify it anyone please help me.
    thanks,

    Dear,
    I am facing the same problem my question is that you resolve your issue about REP-1813 or still pending if solved kindly share with us.
    Regards,
    K.J.J.C

  • I have chosen to fil migrate from old ibook to new MacBook Pro using Time Machine after establishing admin account. I now have two admin. accounts and wish to delete the later one and transfer files manually. I am worried I will loose both accounts. ??

    I have chosen to fil migrate from old ibook to new MacBook Pro using Time Machine after establishing admin account. I now have two admin. accounts and wish to delete the later one and transfer files manually. I am worried I will loose both accounts. ??

    Use the Office for Mac and ignore using Parallels for that. If you have PC only apps you have to run that are MS Windows only then consider Parallels. Just transfer your main PC, using Migration Assistant.  If you don't know how then simply read over Pondini's article called Lion or Mountain Lion Setup Assistant tips and look for the section on migrating from a PC. Millions have done what you are about to, it's far from leading edge these days, if you go to an Apple Store to purchase they will offer this as a service, something you might be interested in.

  • Too Late for Mac OS Extended Journaled??

    Hi guys! So i got a another firewire HD, 250GB by acomdata. It's formatted under FAT 32 for both windows and mac, after after reading several posts, it's best to format it under mac os extended. the problem is I already put about 30 GB of files on it. Is it too late for me to reformat it? do i have to remove all the files, then do it? If someone can provide step by step instructions that won't harm my files, I'd greatly appreciate it. Thanks!

    You understand that if you reformat the drive for Mac OS Extended that you will no longer be able to use the drive on a PC?
    If you do reformat the drive you need to do so as follows:
    1a (If this is the startup drive.) Boot from your OS X Installer Disk. After the installer loads select Disk Utility from the Installer menu (Utilities menu if using Tiger.) Be sure to use the installer disk for the version of OS X you intend to install.
    1b (If this is a non-startup volume or external drive.) Open Disk Utility in the Utilities folder of your Applications folder.
    2. After DU loads select your hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Click on the Partition tab in the DU main window.
    3. Set the number of partitions from the dropdown menu (use 1 partition unless you wish to make more.) Set the format type to Mac OS Extended (Journaled, if supported.) Click on the Partition button and wait until the volume(s) mount on the Desktop.
    4. Select the volume you just created (this is the sub-entry under the drive entry) from the left side list. Click on the Erase tab in the DU main window.
    5. Set the format type to Mac OS Extended (Journaled, if supported.) Click on the Options button, check the button for Zero Data and click on OK to return to the Erase window.
    6. Click on the Erase button. The format process will take 30 minutes to an hour or more depending upon the drive size.

  • HT1212 okay so i entered the wrong passcode cause i forgot it for a while . i just remembered my passcode but now it is too late and it wont connect to itunes an the message on my ipod saying disabled will not go away . ):

    so i forgot my ipods password an its disabled and now i remember my password an its too late and wont connect to itunes . any suggestions on what i can do ?

    Locked Out, Forgot Lock or Restrictions Passcode, or Need to Restore Your Device: Several Alternative Solutions
    1. iOS- Forgotten passcode or device disabled after entering wrong passcode
    2. iPhone, iPad, iPod touch: Wrong passcode results in red disabled screen
    3. Restoring iPod touch after forgotten passcode
    4. What to Do If You've Forgotten Your iPhone's Passcode
    5. iOS- Understanding passcodes
    6. iTunes 10 for Mac- Update and restore software on iPod, iPhone, or iPad
    Forgotten Restrictions Passcode Help
    You will need to restore your device as New to remove a Restrictions passcode. Go through the normal process to restore your device, but when you see the options to restore as New or from a backup, be sure to choose New.
    Also, see iTunes- Restoring iOS software.

  • I am trying to watch Prof. Susskind's video lectures from Stanford univ.U-tube lec work fine.With itunes video and audio have synch problem.Is there a way to fix this or the people who uploaded messed up and it is too late?

    I am trying to watch Prof. Susskind's lectures from Stanford Univ. U-tube lectures work fine.With I-tunes, there is a synchronization problem between audio and video. Is there a way to fix this or the people who uploaded messed up and it is too late?

    I had thought this situation was solved but it just got worse. In addition to being without service for several days I am now being charged  a cancellation fee for a broadband service that BT disconnected in error. BT Vision was also terminated by BT but the set up charges are still in place. Does anyone know who the relevant Ombudsman is? I called BT from America on Friday - for an hour - while someone called Aruj sorted out why there is an order 'in progress' that I didn't initiate; why I have fees relating to a problem created by BT and why there are references to a house move that didn't take place and a BT Vision service I no longer have but didn't cancel myself. He assured me it would be rectified and my bill would be reduced by 139 pounds and we would get confirmation of this later that day. I asked him what chance there was that this would not actually happen - he said no chance at all; my new bill would be 23.50.
    There was no text message. An online chat person today told me there had been a fee reduction request which had been declined and there was nothing else he could help me with as he dealt only with broadband. But he would get BT Vision to email me. They always seem so helpful.............
    I'm sure I'm listed somewhere as 'a problem', there's no other explanation for why I get the runaround

Maybe you are looking for