diff options
author | Jason Merrill <jason@redhat.com> | 2009-07-16 16:36:10 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2009-07-16 16:36:10 -0400 |
commit | c32097d8b4fb21997c571cf6520431fa7d06090f (patch) | |
tree | 100c59a1743caa8ea59faa87406fd5f529be94f4 /gcc/testsuite | |
parent | b3c5a40978985447d8ccf7d583929a4e8a78a91d (diff) | |
download | gcc-c32097d8b4fb21997c571cf6520431fa7d06090f.zip gcc-c32097d8b4fb21997c571cf6520431fa7d06090f.tar.gz gcc-c32097d8b4fb21997c571cf6520431fa7d06090f.tar.bz2 |
re PR libstdc++/37907 ([c++0x] support for std::is_standard_layout)
PR libstdc++/37907
Support std::is_standard_layout and std::is_trivial traits,
change POD to C++0x version (except for layout).
* gcc/c-common.c (c_common_reswords): Add __is_standard_layout
and __is_trivial.
* gcc/c-common.h (enum rid): Add RID_IS_STD_LAYOUT and RID_IS_TRIVIAL.
* gcc/cp/cp-tree.h (enum cp_trait_kind): Add CPTK_IS_STD_LAYOUT,
CPTK_IS_TRIVIAL.
(struct lang_type_class): Add non_std_layout.
(CLASSTYPE_NON_STD_LAYOUT): New.
* gcc/cp/class.c (check_bases): Set it.
(check_field_decls): Likewise.
(check_bases_and_members): Likewise.
* gcc/cp/parser.c (cp_parser_primary_expression): Handle RID_IS_STD_LAYOUT,
RID_IS_TRIVIAL.
(cp_parser_trait_expr): Likewise.
* gcc/cp/semantics.c (trait_expr_value): Handle CPTK_IS_STD_LAYOUT,
CPTK_IS_TRIVIAL.
(finish_trait_expr): Likewise.
* gcc/cp/tree.c (scalarish_type_p, trivial_type_p, std_layout_type_p): New.
(pod_type_p): Use them.
* gcc/cp/typeck.c (build_class_member_access_expr): Check
CLASSTYPE_NON_STD_LAYOUT rather than CLASSTYPE_NON_POD_P.
* libstdc++-v3/include/std/type_traits: Add is_standard_layout, is_trivial.
From-SVN: r149721
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/std-layout1.C | 91 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/trivial1.C | 82 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/has_nothrow_assign.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/has_nothrow_copy-1.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/has_trivial_assign.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/has_trivial_copy.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/is_pod.C | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/other/offsetof3.C | 7 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/overload/ellipsis1.C | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/var-args1.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.brendan/crash63.C | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.brendan/crash64.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.brendan/overload8.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.other/vaarg3.C | 13 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.pt/vaarg3.C | 4 |
16 files changed, 216 insertions, 25 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 989f577..7ab159a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,21 @@ +2009-07-16 Jason Merrill <jason@redhat.com> + + PR libstdc++/37907 + * g++.dg/cpp0x/std-layout1.C: New. + * g++.dg/ext/has_nothrow_assign.C: Fix. + * g++.dg/ext/has_nothrow_copy.C: Fix. + * g++.dg/ext/has_trivial_assign.C: Fix. + * g++.dg/ext/has_trivial_copy.C: Fix. + * g++.dg/ext/is_pod.C: Fix. + * g++.dg/other/offsetof3.C: Adjust. + * g++.dg/overload/ellipsis1.C: Adjust. + * g++.dg/warn/var-args1.C: Adjust. + * g++.old-deja/g++.brendan/crash63.C: Adjust. + * g++.old-deja/g++.brendan/crash64.C: Adjust. + * g++.old-deja/g++.brendan/overload8.C: Adjust. + * g++.old-deja/g++.other/vaarg3.C: Adjust. + * g++.old-deja/g++.pt/vaarg3.C: Adjust. + 2009-07-16 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> * gcc.dg/torture/builtin-math-5.c: Add more cases. diff --git a/gcc/testsuite/g++.dg/cpp0x/std-layout1.C b/gcc/testsuite/g++.dg/cpp0x/std-layout1.C new file mode 100644 index 0000000..bdad82111 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/std-layout1.C @@ -0,0 +1,91 @@ +// { dg-options "-std=c++0x" } + +// [basic.types]/10: +// Scalar types, standard-layout class types (Clause 9), arrays of such +// types and cv-qualified versions of these types (3.9.3) are collectively +// called standard-layout types. + +// [class]/7: +// A standard-layout class is a class that: +// * has no non-static data members of type non-standard-layout class (or +// array of such types) or reference, +// * has no virtual functions (10.3) and no virtual base classes (10.1), +// * has the same access control (Clause 11) for all non-static data members, +// * has no non-standard-layout base classes, +// * either has no non-static data members in the most-derived class and at +// most one base class with non-static data members, or has no base classes +// with non-static data members, and +// * has no base classes of the same type as the first non-static data member. + +#include <type_traits> + +#define TRY(expr) static_assert (expr, #expr) +#define YES(type) TRY(std::is_standard_layout<type>::value); \ + TRY(std::is_standard_layout<type[]>::value); \ + TRY(std::is_standard_layout<const volatile type>::value); +#define NO(type) TRY(!std::is_standard_layout<type>::value); \ + TRY(!std::is_standard_layout<type[]>::value); \ + TRY(!std::is_standard_layout<const volatile type>::value); +#define NONPOD(type) TRY(!std::is_pod<type>::value); \ + TRY(!std::is_pod<type[]>::value); \ + TRY(!std::is_pod<const volatile type>::value); + +struct A; + +YES(int); +YES(__complex int); +YES(void *); +YES(int A::*); +typedef int (A::*pmf)(); +YES(pmf); + +struct A { ~A(); }; +YES(A); +NONPOD(A); +struct F: public A { int i; }; +YES(F); +NONPOD(F); +struct G: public A { A a; }; +NO(G); +struct M { A a; }; +YES(M); + +class B +{ + int i; + __complex int c; + void *p; + double ar[4]; + int A::* pm; + int (A::*pmf)(); +}; +YES(B); +struct D: public B { }; +YES(D); +struct E: public B { int q; }; +NO(E); +struct D2: public B { }; +YES(D2); +struct I: public D, public D2 { }; +NO(I); + +struct C +{ + int i; +private: + int j; +}; +NO(C); +struct H: public C { }; +NO(H); +struct N { C c; }; +NO(N); + +struct J { virtual void f(); }; +struct J2: J { }; +NO(J); +NO(J2); +struct K { }; +struct L: virtual K {}; +YES(K); +NO(L); diff --git a/gcc/testsuite/g++.dg/cpp0x/trivial1.C b/gcc/testsuite/g++.dg/cpp0x/trivial1.C new file mode 100644 index 0000000..62173ac --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/trivial1.C @@ -0,0 +1,82 @@ +// { dg-options "-std=c++0x" } + +// [basic.types]/10: +// Scalar types, trivial class types (Clause 9), arrays of such types and +// cv-qualified versions of these types (3.9.3) are collectively called +// trivial types. + +// [class]/6: +// A trivially copyable class is a class that: +// * has no non-trivial copy constructors (12.8), +// * has no non-trivial copy assignment operators (13.5.3, 12.8), and +// * has a trivial destructor (12.4). +// A trivial class is a class that has a trivial default constructor (12.1) +// and is trivially copyable. + +#include <type_traits> + +#define TRY(expr) static_assert (expr, #expr) +#define YES(type) TRY(std::is_trivial<type>::value); \ + TRY(std::is_trivial<type[]>::value); \ + TRY(std::is_trivial<const volatile type>::value); +#define NO(type) TRY(!std::is_trivial<type>::value); \ + TRY(!std::is_trivial<type[]>::value); \ + TRY(!std::is_trivial<const volatile type>::value); + +struct A; + +YES(int); +YES(__complex int); +YES(void *); +YES(int A::*); +typedef int (A::*pmf)(); +YES(pmf); + +struct A { ~A(); }; +NO(A); +struct F: public A { int i; }; +NO(F); +struct G: public A { A a; }; +NO(G); +struct M { A a; }; +NO(M); + +class B +{ + int i; + __complex int c; + void *p; + double ar[4]; + int A::* pm; + int (A::*pmf)(); +}; +YES(B); +struct D: public B { }; +YES(D); +struct E: public B { int q; }; +YES(E); +struct D2: public B { }; +YES(D2); +struct I: public D, public D2 { }; +YES(I); + +struct C +{ + int i; +private: + int j; +}; +YES(C); +struct H: public C { }; +YES(H); +struct N { C c; }; +YES(N); + +struct J { virtual void f(); }; +struct J2: J { }; +NO(J); +NO(J2); +struct K { }; +struct L: virtual K {}; +YES(K); +NO(L); diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_assign.C b/gcc/testsuite/g++.dg/ext/has_nothrow_assign.C index 73a904e..f3b4a8b 100644 --- a/gcc/testsuite/g++.dg/ext/has_nothrow_assign.C +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_assign.C @@ -134,7 +134,7 @@ int main() assert (PTEST (A)); assert (PTEST (B)); assert (PTEST (C)); - assert (NTEST (C[])); + assert (PTEST (C[])); assert (PTEST (D)); assert (NTEST (E)); assert (NTEST (E1)); diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_copy-1.C b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-1.C index e8507cf..056c9be 100644 --- a/gcc/testsuite/g++.dg/ext/has_nothrow_copy-1.C +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-1.C @@ -124,7 +124,7 @@ int main() assert (PTEST (A)); assert (PTEST (B)); assert (PTEST (C)); - assert (NTEST (C[])); + assert (PTEST (C[])); assert (PTEST (D)); assert (NTEST (E)); assert (NTEST (E1)); diff --git a/gcc/testsuite/g++.dg/ext/has_trivial_assign.C b/gcc/testsuite/g++.dg/ext/has_trivial_assign.C index 97bcbf23..46d8c34 100644 --- a/gcc/testsuite/g++.dg/ext/has_trivial_assign.C +++ b/gcc/testsuite/g++.dg/ext/has_trivial_assign.C @@ -96,7 +96,7 @@ int main() assert (NTEST (C)); assert (NTEST (D)); assert (PTEST (E)); - assert (NTEST (E[])); + assert (PTEST (E[])); assert (PTEST (F)); assert (NTEST (G)); assert (NTEST (const A)); diff --git a/gcc/testsuite/g++.dg/ext/has_trivial_copy.C b/gcc/testsuite/g++.dg/ext/has_trivial_copy.C index ca2eeec..4b8cc15 100644 --- a/gcc/testsuite/g++.dg/ext/has_trivial_copy.C +++ b/gcc/testsuite/g++.dg/ext/has_trivial_copy.C @@ -96,7 +96,7 @@ int main() assert (NTEST (C)); assert (NTEST (D)); assert (PTEST (E)); - assert (NTEST (E[])); + assert (PTEST (E[])); assert (PTEST (F)); assert (NTEST (G)); assert (PTEST (B&)); diff --git a/gcc/testsuite/g++.dg/ext/is_pod.C b/gcc/testsuite/g++.dg/ext/is_pod.C index 5c1f0cd..c984283 100644 --- a/gcc/testsuite/g++.dg/ext/is_pod.C +++ b/gcc/testsuite/g++.dg/ext/is_pod.C @@ -68,8 +68,8 @@ int main() assert (PTEST (A)); assert (PTEST (A[])); assert (NTEST (B)); - assert (NTEST (C)); - assert (NTEST (C[])); + assert (PTEST (C)); + assert (PTEST (C[])); return 0; } diff --git a/gcc/testsuite/g++.dg/other/offsetof3.C b/gcc/testsuite/g++.dg/other/offsetof3.C index 1e83af9..5946c81 100644 --- a/gcc/testsuite/g++.dg/other/offsetof3.C +++ b/gcc/testsuite/g++.dg/other/offsetof3.C @@ -1,16 +1,17 @@ -/* Verify that offsetof warns if given a non-POD */ +/* Verify that offsetof warns if given a non-standard-layout class */ /* Copyright (C) 2003 Free Software Foundation, Inc. */ /* Contributed by Matt Austern <austern@apple.com> 15 May 2003 */ /* { dg-do compile } */ struct X { - X() : x(3), y(4) { } int x, y; +protected: + int z; }; typedef X* pX; typedef __SIZE_TYPE__ size_t; size_t yoff = size_t(&(pX(0)->y)); /* { dg-warning "invalid access" "" } */ -/* { dg-warning "macro was used incorrectly" "macro" { target *-*-* } 15 } */ +/* { dg-warning "macro was used incorrectly" "macro" { target *-*-* } 16 } */ diff --git a/gcc/testsuite/g++.dg/overload/ellipsis1.C b/gcc/testsuite/g++.dg/overload/ellipsis1.C index bdd3cd2..3dedaa6 100644 --- a/gcc/testsuite/g++.dg/overload/ellipsis1.C +++ b/gcc/testsuite/g++.dg/overload/ellipsis1.C @@ -1,9 +1,6 @@ // PR c++/15142 // Bug: We were aborting after giving a warning about passing a non-POD. -// Suppress the warning about undefined behavior. -// { dg-options "-w" } - struct B { B() throw() { } B(const B&) throw() { } @@ -17,5 +14,5 @@ struct X { struct S { S(...); }; void SillyFunc() { - throw S(X()); + throw S(X()); // { dg-error "copy" } } diff --git a/gcc/testsuite/g++.dg/warn/var-args1.C b/gcc/testsuite/g++.dg/warn/var-args1.C index aadac20..9bd84a7 100644 --- a/gcc/testsuite/g++.dg/warn/var-args1.C +++ b/gcc/testsuite/g++.dg/warn/var-args1.C @@ -6,6 +6,6 @@ void foo(int, ...) { va_list va; int i; - i = va_arg(va, int&); /* { dg-warning "cannot receive objects" } */ + i = va_arg(va, int&); /* { dg-error "cannot receive objects" } */ } diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/crash63.C b/gcc/testsuite/g++.old-deja/g++.brendan/crash63.C index 13f8339..89685fc 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/crash63.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/crash63.C @@ -4,6 +4,7 @@ class String { public: String (const char *str); + String (const String&); }; class UnitList @@ -12,4 +13,4 @@ class UnitList UnitList (...); }; -UnitList unit_list (String("keV")); // { dg-warning "" } cannot pass non-pod +UnitList unit_list (String("keV")); // { dg-error "" } cannot pass non-pod diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/crash64.C b/gcc/testsuite/g++.old-deja/g++.brendan/crash64.C index 6046cb1..3c98692 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/crash64.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/crash64.C @@ -16,4 +16,4 @@ struct metatype { int base_list; }; static _type_desc _type_metatype("metatype", sizeof(metatype), (RF_Ptr)0, 0, 1, 1, - _im_pers_mem_spec( ((size_t)&((( metatype *)0)-> base_list )) , 1)); // { dg-warning "" } cannot pass non-pod + _im_pers_mem_spec( ((size_t)&((( metatype *)0)-> base_list )) , 1)); diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/overload8.C b/gcc/testsuite/g++.old-deja/g++.brendan/overload8.C index fc1b23b..bf129b0 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/overload8.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/overload8.C @@ -6,4 +6,4 @@ class Complex{public:double re,im; void zxcvbnm(int n,...){n=1;} int main(){complex c; Complex C; zxcvbnm(1,c); -zxcvbnm(1,C);} // { dg-warning "" } cannot pass non pod +zxcvbnm(1,C);} diff --git a/gcc/testsuite/g++.old-deja/g++.other/vaarg3.C b/gcc/testsuite/g++.old-deja/g++.other/vaarg3.C index f852b08..3408a18 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/vaarg3.C +++ b/gcc/testsuite/g++.old-deja/g++.other/vaarg3.C @@ -9,14 +9,14 @@ #include <stdarg.h> struct X {int m;}; -struct Y : X {int m;}; +struct Y { Y(const Y&); }; struct Z; // { dg-error "forward decl" } void fn1(va_list args) { int i = va_arg (args, int); - Y x = va_arg (args, Y); // { dg-warning "cannot receive" } - Y y = va_arg (args, struct Y); // { dg-warning "cannot receive" } - int &r = va_arg (args, int &); // { dg-warning "cannot receive" } + Y x = va_arg (args, Y); // { dg-error "cannot receive" } + Y y = va_arg (args, struct Y); // { dg-error "cannot receive" } + int &r = va_arg (args, int &); // { dg-error "cannot receive" } Z z1 = va_arg (args, Z); // { dg-error "incomplete" } const Z &z2 = va_arg (args, Z); // { dg-error "incomplete" } @@ -25,7 +25,8 @@ void fn1(va_list args) // { dg-message "should pass" "pass" { target *-*-* } 24 } // { dg-message "abort" "abort" { target *-*-* } 24 } va_arg (args, int []); // { dg-error "array with unspecified bounds" } promote - va_arg (args, int ()); // { dg-warning "non-POD" } promote + va_arg (args, int ()); // { dg-warning "promoted" } promote + // { dg-message "abort" "abort" { target *-*-* } 28 } va_arg (args, bool); // { dg-warning "promote" "promote" } - // { dg-message "abort" "abort" { target *-*-* } 29 } + // { dg-message "abort" "abort" { target *-*-* } 30 } } diff --git a/gcc/testsuite/g++.old-deja/g++.pt/vaarg3.C b/gcc/testsuite/g++.old-deja/g++.pt/vaarg3.C index dced89d..07fb18d 100644 --- a/gcc/testsuite/g++.old-deja/g++.pt/vaarg3.C +++ b/gcc/testsuite/g++.old-deja/g++.pt/vaarg3.C @@ -14,14 +14,14 @@ void PrintArgs (Type somearg, ...) va_list argp; va_start (argp, somearg); Type value; -value = va_arg (argp, Type); // { dg-warning "non-POD" } cannot pass non-POD +value = va_arg (argp, Type); // { dg-error "cannot receive" } cannot pass non-POD va_end (argp); } int main (void) { A dummy; -PrintArgs (dummy, dummy); // { dg-warning "non-POD" } cannot pass non-POD +PrintArgs (dummy, dummy); // { dg-error "cannot pass" } cannot pass non-POD // { dg-message "instantiated" "inst" { target *-*-* } 24 } return 0; } |