This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [v3] constexpr array additions


> I'll do that today, and put in a marker for this issue in the
> testsuite.

Like so.

-benjamin
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.

Index: include/std/array
===================================================================
--- include/std/array	(revision 176779)
+++ include/std/array	(working copy)
@@ -163,16 +163,21 @@
 	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];
+      const_reference
+      at(size_type __n) const
+      {
+	return __n < _Nm ?
+	       _M_instance[__n] : __throw_out_of_range(__N("array::at"));
+      }
 #endif
-      }
 
       reference 
       front()
Index: testsuite/23_containers/array/at_neg.cc
===================================================================
--- testsuite/23_containers/array/at_neg.cc	(revision 0)
+++ testsuite/23_containers/array/at_neg.cc	(revision 0)
@@ -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;
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]