Bug 83374 - [DR1813] Bad std::is_standard_layout with two base class subobjects of the same type
Summary: [DR1813] Bad std::is_standard_layout with two base class subobjects of the sa...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.3.0
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
URL:
Keywords: accepts-invalid, patch, rejects-valid
: 91064 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-12-11 16:20 UTC by Александр Михалевич
Modified: 2019-07-05 14:51 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-12-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Александр Михалевич 2017-12-11 16:20:52 UTC
Steps to reproduce:
1. Compile the following code with gcc 6.3.0 (maybe affects other versions, I was not able to check):
#include <iostream>
#include <type_traits>

struct Q {};
struct S : Q {};
struct T : Q {};
struct NonPod : S, T {};
int main(int argc, char** argv) {
        std::cout << (bool)std::is_pod<NonPod>::value << " ";
        std::cout << (bool)std::is_standard_layout<NonPod>::value << std::endl;
        return 0;
}
2. Run the result program.

Expected result:
0 0 (the NonPod structure is not a standard-layout class as described here: http://en.cppreference.com/w/cpp/concept/StandardLayoutType).

Actual result:
1 1
Comment 1 Jonathan Wakely 2017-12-11 16:36:32 UTC
G++ doesn't implement DR 1813 yet, https://wg21.link/cwg1813

struct B { int i; };        // standard-layout class
struct C : B { };           // standard-layout class
struct D : C { };           // standard-layout class
struct E : D { char : 4; }; // not a standard-layout class
static_assert( __is_standard_layout(B), "" );
static_assert( __is_standard_layout(C), "" );
static_assert( __is_standard_layout(D), "" );
static_assert( ! __is_standard_layout(E), "" );
struct Q {};
struct S : Q { };
struct T : Q { };
struct U : S, T { };         // not a standard-layout class
static_assert( ! __is_standard_layout(U), "" );
int main() { }

G++ fails the last assertion (and Clang fails the last two).
Comment 2 Martin Sebor 2019-07-03 14:05:35 UTC
*** Bug 91064 has been marked as a duplicate of this bug. ***
Comment 3 Marek Polacek 2019-07-03 14:16:44 UTC
Clang 7 and newer now implement DR 1813.  I'll take a look.
Comment 5 Marek Polacek 2019-07-05 14:46:03 UTC
Author: mpolacek
Date: Fri Jul  5 14:45:30 2019
New Revision: 273139

URL: https://gcc.gnu.org/viewcvs?rev=273139&root=gcc&view=rev
Log:
	DR 1813
	PR c++/83374 - __is_standard_layout wrong for a class with repeated bases.
	* class.c (check_bases): Set CLASSTYPE_NON_STD_LAYOUT for a class if
	CLASSTYPE_REPEATED_BASE_P is true.

	* g++.dg/ext/is_std_layout3.C: New test.
	* g++.dg/ext/is_std_layout4.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/ext/is_std_layout3.C
    trunk/gcc/testsuite/g++.dg/ext/is_std_layout4.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Marek Polacek 2019-07-05 14:49:06 UTC
Fixed for GCC 10.
Comment 7 Marek Polacek 2019-07-05 14:51:10 UTC
Related PRs:
PR91079
PR91080
PR91081