Why would a new[] expression ever invoke a destructor?About constructors/destructors and new/delete operators...

PTIJ: Haman's bad computer

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

Do the primes contain an infinite almost arithmetic progression?

Why Shazam when there is already Superman?

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

Mimic lecturing on blackboard, facing audience

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

How to cover method return statement in Apex Class?

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

What if you are holding an Iron Flask with a demon inside and walk into Antimagic Field?

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

What are the balance implications behind making invisible things auto-hide?

User Story breakdown - Technical Task + User Feature

Angel of Condemnation - Exile creature with second ability

Why is this estimator biased?

Calculate sum of polynomial roots

Yosemite Fire Rings - What to Expect?

When were female captains banned from Starfleet?

Why is the "ls" command showing permissions of files in a FAT32 partition?

Fear of getting stuck on one programming language / technology that is not used in my country

Pre-mixing cryogenic fuels and using only one fuel tank

Quasinilpotent , non-compact operators

Why is short-wave infrared portion of electromagnetic spectrum so sensitive to fire?

Probability that THHT occurs in a sequence of 10 coin tosses



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 1 hour 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

                    IEEEtran - How to include ORCID in TeX/PDF with PdfLatexIs there a standard way to include ORCID in TeX /...

                    Cicindela nigrior Przypisy | Menu nawigacyjneCicindela varians unicolorManual for the Identification of the...

                    Glossaries-extra: Adding glossaries package to “Clas­sicTh­e­sis” template by Dr. André Miede v. 4.6 ...