array (at): Remove constexpr when -fno-exceptions.
authorBenjamin Kosnik <bkoz@redhat.com>
Tue, 26 Jul 2011 04:21:57 +0000 (04:21 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Tue, 26 Jul 2011 04:21:57 +0000 (04:21 +0000)
2011-07-25  Benjamin Kosnik  <bkoz@redhat.com>

* include/std/array (at): Remove constexpr when -fno-exceptions.
* testsuite/23_containers/array/at_neg.cc: Test.

From-SVN: r176780

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/array
libstdc++-v3/testsuite/23_containers/array/at_neg.cc [new file with mode: 0644]

index 79db713ff5b409351b55bca609568d7c4db6e664..38833b71e76c373a4e6aa3f117c25af75384b599 100644 (file)
@@ -1,3 +1,8 @@
+2011-07-25  Benjamin Kosnik  <bkoz@redhat.com>
+
+       * include/std/array (at): Remove constexpr when -fno-exceptions.
+       * testsuite/23_containers/array/at_neg.cc: Test.
+
 2011-07-25  Paolo Carlini  <paolo.carlini@oracle.com>
            Nathan Ridge  <zeratul976@hotmail.com>
 
index 0abb628aded01fbadbe8fb16a992e2477df80d59..39573bec844189c7de76b0d6c547b4c367d64475 100644 (file)
@@ -163,16 +163,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        return _M_instance[__n];
       }
 
+#ifdef __EXCEPTIONS
       constexpr const_reference
       at(size_type __n) const
       {
-       return __n < _Nm ? _M_instance[__n] : 
-#ifdef __EXCEPTIONS
-                          throw out_of_range(__N("array::at"));
+       return __n < _Nm ? 
+              _M_instance[__n] : throw out_of_range(__N("array::at"));
+      }
 #else
-                          _M_instance[0];
-#endif
+      const_reference
+      at(size_type __n) const
+      {
+       return __n < _Nm ?
+              _M_instance[__n] : __throw_out_of_range(__N("array::at"));
       }
+#endif
 
       reference 
       front()
diff --git a/libstdc++-v3/testsuite/23_containers/array/at_neg.cc b/libstdc++-v3/testsuite/23_containers/array/at_neg.cc
new file mode 100644 (file)
index 0000000..aefc39b
--- /dev/null
@@ -0,0 +1,28 @@
+// { dg-do run { xfail *-*-* } }
+// { dg-options "-std=gnu++0x -fno-exceptions" }
+
+// Copyright (C) 2011 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 Pred 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 <array>
+
+int main()
+{
+  std::array<int, 3> a{{1, 2, 3}};
+  auto i = a.at(4); // expected behavior is to either throw or abort
+  return 0;
+}