2008-03-30  Martin Sebor  <sebor@roguewave.com>

	Merged rev 641091 from trunk.
	* tests/regress/18.limits.traps.stdcxx-624.cpp: Added a regression
	test for STDCXX-624.


git-svn-id: https://svn.apache.org/repos/asf/stdcxx/branches/4.2.x@642845 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tests/regress/18.limits.traps.stdcxx-624.cpp b/tests/regress/18.limits.traps.stdcxx-624.cpp
new file mode 100644
index 0000000..0c06c17
--- /dev/null
+++ b/tests/regress/18.limits.traps.stdcxx-624.cpp
@@ -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;
+}