diff mbox

[v3] Fix libstdc++/58815

Message ID 5267B7D1.8060209@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 23, 2013, 11:49 a.m. UTC
Hi,

for details see the audit trail. Tested x86_64-linux, committed to mainline.

Thanks,
Paolo.

//////////////////////
2013-10-23  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/58815
	* include/decimal/decimal (decimal32::operator long long(),
	decimal64::operator long long(), decimal128::operator long long()):
	Add in c++11 mode per n3407.
	* testsuite/decimal/pr58815.cc: New.

Comments

Daniel Krügler Oct. 23, 2013, 11:54 a.m. UTC | #1
2013/10/23 Paolo Carlini <paolo.carlini@oracle.com>:
> Hi,
>
> for details see the audit trail. Tested x86_64-linux, committed to mainline.

I suggest to initialize the decimal values in the new unit tests. If

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3407.html

would be applied these initializations would become
default-initializations thus leaving them uninitialized. This might
trap during the static_cast.

- Daniel
diff mbox

Patch

Index: include/decimal/decimal
===================================================================
--- include/decimal/decimal	(revision 203951)
+++ include/decimal/decimal	(working copy)
@@ -250,8 +250,11 @@ 
     /// Conforming extension: Conversion from scalar decimal type.
     decimal32(__decfloat32 __z)			: __val(__z) {}
 
-    // 3.2.2.5  Conversion to integral type. (DISABLED)
-    //operator long long() const { return (long long)__val; }
+#if __cplusplus >= 201103L
+    // 3.2.2.5  Conversion to integral type.
+    // Note: explicit per n3407.
+    explicit operator long long() const { return (long long)__val; }
+#endif
 
     // 3.2.2.6  Increment and decrement operators.
     decimal32& operator++()
@@ -333,8 +336,11 @@ 
     /// Conforming extension: Conversion from scalar decimal type.
     decimal64(__decfloat64 __z)			: __val(__z) {}
 
-    // 3.2.3.5  Conversion to integral type. (DISABLED)
-    //operator long long() const { return (long long)__val; }
+#if __cplusplus >= 201103L
+    // 3.2.3.5  Conversion to integral type.
+    // Note: explicit per n3407.
+    explicit operator long long() const { return (long long)__val; }
+#endif
 
     // 3.2.3.6  Increment and decrement operators.
     decimal64& operator++()
@@ -417,8 +423,11 @@ 
     /// Conforming extension: Conversion from scalar decimal type.
     decimal128(__decfloat128 __z)		: __val(__z) {}
 
-    // 3.2.4.5  Conversion to integral type. (DISABLED)
-    //operator long long() const { return (long long)__val; }
+#if __cplusplus >= 201103L
+    // 3.2.4.5  Conversion to integral type.
+    // Note: explicit per n3407.
+    explicit operator long long() const { return (long long)__val; }
+#endif
 
     // 3.2.4.6  Increment and decrement operators.
     decimal128& operator++()
Index: testsuite/decimal/pr58815.cc
===================================================================
--- testsuite/decimal/pr58815.cc	(revision 0)
+++ testsuite/decimal/pr58815.cc	(working copy)
@@ -0,0 +1,35 @@ 
+// { dg-options "-std=gnu++11" }
+//
+// Copyright (C) 2013 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/>.
+
+// { dg-do compile }
+// { dg-require-effective-target dfp }
+
+#include <decimal/decimal>
+
+void
+test01 ()
+{
+  std::decimal::decimal32 d32;
+  std::decimal::decimal64 d64;
+  std::decimal::decimal128 d128;
+
+  static_cast<long long>(d32);
+  static_cast<long long>(d64);
+  static_cast<long long>(d128);
+}