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?

How can mimic phobia be cured?

Is aluminum electrical wire used on aircraft?

Is there a way to get `mathscr' with lower case letters in pdfLaTeX?

Unexpected behavior of the procedure `Area` on the object 'Polygon'

Non-trope happy ending?

What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?

Is there a RAID 0 Equivalent for RAM?

Creepy dinosaur pc game identification

System.QueryException unexpected token

How does a computer interpret real numbers?

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

How could a planet have erratic days?

Mixing PEX brands

How to hide some fields of struct in C?

Does malloc reserve more space while allocating memory?

How do I delete all blank lines in a buffer?

Why is this estimator biased?

Does IPv6 have similar concept of network mask?

Calculate sum of polynomial roots

On a tidally locked planet, would time be quantized?

Hero deduces identity of a killer

This is why we puzzle

Why is it that I can sometimes guess the next note?

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



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?













10















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




























    10















    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


























      10












      10








      10








      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 3 hours ago









      Cody Gray

      195k35382470




      195k35382470










      asked 3 hours ago









      thbthb

      8,67932356




      8,67932356






















          1 Answer
          1






          active

          oldest

          votes


















          17














          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









            17














            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





























              17














              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



























                17












                17








                17







                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 3 hours ago









                Sombrero Chicken

                24.4k33281




                24.4k33281










                answered 3 hours 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

                    Reverse int within the 32-bit signed integer range: [−2^31, 2^31 − 1]Combining two 32-bit integers into one 64-bit integerDetermine if an int is within rangeLossy packing 32 bit integer to 16 bitComputing the square root of a 64-bit integerKeeping integer addition within boundsSafe multiplication of two 64-bit signed integersLeetcode 10: Regular Expression MatchingSigned integer-to-ascii x86_64 assembler macroReverse the digits of an Integer“Add two numbers given in reverse order from a linked list”

                    Category:Fedor von Bock Media in category "Fedor von Bock"Navigation menuUpload mediaISNI: 0000 0000 5511 3417VIAF ID: 24712551GND ID: 119294796Library of Congress authority ID: n96068363BnF ID: 12534305fSUDOC authorities ID: 034604189Open Library ID: OL338253ANKCR AUT ID: jn19990000869National Library of Israel ID: 000514068National Thesaurus for Author Names ID: 341574317ReasonatorScholiaStatistics

                    Kiel Indholdsfortegnelse Historie | Transport og færgeforbindelser | Sejlsport og anden sport | Kultur | Kendte personer fra Kiel | Noter | Litteratur | Eksterne henvisninger | Navigationsmenuwww.kiel.de54°19′31″N 10°8′26″Ø / 54.32528°N 10.14056°Ø / 54.32528; 10.14056Oberbürgermeister Dr. Ulf Kämpferwww.statistik-nord.deDen danske Stats StatistikKiels hjemmesiderrrWorldCat312794080n790547494030481-4