my understanding is that not having any virtual method is one of requirements for standard layout. however, following code prints out true while there is a virtual method in struct Cancel.
if I remove the virtual method. is_stand_layout returns false which makes sense, as Cancel has members with different access control.
I tested this on gcc 10.2, 9.2 9.3 and clang 11.0, the results are the same.
is this a bug? or is there something I am missing about standard layout?
#include <variant>
#include <iostream>
struct NewOrder
{
int i;
};
struct Cancel
{
virtual ~Cancel() {}
int j;
private:
int i;
};
int main() {
std::cout << std::is_standard_layout_v<std::variant<NewOrder, Cancel>> << std::endl;
return 0;
}