From cc72bbaac742dd66ce5aaa9791a20903cdbac3ec Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 22 Mar 2010 16:38:57 -0400 Subject: [PATCH] re PR c++/43333 (__is_pod seems broken) PR c++/43333 * tree.c (pod_type_p): Use old meaning in C++98 mode. From-SVN: r157652 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/tree.c | 7 +++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/ext/is_pod.C | 1 + gcc/testsuite/g++.dg/ext/is_pod_98.C | 16 ++++++++++++++++ 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_pod_98.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fd08a543dd0..0e10b5bb203 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2010-03-22 Jason Merrill + PR c++/43333 + * tree.c (pod_type_p): Use old meaning in C++98 mode. + PR c++/43281 * pt.c (contains_auto_r): New fn. (do_auto_deduction): Use it. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 9867d2efb66..35b0da62ea5 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2390,7 +2390,9 @@ pod_type_p (const_tree t) argument unmodified and we assign it to a const_tree. */ t = strip_array_types (CONST_CAST_TREE(t)); - if (CLASS_TYPE_P (t)) + if (!CLASS_TYPE_P (t)) + return scalarish_type_p (t); + else if (cxx_dialect > cxx98) /* [class]/10: A POD struct is a class that is both a trivial class and a standard-layout class, and has no non-static data members of type non-POD struct, non-POD union (or array of such types). @@ -2399,7 +2401,8 @@ pod_type_p (const_tree t) non-std-layout or non-trivial, the class will be too. */ return (std_layout_type_p (t) && trivial_type_p (t)); else - return scalarish_type_p (t); + /* The C++98 definition of POD is different. */ + return !CLASSTYPE_NON_LAYOUT_POD_P (t); } /* Returns true iff T is POD for the purpose of layout, as defined in the diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 99f67470fc5..e01b7ad5a1f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2010-03-22 Jason Merrill + PR c++/43333 + * g++.dg/ext/is_pod.C: Pass -std=c++0x. + * g++.dg/ext/is_pod_98.C: New. + PR c++/43281 * g++.dg/cpp0x/auto18.C: New. diff --git a/gcc/testsuite/g++.dg/ext/is_pod.C b/gcc/testsuite/g++.dg/ext/is_pod.C index c984283a0e9..570d23565f1 100644 --- a/gcc/testsuite/g++.dg/ext/is_pod.C +++ b/gcc/testsuite/g++.dg/ext/is_pod.C @@ -1,3 +1,4 @@ +// { dg-options "-std=c++0x" } // { dg-do "run" } #include diff --git a/gcc/testsuite/g++.dg/ext/is_pod_98.C b/gcc/testsuite/g++.dg/ext/is_pod_98.C new file mode 100644 index 00000000000..80a87c825c4 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pod_98.C @@ -0,0 +1,16 @@ +// PR c++/43333 +// { dg-options "-std=c++98" } +// { dg-do run } + +struct strPOD +{ + const char *const foo; + const char *const bar; +}; +extern "C" void abort (void); +int main () +{ + if (!__is_pod (strPOD)) + abort (); + return 0; +}