This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[v3] constexpr comparison operator tests
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
- Date: Fri, 5 Nov 2010 20:50:18 -0700
- Subject: [v3] constexpr comparison operator tests
Add typeindex for doxyen.
This adds some test infrastructure for detecting comparison operators.
tested x86_64/linux
-benjamin
2010-11-05 Benjamin Kosnik <bkoz@redhat.com>
* doc/doxygen/user.cfg.in: Add typeindex.
* testsuite/util/testsuite_common_types.h (constexpr_comparison_eq_ne,
constexpr_comparison_operators): New.
* testsuite/20_util/duration/comparisons: Move...
* testsuite/20_util/duration/comparison_operators: ...here.
* testsuite/20_util/duration/comparison_operators/constexpr.cc: New.
* testsuite/20_util/time_point/comparison_operators/constexpr.cc: Add.
* testsuite/29_atomics/atomic_integral/cons/assign_neg.cc: Adjust line
numbers.
* testsuite/29_atomics/atomic_integral/cons/copy_neg.cc: Same.
* testsuite/29_atomics/atomic/cons/assign_neg.cc: Same.
* testsuite/29_atomics/atomic/cons/copy_neg.cc: Same.
Index: doc/doxygen/user.cfg.in
===================================================================
--- doc/doxygen/user.cfg.in (revision 166391)
+++ doc/doxygen/user.cfg.in (working copy)
@@ -631,6 +631,7 @@
include/system_error \
include/thread \
include/tuple \
+ include/typeindex \
include/type_traits \
include/unordered_map \
include/unordered_set \
Index: testsuite/29_atomics/atomic_integral/cons/assign_neg.cc
===================================================================
--- testsuite/29_atomics/atomic_integral/cons/assign_neg.cc (revision 166391)
+++ testsuite/29_atomics/atomic_integral/cons/assign_neg.cc (working copy)
@@ -29,5 +29,5 @@
return 0;
}
-// { dg-error "deleted" "" { target *-*-* } 544 }
+// { dg-error "deleted" "" { target *-*-* } 571 }
// { dg-prune-output "include" }
Index: testsuite/29_atomics/atomic_integral/cons/copy_neg.cc
===================================================================
--- testsuite/29_atomics/atomic_integral/cons/copy_neg.cc (revision 166391)
+++ testsuite/29_atomics/atomic_integral/cons/copy_neg.cc (working copy)
@@ -29,5 +29,5 @@
return 0;
}
-// { dg-error "deleted" "" { target *-*-* } 583 }
+// { dg-error "deleted" "" { target *-*-* } 610 }
// { dg-prune-output "include" }
Index: testsuite/29_atomics/atomic/cons/assign_neg.cc
===================================================================
--- testsuite/29_atomics/atomic/cons/assign_neg.cc (revision 166391)
+++ testsuite/29_atomics/atomic/cons/assign_neg.cc (working copy)
@@ -28,5 +28,5 @@
return 0;
}
-// { dg-error "deleted" "" { target *-*-* } 544 }
+// { dg-error "deleted" "" { target *-*-* } 571 }
// { dg-prune-output "include" }
Index: testsuite/29_atomics/atomic/cons/copy_neg.cc
===================================================================
--- testsuite/29_atomics/atomic/cons/copy_neg.cc (revision 166391)
+++ testsuite/29_atomics/atomic/cons/copy_neg.cc (working copy)
@@ -28,5 +28,5 @@
return 0;
}
-// { dg-error "deleted" "" { target *-*-* } 583 }
+// { dg-error "deleted" "" { target *-*-* } 610 }
// { dg-prune-output "include" }
Index: testsuite/util/testsuite_common_types.h
===================================================================
--- testsuite/util/testsuite_common_types.h (revision 166391)
+++ testsuite/util/testsuite_common_types.h (working copy)
@@ -462,8 +462,35 @@
}
};
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+
+ struct constexpr_comparison_eq_ne
+ {
+ template<typename _Tp1, typename _Tp2 = _Tp1>
+ void
+ operator()()
+ {
+ static_assert(_Tp1() == _Tp2(), "eq");
+ static_assert(!(_Tp1() != _Tp2()), "ne");
+ }
+ };
+
+ struct constexpr_comparison_operators
+ {
+ template<typename _Tp>
+ void
+ operator()()
+ {
+ static_assert(!(_Tp() < _Tp()), "less");
+ static_assert(_Tp() <= _Tp(), "leq");
+ static_assert(!(_Tp() > _Tp()), "more");
+ static_assert(_Tp() >= _Tp(), "meq");
+ static_assert(_Tp() == _Tp(), "eq");
+ static_assert(!(_Tp() != _Tp()), "ne");
+ }
+ };
+
// Generator to test standard layout
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
struct has_trivial_cons_dtor
{
template<typename _Tp>
Index: testsuite/20_util/duration/comparison_operators/constexpr.cc
===================================================================
--- testsuite/20_util/duration/comparison_operators/constexpr.cc (revision 0)
+++ testsuite/20_util/duration/comparison_operators/constexpr.cc (revision 0)
@@ -0,0 +1,29 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <chrono>
+#include <testsuite_common_types.h>
+
+int main()
+{
+ __gnu_test::constexpr_comparison_operators test;
+ test.operator()<std::chrono::nanoseconds>();
+ return 0;
+}
Index: testsuite/20_util/duration/comparisons/1.cc
===================================================================
--- testsuite/20_util/duration/comparisons/1.cc (revision 166391)
+++ testsuite/20_util/duration/comparisons/1.cc (working copy)
@@ -1,55 +0,0 @@
-// { dg-options "-std=gnu++0x" }
-// { dg-require-cstdint "" }
-
-// Copyright (C) 2008, 2009 Free Software Foundation
-//
-// This file is part of the GNU ISO C++ Library. This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 3, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING3. If not see
-// <http://www.gnu.org/licenses/>.
-
-// 20.8.3 Class template duration [time.duration]
-
-#include <chrono>
-#include <testsuite_hooks.h>
-
-// 20.8.3.6 duration comparisons [time.duration.comparisons]
-void
-test01()
-{
- bool test __attribute__((unused)) = true;
- using namespace std::chrono;
-
- duration<int> d0(12);
- duration<int> d1(3);
- duration<int> d2(3);
-
- VERIFY(d1 < d0);
- VERIFY(d0 > d1);
-
- VERIFY(d0 != d1);
- VERIFY(d1 == d2);
-
- VERIFY(d1 <= d2);
- VERIFY(d1 >= d2);
-
- VERIFY(d1 <= d0);
- VERIFY(d0 >= d1);
-}
-
-int
-main()
-{
- test01();
- return 0;
-}
Index: testsuite/20_util/time_point/comparison_operators/constexpr.cc
===================================================================
--- testsuite/20_util/time_point/comparison_operators/constexpr.cc (revision 0)
+++ testsuite/20_util/time_point/comparison_operators/constexpr.cc (revision 0)
@@ -0,0 +1,30 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <chrono>
+#include <testsuite_common_types.h>
+
+int main()
+{
+ using namespace std::chrono;
+ __gnu_test::constexpr_comparison_operators test;
+ test.operator()<time_point<system_clock>>();
+ return 0;
+}