diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-04-05 18:55:37 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-04-05 18:55:37 +0000 |
commit | 8f900c27469fcefbffb044a1d2e23c1db92650be (patch) | |
tree | 20bcd7effaccf440fab5ef9e0c251a02342e1d41 /clang/test/CXX | |
parent | d8928a44ffb0b9cae1cfd5215b59b1687b5d7de1 (diff) |
DR1672, DR1813, DR1881, DR2120: Implement recent fixes to "standard
layout" rules.
The new rules say that a standard-layout struct has its first non-static
data member and all base classes at offset 0, and consider a class to
not be standard-layout if that would result in multiple subobjects of a
single type having the same address.
We track "is C++11 standard-layout class" separately from "is
standard-layout class" so that the ABIs that need this information can
still use it.
Differential Revision: https://reviews.llvm.org/D45176
Diffstat (limited to 'clang/test/CXX')
-rw-r--r-- | clang/test/CXX/drs/dr14xx.cpp | 2 | ||||
-rw-r--r-- | clang/test/CXX/drs/dr16xx.cpp | 30 | ||||
-rw-r--r-- | clang/test/CXX/drs/dr18xx.cpp | 37 | ||||
-rw-r--r-- | clang/test/CXX/drs/dr21xx.cpp | 16 | ||||
-rw-r--r-- | clang/test/CXX/drs/dr22xx.cpp | 2 |
5 files changed, 85 insertions, 2 deletions
diff --git a/clang/test/CXX/drs/dr14xx.cpp b/clang/test/CXX/drs/dr14xx.cpp index 116437b1ab3..eb5ba3db448 100644 --- a/clang/test/CXX/drs/dr14xx.cpp +++ b/clang/test/CXX/drs/dr14xx.cpp @@ -7,6 +7,8 @@ // expected-no-diagnostics #endif +// dr1425: na abi + namespace dr1460 { // dr1460: 3.5 #if __cplusplus >= 201103L namespace DRExample { diff --git a/clang/test/CXX/drs/dr16xx.cpp b/clang/test/CXX/drs/dr16xx.cpp index 08ae92570ce..898672ab807 100644 --- a/clang/test/CXX/drs/dr16xx.cpp +++ b/clang/test/CXX/drs/dr16xx.cpp @@ -3,6 +3,11 @@ // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors // RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors +#if __cplusplus < 201103L +// expected-error@+1 {{variadic macro}} +#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__) +#endif + namespace dr1611 { // dr1611: dup 1658 struct A { A(int); }; struct B : virtual A { virtual void f() = 0; }; @@ -219,3 +224,28 @@ namespace dr1658 { // dr1658: 5 // assignment case is superseded by dr2180 } + +namespace dr1672 { // dr1672: 7 + struct Empty {}; + struct A : Empty {}; + struct B { Empty e; }; + struct C : A { B b; int n; }; + struct D : A { int n; B b; }; + + static_assert(!__is_standard_layout(C), ""); + static_assert(__is_standard_layout(D), ""); + + struct E { B b; int n; }; + struct F { int n; B b; }; + union G { B b; int n; }; + union H { int n; B b; }; + + struct X {}; + template<typename T> struct Y : X, A { T t; }; + + static_assert(!__is_standard_layout(Y<E>), ""); + static_assert(__is_standard_layout(Y<F>), ""); + static_assert(!__is_standard_layout(Y<G>), ""); + static_assert(!__is_standard_layout(Y<H>), ""); + static_assert(!__is_standard_layout(Y<X>), ""); +} diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp index e4ec199fcae..a0f470ed4a2 100644 --- a/clang/test/CXX/drs/dr18xx.cpp +++ b/clang/test/CXX/drs/dr18xx.cpp @@ -4,9 +4,44 @@ // RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors #if __cplusplus < 201103L -// expected-no-diagnostics +// expected-error@+1 {{variadic macro}} +#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__) #endif +namespace dr1813 { // dr1813: 7 + struct B { int i; }; + struct C : B {}; + struct D : C {}; + struct E : D { char : 4; }; + + 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 {}; + + static_assert(__is_standard_layout(Q), ""); + static_assert(__is_standard_layout(S), ""); + static_assert(__is_standard_layout(T), ""); + static_assert(!__is_standard_layout(U), ""); +} + +namespace dr1881 { // dr1881: 7 + struct A { int a : 4; }; + struct B : A { int b : 3; }; + static_assert(__is_standard_layout(A), ""); + static_assert(!__is_standard_layout(B), ""); + + struct C { int : 0; }; + struct D : C { int : 0; }; + static_assert(__is_standard_layout(C), ""); + static_assert(!__is_standard_layout(D), ""); +} + void dr1891() { // dr1891: 4 #if __cplusplus >= 201103L int n; diff --git a/clang/test/CXX/drs/dr21xx.cpp b/clang/test/CXX/drs/dr21xx.cpp index 78fc0bec40b..2522ff7dbde 100644 --- a/clang/test/CXX/drs/dr21xx.cpp +++ b/clang/test/CXX/drs/dr21xx.cpp @@ -3,6 +3,22 @@ // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors // RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors +#if __cplusplus < 201103L +// expected-error@+1 {{variadic macro}} +#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__) +#endif + +namespace dr2120 { // dr2120: 7 + struct A {}; + struct B : A {}; + struct C { A a; }; + struct D { C c[5]; }; + struct E : B { D d; }; + static_assert(__is_standard_layout(B), ""); + static_assert(__is_standard_layout(D), ""); + static_assert(!__is_standard_layout(E), ""); +} + namespace dr2180 { // dr2180: yes class A { A &operator=(const A &); // expected-note 0-2{{here}} diff --git a/clang/test/CXX/drs/dr22xx.cpp b/clang/test/CXX/drs/dr22xx.cpp index 55b3d782077..021707d876b 100644 --- a/clang/test/CXX/drs/dr22xx.cpp +++ b/clang/test/CXX/drs/dr22xx.cpp @@ -3,7 +3,7 @@ // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors // RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -namespace dr2229 { // dr2229: yes +namespace dr2229 { // dr2229: 7 struct AnonBitfieldQualifiers { const unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}} volatile unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}} |