`is_trivially_destructible` does not work with an inherited class

#include <iostream>
using namespace std;


    class NoConstructOperation
    {
    protected:
        NoConstructOperation() = default;
        virtual ~NoConstructOperation() = default;
    public:
        NoConstructOperation(const NoConstructOperation&) = delete;
        NoConstructOperation& operator =(NoConstructOperation&) = delete;
        NoConstructOperation(NoConstructOperation&&) = delete;
        NoConstructOperation& operator = (NoConstructOperation&&) = delete;
    };

class Myclass:public NoConstructOperation
{

};


int main() {
    static_assert(!std::is_trivially_destructible<Myclass>::value, "Compiler provided destructor is public: Please declare it private");
    return 0;
}  

If I don't inherit Myclassfrom NoConstructOperationabove, the code gives a compilation error with a static statement.
But if I inherit Myclassusing NoConstructOperation is_trivially_destructible, the check does not work, although the constructor Myclassis publicly available. This code compiles for what reason .

+4
source share
1 answer

You define the destructor NoConstructorOperationas virtual. Removing virtualwill result in a static statement as intended: wandbox example .

From cplusplus.com :

- ( , ), :

  • .

  • .

  • ( ) .

N4567 $12.4:

, , :

(5.4) - ,

(5.5) - ,

(5.6) - , ( ), .

+9

Source: https://habr.com/ru/post/1654791/


All Articles