Author: sebor
Date: Tue Mar 25 17:12:57 2008
New Revision: 641091
URL: http://svn.apache.org/viewvc?rev=641091&view=rev
Log:
2008-03-25 Martin Sebor <[EMAIL PROTECTED]>
* tests/regress/18.limits.traps.stdcxx-624.cpp: Added a regression
test for STDCXX-624.
Added:
stdcxx/trunk/tests/regress/18.limits.traps.stdcxx-624.cpp (with props)
Added: stdcxx/trunk/tests/regress/18.limits.traps.stdcxx-624.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/trunk/tests/regress/18.limits.traps.stdcxx-624.cpp?rev=641091&view=auto
==============================================================================
--- stdcxx/trunk/tests/regress/18.limits.traps.stdcxx-624.cpp (added)
+++ stdcxx/trunk/tests/regress/18.limits.traps.stdcxx-624.cpp Tue Mar 25
17:12:57 2008
@@ -0,0 +1,81 @@
+/************************************************************************
+ *
+ * 18.limits.traps.stdcxx-624.cpp - regression test for STDCXX-624
+ *
+ * $Id:$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ **************************************************************************/
+
+#include <cassert> // for assert()
+#include <csignal> // for SIGFPE and signal()
+#include <cstdlib> // for strtod()
+#include <limits> // for numeric_limits
+
+
+char digits[] = " +0.?23456789e+01";
+
+volatile int result;
+
+
+extern "C" {
+
+void handle_FPE (int)
+{
+ // if we get here (presumably in response to SIGFPE triggered
+ // by a trap in integer arithmetic) verify that numeric_limits
+ // traps is non-zero and successfuly exit the process
+ assert (std::numeric_limits<int>::traps);
+
+ std::exit (0);
+}
+
+} // extern "C"
+
+
+int main ()
+{
+ // prevent clever optimizers from figuring out that (zero == 0)
+ digits [4] = '0';
+ const int zero = (int)std::strtod (digits, 0);
+
+ // compute a non-zero integer value
+ digits [4] = '1';
+ const int non_zero = (int)std::strtod (digits, 0);
+
+ // set up a handler for the FPE signal only when traps is true
+ // otherwise expect to be able to perform integer arithmetic
+ // without a signal
+ if (std::numeric_limits<int>::traps)
+ std::signal (SIGFPE, handle_FPE);
+
+ // if this traps (generates SIGFPE), verify (in the signal handler)
+ // that integer arithmetic is expected to trap
+ result = non_zero / zero;
+ result += non_zero % zero;
+
+ // if we get this far, verify that integer arithmetic is known not
+ // to trap
+ assert (!std::numeric_limits<int>::traps);
+
+ (void)&result;
+
+ return 0;
+}
Propchange: stdcxx/trunk/tests/regress/18.limits.traps.stdcxx-624.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: stdcxx/trunk/tests/regress/18.limits.traps.stdcxx-624.cpp
------------------------------------------------------------------------------
svn:keywords = Id