Why would a new[] expression ever invoke a destructor?About constructors/destructors and new/delete operators in C++ for custom objectsDoes delete call the destructor?Overloading operator delete in a base classWhen is %destructor invoked in BISON?Why should C++ programmers minimize use of 'new'?Why is ::operator new[] necessary when ::operator new is enough?Why am I permitted to declare an object with a deleted destructor?Does delete[] deallocate memory in one shot after invoking destructors?Why are non-placement `new` and `delete` built into the language and not just regular functions?Why deallocation function is not called when object constructor throw in a new expression?

Why "had" in "[something] we would have made had we used [something]"?

Can disgust be a key component of horror?

Has any country ever had 2 former presidents in jail simultaneously?

Can a college of swords bard use blade flourish on an OA from dissonant whispers?

Temporarily disable WLAN internet access for children, but allow it for adults

How much character growth crosses the line into breaking the character

Does IPv6 have similar concept of network mask?

Why should universal income be universal?

What is the highest possible scrabble score for placing a single tile

Why did the EU agree to delay the Brexit deadline?

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

Does Doodling or Improvising on the Piano Have Any Benefits?

putting logo on same line but after title, latex

Probability that THHT occurs in a sequence of 10 coin tosses

Did arcade monitors have same pixel aspect ratio as TV sets?

Recommended PCB layout understanding - ADM2572 datasheet

Store Credit Card Information in Password Manager?

Why can Carol Danvers change her suit colours in the first place?

It grows, but water kills it

What exactly color does ozone gas have?

How can mimic phobia be cured?

How to explain what's wrong with this application of the chain rule?

Yosemite Fire Rings - What to Expect?

Calculating total slots



Why would a new[] expression ever invoke a destructor?


About constructors/destructors and new/delete operators in C++ for custom objectsDoes delete call the destructor?Overloading operator delete in a base classWhen is %destructor invoked in BISON?Why should C++ programmers minimize use of 'new'?Why is ::operator new[] necessary when ::operator new is enough?Why am I permitted to declare an object with a deleted destructor?Does delete[] deallocate memory in one shot after invoking destructors?Why are non-placement `new` and `delete` built into the language and not just regular functions?Why deallocation function is not called when object constructor throw in a new expression?













8















From the C++17 standard (draft here), [expr.new]:




If the new-expression creates an object or an array of objects of class type, access and ambiguity control are done for the allocation function, the deallocation function, and the constructor. If the new-expression creates an array of objects of class type, the destructor is potentially invoked.




Why would new[] invoke a destructor? It's new, after all. It isn't delete.










share|improve this question




























    8















    From the C++17 standard (draft here), [expr.new]:




    If the new-expression creates an object or an array of objects of class type, access and ambiguity control are done for the allocation function, the deallocation function, and the constructor. If the new-expression creates an array of objects of class type, the destructor is potentially invoked.




    Why would new[] invoke a destructor? It's new, after all. It isn't delete.










    share|improve this question


























      8












      8








      8








      From the C++17 standard (draft here), [expr.new]:




      If the new-expression creates an object or an array of objects of class type, access and ambiguity control are done for the allocation function, the deallocation function, and the constructor. If the new-expression creates an array of objects of class type, the destructor is potentially invoked.




      Why would new[] invoke a destructor? It's new, after all. It isn't delete.










      share|improve this question
















      From the C++17 standard (draft here), [expr.new]:




      If the new-expression creates an object or an array of objects of class type, access and ambiguity control are done for the allocation function, the deallocation function, and the constructor. If the new-expression creates an array of objects of class type, the destructor is potentially invoked.




      Why would new[] invoke a destructor? It's new, after all. It isn't delete.







      c++ c++17 new-operator






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago









      Cody Gray

      195k35382470




      195k35382470










      asked 2 hours ago









      thbthb

      8,66932355




      8,66932355






















          1 Answer
          1






          active

          oldest

          votes


















          14














          If construction of any object in the buffer throws an exception, the previously constructed objects must be destructed. That requires an available destructor.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55307381%2fwhy-would-a-new-expression-ever-invoke-a-destructor%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            14














            If construction of any object in the buffer throws an exception, the previously constructed objects must be destructed. That requires an available destructor.






            share|improve this answer





























              14














              If construction of any object in the buffer throws an exception, the previously constructed objects must be destructed. That requires an available destructor.






              share|improve this answer



























                14












                14








                14







                If construction of any object in the buffer throws an exception, the previously constructed objects must be destructed. That requires an available destructor.






                share|improve this answer















                If construction of any object in the buffer throws an exception, the previously constructed objects must be destructed. That requires an available destructor.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 1 hour ago









                Sombrero Chicken

                24.4k33281




                24.4k33281










                answered 1 hour ago









                StoryTellerStoryTeller

                103k12215280




                103k12215280





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55307381%2fwhy-would-a-new-expression-ever-invoke-a-destructor%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

                    How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2

                    Nissan Patrol Зміст Перше покоління — 4W60 (1951-1960) | Друге покоління — 60 series (1960-1980) | Третє покоління (1980–2002) | Четверте покоління — Y60 (1987–1998) | П'яте покоління — Y61 (1997–2013) | Шосте покоління — Y62 (2010- ) | Посилання | Зноски | Навігаційне менюОфіційний український сайтТест-драйв Nissan Patrol 2010 7-го поколінняNissan PatrolКак мы тестировали Nissan Patrol 2016рвиправивши або дописавши її