Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-26 Thread Christophe Lyon
Hi Jonathan,


On 23 September 2016 at 12:41, Jonathan Wakely  wrote:
> On 22/09/16 20:22 +0200, Christophe Lyon wrote:
>>
>> On 22 September 2016 at 15:25, Jonathan Wakely  wrote:
>>>
>>> On 22/09/16 12:15 +0100, Jonathan Wakely wrote:


 On 22/09/16 11:16 +0100, Jonathan Wakely wrote:
>
>
> (Somebody should fix PR58938 so exception_ptr is portable).



 Christophe, would you be able to test this patch?

 It uses a single global mutex for exception_ptr objects, which doesn't
 scale well but that probably isn't a problem for processors without
 lock-free atomics for single words.

 This also solves the problem of mismatched -march options, where the
 header is compiled for a CPU that supports the atomics but
 libstdc++.so was built for an older CPU that doesn't support them, and
 linking fails (as in https://gcc.gnu.org/PR58938#c13).
>>>
>>>
>>>
>>> We'd also need something like this extra piece, to ensure we don't
>>> leak exceptions. Currently __gxx_exception_cleanup assumes that if
>>> ATOMIC_INT_LOCK_FREE < 2 the referenceCount can never be greater than
>>> 1, because there are not exception_ptr objects that could increase it.
>>>
>>> If we enable exception_ptr unconditionally then that assumption
>>> doesn't hold. This patch uses the exception_ptr code to do the
>>> cleanup, under the same mutex as any other increments and decrements
>>> of the reference count.
>>>
>>> It's a bit of a hack though.
>>>
>> Should I have applied this one on top of the other?
>>
>> I ran a validation with it alone, and
>> arm-none-eabi with default mode, cpu, and fpu does not build:
>
>
> That's expected, the second patch requires the first one (you can't
> use exception_ptr unconditionally if it's only defined conditionally
> :-)
>
>
>> In file included from
>>
>> /tmp/9260164_29.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/libsupc++/eh_throw.cc:27:0:
>>
>> /tmp/9260164_29.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/libsupc++/exception_ptr.h:43:4:
>> error: #error This platform does
>> not support exception propagation.
>> #  error This platform does not support exception propagation.
>>^
>> make[4]: *** [eh_throw.lo] Error 1
>>
>>
>> In addition, on arm-none-eabi --with-mode=thumb --with-cpu=cortex-a9,
>> I've noticed a regression in c++
>>  - PASS now FAIL [PASS => FAIL]:
>>
>>  g++.dg/opt/pr36449.C  -std=gnu++11 execution test
>>  g++.dg/opt/pr36449.C  -std=gnu++14 execution test
>>  g++.dg/opt/pr36449.C  -std=gnu++98 execution test
>>
>> My logs show:
>> qemu: uncaught target signal 11 (Segmentation fault) - core dumped
>
>
> Strange, I don't see how my patch could cause that.
>

I've run validations with the 2 patches applied, and you can see the
results here:
http://people.linaro.org/~christophe.lyon/cross-validation/gcc-test-patches/240339-pr58938-v3/report-build-info.html

As you can see there are several regressions, including:
  18_support/exception_ptr/40296.cc (test for excess errors)
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc:
In function 'bool test01()':
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc:25:
error: 'exception_ptr' is not a member of 'std'
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc:25:
note: suggested alternative: 'fexcept_t'
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc:27:
error: 'p' was not declared in this scope

when compiling with -march=armv5t on arm*linux* targets.

On arm-none-eabi, I still see the regressions I reported when gcc is configured
--with-mode=thumb --with-cpu=cortex-a9
  g++.dg/opt/pr36449.C  -std=gnu++11 execution test
  g++.dg/opt/pr36449.C  -std=gnu++14 execution test
  g++.dg/opt/pr36449.C  -std=gnu++98 execution test
I have no detail besides
qemu: uncaught target signal 11 (Segmentation fault) - core dumped

Finally, on arm-none-eabi using default mode/cpu, some tests no longer
compile because:
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-eabi/gcc3/arm-none-eabi/./libstdc++-v3/src/.libs/libstdc++.a(eh_ptr.o):
In function `__gx
x_dependent_exception_cleanup':
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/libsupc++/eh_ptr.cc:241:
undefined reference to `__atomic_fetch_sub_4'
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-eabi/gcc3/arm-none-eabi/./libstdc++-v3/src/.libs/libstdc++.a(eh_ptr.o):
In function `eh_p
tr_mutex':
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/libsupc++/eh_ptr.cc:39:
undefined reference to `__sync_synchronize'
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/libsupc++/eh_ptr.cc:39:
undefined reference to `__sync_synchronize'
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/libsupc++/eh_ptr.cc:39:
undefined reference to `__sync_synchronize'

Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-23 Thread Jonathan Wakely

On 22/09/16 20:22 +0200, Christophe Lyon wrote:

On 22 September 2016 at 15:25, Jonathan Wakely  wrote:

On 22/09/16 12:15 +0100, Jonathan Wakely wrote:


On 22/09/16 11:16 +0100, Jonathan Wakely wrote:


(Somebody should fix PR58938 so exception_ptr is portable).



Christophe, would you be able to test this patch?

It uses a single global mutex for exception_ptr objects, which doesn't
scale well but that probably isn't a problem for processors without
lock-free atomics for single words.

This also solves the problem of mismatched -march options, where the
header is compiled for a CPU that supports the atomics but
libstdc++.so was built for an older CPU that doesn't support them, and
linking fails (as in https://gcc.gnu.org/PR58938#c13).



We'd also need something like this extra piece, to ensure we don't
leak exceptions. Currently __gxx_exception_cleanup assumes that if
ATOMIC_INT_LOCK_FREE < 2 the referenceCount can never be greater than
1, because there are not exception_ptr objects that could increase it.

If we enable exception_ptr unconditionally then that assumption
doesn't hold. This patch uses the exception_ptr code to do the
cleanup, under the same mutex as any other increments and decrements
of the reference count.

It's a bit of a hack though.


Should I have applied this one on top of the other?

I ran a validation with it alone, and
arm-none-eabi with default mode, cpu, and fpu does not build:


That's expected, the second patch requires the first one (you can't
use exception_ptr unconditionally if it's only defined conditionally
:-)



In file included from
/tmp/9260164_29.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/libsupc++/eh_throw.cc:27:0:
/tmp/9260164_29.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/libsupc++/exception_ptr.h:43:4:
error: #error This platform does
not support exception propagation.
#  error This platform does not support exception propagation.
   ^
make[4]: *** [eh_throw.lo] Error 1


In addition, on arm-none-eabi --with-mode=thumb --with-cpu=cortex-a9,
I've noticed a regression in c++
 - PASS now FAIL [PASS => FAIL]:

 g++.dg/opt/pr36449.C  -std=gnu++11 execution test
 g++.dg/opt/pr36449.C  -std=gnu++14 execution test
 g++.dg/opt/pr36449.C  -std=gnu++98 execution test

My logs show:
qemu: uncaught target signal 11 (Segmentation fault) - core dumped


Strange, I don't see how my patch could cause that.



The validation of the other patch is still running: I had to re-run it
because the
patch didn't apply because of the ChangeLog entry.


Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-22 Thread Christophe Lyon
On 22 September 2016 at 13:15, Jonathan Wakely  wrote:
> On 22/09/16 11:16 +0100, Jonathan Wakely wrote:
>>
>> (Somebody should fix PR58938 so exception_ptr is portable).
>
>
> Christophe, would you be able to test this patch?
>
> It uses a single global mutex for exception_ptr objects, which doesn't
> scale well but that probably isn't a problem for processors without
> lock-free atomics for single words.
>
> This also solves the problem of mismatched -march options, where the
> header is compiled for a CPU that supports the atomics but
> libstdc++.so was built for an older CPU that doesn't support them, and
> linking fails (as in https://gcc.gnu.org/PR58938#c13).
>
>
Hi Jonathan,

This is not quite right.
In most cases, it moves
18_support/exception_ptr/requirements_neg.cc  (test for errors, line 30)
to line 27 (not sure why, since you removed 1 line only)

but on older arm architectures, the tests you updated fail to compile:
  18_support/exception_ptr/40296.cc (test for excess errors)
  18_support/exception_ptr/60612-terminate.cc (test for excess errors)
  18_support/exception_ptr/60612-unexpected.cc (test for excess errors)
  18_support/exception_ptr/62258.cc (test for excess errors)
  18_support/exception_ptr/64241.cc (test for excess errors)
  18_support/exception_ptr/current_exception.cc (test for excess errors)
  18_support/exception_ptr/lifespan.cc (test for excess errors)
  18_support/exception_ptr/make_exception_ptr.cc (test for excess errors)
  18_support/exception_ptr/move.cc (test for excess errors)
  18_support/exception_ptr/requirements.cc (test for excess errors)
  18_support/exception_ptr/requirements_neg.cc  (test for errors, line 27)
  18_support/exception_ptr/requirements_neg.cc  (test for errors, line 28)
  18_support/exception_ptr/requirements_neg.cc  (test for errors, line 29)
  18_support/exception_ptr/requirements_neg.cc (test for excess errors)
  18_support/exception_ptr/rethrow_exception.cc (test for excess errors)

For instance:
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc:
In function 'bool test01()':
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc:25:
error: 'exception_ptr' is not a member of 'std'
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc:25:
note: suggested alternative: 'fexcept_t'
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc:27:
error: 'p' was not declared in this scope

/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc:
In function 'void f()':
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc:34:
error: 'rethrow_exception' is not a member of 'std'
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc:34:
note: suggested alternative: '__exception'
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc:34:
error: 'current_exception' is not a member of 'std'
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc:34:
note: suggested alternative: '_ZTISt9exception'

For more details:
http://people.linaro.org/~christophe.lyon/cross-validation/gcc-test-patches/240339-pr58938-v2/report-build-info.html

Thanks,

Christophe


Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-22 Thread Christophe Lyon
On 22 September 2016 at 15:25, Jonathan Wakely  wrote:
> On 22/09/16 12:15 +0100, Jonathan Wakely wrote:
>>
>> On 22/09/16 11:16 +0100, Jonathan Wakely wrote:
>>>
>>> (Somebody should fix PR58938 so exception_ptr is portable).
>>
>>
>> Christophe, would you be able to test this patch?
>>
>> It uses a single global mutex for exception_ptr objects, which doesn't
>> scale well but that probably isn't a problem for processors without
>> lock-free atomics for single words.
>>
>> This also solves the problem of mismatched -march options, where the
>> header is compiled for a CPU that supports the atomics but
>> libstdc++.so was built for an older CPU that doesn't support them, and
>> linking fails (as in https://gcc.gnu.org/PR58938#c13).
>
>
> We'd also need something like this extra piece, to ensure we don't
> leak exceptions. Currently __gxx_exception_cleanup assumes that if
> ATOMIC_INT_LOCK_FREE < 2 the referenceCount can never be greater than
> 1, because there are not exception_ptr objects that could increase it.
>
> If we enable exception_ptr unconditionally then that assumption
> doesn't hold. This patch uses the exception_ptr code to do the
> cleanup, under the same mutex as any other increments and decrements
> of the reference count.
>
> It's a bit of a hack though.
>
Should I have applied this one on top of the other?

I ran a validation with it alone, and
arm-none-eabi with default mode, cpu, and fpu does not build:
In file included from
/tmp/9260164_29.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/libsupc++/eh_throw.cc:27:0:
/tmp/9260164_29.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/libsupc++/exception_ptr.h:43:4:
error: #error This platform does
not support exception propagation.
 #  error This platform does not support exception propagation.
^
make[4]: *** [eh_throw.lo] Error 1


In addition, on arm-none-eabi --with-mode=thumb --with-cpu=cortex-a9,
I've noticed a regression in c++
  - PASS now FAIL [PASS => FAIL]:

  g++.dg/opt/pr36449.C  -std=gnu++11 execution test
  g++.dg/opt/pr36449.C  -std=gnu++14 execution test
  g++.dg/opt/pr36449.C  -std=gnu++98 execution test

My logs show:
qemu: uncaught target signal 11 (Segmentation fault) - core dumped

The validation of the other patch is still running: I had to re-run it
because the
patch didn't apply because of the ChangeLog entry.


Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-22 Thread Jonathan Wakely

On 22/09/16 12:15 +0100, Jonathan Wakely wrote:

On 22/09/16 11:16 +0100, Jonathan Wakely wrote:

(Somebody should fix PR58938 so exception_ptr is portable).


Christophe, would you be able to test this patch?

It uses a single global mutex for exception_ptr objects, which doesn't
scale well but that probably isn't a problem for processors without
lock-free atomics for single words.

This also solves the problem of mismatched -march options, where the
header is compiled for a CPU that supports the atomics but
libstdc++.so was built for an older CPU that doesn't support them, and
linking fails (as in https://gcc.gnu.org/PR58938#c13).


We'd also need something like this extra piece, to ensure we don't
leak exceptions. Currently __gxx_exception_cleanup assumes that if
ATOMIC_INT_LOCK_FREE < 2 the referenceCount can never be greater than
1, because there are not exception_ptr objects that could increase it.

If we enable exception_ptr unconditionally then that assumption
doesn't hold. This patch uses the exception_ptr code to do the
cleanup, under the same mutex as any other increments and decrements
of the reference count.

It's a bit of a hack though.

diff --git a/libstdc++-v3/libsupc++/Makefile.am b/libstdc++-v3/libsupc++/Makefile.am
index 2df31ff..dbfd00f 100644
--- a/libstdc++-v3/libsupc++/Makefile.am
+++ b/libstdc++-v3/libsupc++/Makefile.am
@@ -155,9 +155,9 @@ eh_terminate.o: eh_terminate.cc
 	$(CXXCOMPILE) -std=gnu++11 -c $<
 
 eh_throw.lo: eh_throw.cc
-	$(LTCXXCOMPILE) -std=gnu++11 -c $<
+	$(LTCXXCOMPILE) -std=gnu++11 -fno-access-control -c $<
 eh_throw.o: eh_throw.cc
-	$(CXXCOMPILE) -std=gnu++11 -c $<
+	$(CXXCOMPILE) -std=gnu++11 -fno-access-control -c $<
 
 guard.lo: guard.cc
 	$(LTCXXCOMPILE) -std=gnu++11 -c $<
diff --git a/libstdc++-v3/libsupc++/Makefile.in b/libstdc++-v3/libsupc++/Makefile.in
index e828ed9..f3e2193 100644
--- a/libstdc++-v3/libsupc++/Makefile.in
+++ b/libstdc++-v3/libsupc++/Makefile.in
@@ -884,9 +884,9 @@ eh_terminate.o: eh_terminate.cc
 	$(CXXCOMPILE) -std=gnu++11 -c $<
 
 eh_throw.lo: eh_throw.cc
-	$(LTCXXCOMPILE) -std=gnu++11 -c $<
+	$(LTCXXCOMPILE) -std=gnu++11 -fno-access-control -c $<
 eh_throw.o: eh_throw.cc
-	$(CXXCOMPILE) -std=gnu++11 -c $<
+	$(CXXCOMPILE) -std=gnu++11 -fno-access-control -c $<
 
 guard.lo: guard.cc
 	$(LTCXXCOMPILE) -std=gnu++11 -c $<
diff --git a/libstdc++-v3/libsupc++/eh_throw.cc b/libstdc++-v3/libsupc++/eh_throw.cc
index a05f4eb..0f61fbf 100644
--- a/libstdc++-v3/libsupc++/eh_throw.cc
+++ b/libstdc++-v3/libsupc++/eh_throw.cc
@@ -24,6 +24,7 @@
 
 #include 
 #include "unwind-cxx.h"
+#include "exception_ptr.h"
 
 using namespace __cxxabiv1;
 
@@ -42,17 +43,8 @@ __gxx_exception_cleanup (_Unwind_Reason_Code code, _Unwind_Exception *exc)
   if (code != _URC_FOREIGN_EXCEPTION_CAUGHT && code != _URC_NO_REASON)
 __terminate (header->exc.terminateHandler);
 
-#if ATOMIC_INT_LOCK_FREE > 1
-  if (__atomic_sub_fetch (>referenceCount, 1, __ATOMIC_ACQ_REL) == 0)
-{
-#endif
-  if (header->exc.exceptionDestructor)
-	header->exc.exceptionDestructor (header + 1);
-
-  __cxa_free_exception (header + 1);
-#if ATOMIC_INT_LOCK_FREE > 1
-}
-#endif
+  std::__exception_ptr::exception_ptr ptr;
+  ptr._M_exception_object = header + 1;
 }
 
 extern "C" __cxa_refcounted_exception*


Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-22 Thread Jonathan Wakely

On 22/09/16 11:16 +0100, Jonathan Wakely wrote:

(Somebody should fix PR58938 so exception_ptr is portable).


Christophe, would you be able to test this patch?

It uses a single global mutex for exception_ptr objects, which doesn't
scale well but that probably isn't a problem for processors without
lock-free atomics for single words.

This also solves the problem of mismatched -march options, where the
header is compiled for a CPU that supports the atomics but
libstdc++.so was built for an older CPU that doesn't support them, and
linking fails (as in https://gcc.gnu.org/PR58938#c13).


diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index e9bb0ce..363900a 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,26 @@
 2016-09-22  Jonathan Wakely  
 
+	PR libstdc++/58938
+	* libsupc++/eh_ptr.cc [ATOMIC_INT_LOCK_FREE < 2] (eh_ptr_mutex)
+	(exception_ptr::_M_addref, exception_ptr::_M_release): Use mutex if
+	atomic builtins not available.
+	* libsupc++/exception_ptr.h [ATOMIC_INT_LOCK_FREE < 2]: Remove #error.
+	* testsuite/18_support/exception_ptr/40296.cc: Remove
+	dg-require-atomic-builtins directive.
+	* testsuite/18_support/exception_ptr/60612-terminate.cc: Likewise.
+	* testsuite/18_support/exception_ptr/60612-unexpected.cc: Likewise.
+	* testsuite/18_support/exception_ptr/62258.cc: Likewise.
+	* testsuite/18_support/exception_ptr/64241.cc: Likewise.
+	* testsuite/18_support/exception_ptr/current_exception.cc: Likewise.
+	* testsuite/18_support/exception_ptr/lifespan.cc: Likewise.
+	* testsuite/18_support/exception_ptr/make_exception_ptr.cc: Likewise.
+	* testsuite/18_support/exception_ptr/move.cc: Likewise.
+	* testsuite/18_support/exception_ptr/requirements.cc: Likewise.
+	* testsuite/18_support/exception_ptr/requirements_neg.cc: Likewise.
+	* testsuite/18_support/exception_ptr/rethrow_exception.cc: Likewise.
+
+2016-09-22  Jonathan Wakely  
+
 	* python/libstdcxx/v6/printers.py (StdVariantPrinter): Adjust for
 	recent change to _Variant_storage.
 	* testsuite/libstdc++-prettyprinters/cxx17.cc: Test variant with
diff --git a/libstdc++-v3/libsupc++/eh_ptr.cc b/libstdc++-v3/libsupc++/eh_ptr.cc
index 3b8e0a01..ac4e375 100644
--- a/libstdc++-v3/libsupc++/eh_ptr.cc
+++ b/libstdc++-v3/libsupc++/eh_ptr.cc
@@ -25,14 +25,23 @@
 #include 
 #include 
 
-#if ATOMIC_INT_LOCK_FREE > 1
-
 #define _GLIBCXX_EH_PTR_COMPAT
 
 #include 
 #include 
 #include "unwind-cxx.h"
 
+#if ATOMIC_INT_LOCK_FREE < 2
+# include 
+# define USE_EH_PTR_MUTEX
+static inline __gnu_cxx::__mutex& eh_ptr_mutex()
+{
+static __gnu_cxx::__mutex mx;
+return mx;
+}
+using __gnu_cxx::__scoped_lock;
+#endif
+
 using namespace __cxxabiv1;
 
 // Verify assumptions about member layout in exception types
@@ -103,7 +112,12 @@ std::__exception_ptr::exception_ptr::_M_addref() _GLIBCXX_USE_NOEXCEPT
 {
   __cxa_refcounted_exception *eh =
 	__get_refcounted_exception_header_from_obj (_M_exception_object);
+#ifdef USE_EH_PTR_MUTEX
+  __scoped_lock lock(eh_ptr_mutex());
+  ++eh->referenceCount;
+#else
   __atomic_add_fetch (>referenceCount, 1, __ATOMIC_ACQ_REL);
+#endif
 }
 }
 
@@ -115,7 +129,12 @@ std::__exception_ptr::exception_ptr::_M_release() _GLIBCXX_USE_NOEXCEPT
 {
   __cxa_refcounted_exception *eh =
 	__get_refcounted_exception_header_from_obj (_M_exception_object);
+#ifdef USE_EH_PTR_MUTEX
+  auto count = (__scoped_lock(eh_ptr_mutex()), --eh->referenceCount);
+  if (count == 0)
+#else
   if (__atomic_sub_fetch (>referenceCount, 1, __ATOMIC_ACQ_REL) == 0)
+#endif
 {
 	  if (eh->exc.exceptionDestructor)
 	eh->exc.exceptionDestructor (_M_exception_object);
@@ -260,5 +279,3 @@ std::rethrow_exception(std::exception_ptr ep)
 }
 
 #undef _GLIBCXX_EH_PTR_COMPAT
-
-#endif
diff --git a/libstdc++-v3/libsupc++/exception_ptr.h b/libstdc++-v3/libsupc++/exception_ptr.h
index 21e4e8b..ae8fb1f5 100644
--- a/libstdc++-v3/libsupc++/exception_ptr.h
+++ b/libstdc++-v3/libsupc++/exception_ptr.h
@@ -39,10 +39,6 @@
 #include 
 #include 
 
-#if ATOMIC_INT_LOCK_FREE < 2
-#  error This platform does not support exception propagation.
-#endif
-
 extern "C++" {
 
 namespace std 
diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc
index 74307cc..a6659b8 100644
--- a/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc
+++ b/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc
@@ -1,5 +1,4 @@
 // { dg-do compile { target c++11 } }
-// { dg-require-atomic-builtins "" }
 
 // Copyright (C) 2009-2016 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc
index c00e287..d58f32d 100644
--- a/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc
+++ b/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc
@@ -1,5 +1,4 

Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-22 Thread Jonathan Wakely

On 22/09/16 12:41 +0300, Ville Voutilainen wrote:

On 22 September 2016 at 12:37, Christophe Lyon
 wrote:

Does the attached patch fix the problem?


Yes, thanks!


Here be the changelog. Jonathan, ok for trunk? Patch attached again
for convenience.


OK, thanks.

(Somebody should fix PR58938 so exception_ptr is portable).


Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-22 Thread Ville Voutilainen
On 22 September 2016 at 12:37, Christophe Lyon
 wrote:
>> Does the attached patch fix the problem?
>
> Yes, thanks!

Here be the changelog. Jonathan, ok for trunk? Patch attached again
for convenience.

2016-09-22  Ville Voutilainen  

Fix tests on old arm platforms for optional.
* testsuite/20_util/optional/77288.cc: Don't use exception_ptr.
diff --git a/libstdc++-v3/testsuite/20_util/optional/77288.cc b/libstdc++-v3/testsuite/20_util/optional/77288.cc
index eafafb7..0df74a9 100644
--- a/libstdc++-v3/testsuite/20_util/optional/77288.cc
+++ b/libstdc++-v3/testsuite/20_util/optional/77288.cc
@@ -18,7 +18,6 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-#include 
 #include 
 #include 
 
@@ -28,8 +27,8 @@ using std::optional;
 
 void test01()
 {
-optional nested_element;
-optional element = {};
+optional nested_element;
+optional element = {};
 nested_element = element;
 VERIFY(nested_element);
 }


Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-22 Thread Christophe Lyon
On 22 September 2016 at 11:05, Ville Voutilainen
 wrote:
> On 22 September 2016 at 11:55, Christophe Lyon
>  wrote:
>> The new test 77288.cc fails on old arm targets (armv5t):
>> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:
>> In function 'void test01()':
>> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:31:
>> error: 'exception_ptr' is not a member of 'std'
>> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:31:
>> error: template argument 1 is invalid
>> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:31:
>> error: template argument 1 is invalid
>> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:32:
>> error: 'exception_ptr' is not a member of 'std'
>> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:32:
>> error: template argument 1 is invalid
>
>
> Does the attached patch fix the problem?

Yes, thanks!

Christophe


Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-22 Thread Ville Voutilainen
On 22 September 2016 at 11:55, Christophe Lyon
 wrote:
> The new test 77288.cc fails on old arm targets (armv5t):
> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:
> In function 'void test01()':
> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:31:
> error: 'exception_ptr' is not a member of 'std'
> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:31:
> error: template argument 1 is invalid
> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:31:
> error: template argument 1 is invalid
> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:32:
> error: 'exception_ptr' is not a member of 'std'
> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:32:
> error: template argument 1 is invalid


Does the attached patch fix the problem?
diff --git a/libstdc++-v3/testsuite/20_util/optional/77288.cc b/libstdc++-v3/testsuite/20_util/optional/77288.cc
index eafafb7..0df74a9 100644
--- a/libstdc++-v3/testsuite/20_util/optional/77288.cc
+++ b/libstdc++-v3/testsuite/20_util/optional/77288.cc
@@ -18,7 +18,6 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-#include 
 #include 
 #include 
 
@@ -28,8 +27,8 @@ using std::optional;
 
 void test01()
 {
-optional nested_element;
-optional element = {};
+optional nested_element;
+optional element = {};
 nested_element = element;
 VERIFY(nested_element);
 }


Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-22 Thread Christophe Lyon
Hi,


On 21 September 2016 at 21:42, Ville Voutilainen
 wrote:
> On 21 September 2016 at 12:31, Jonathan Wakely  wrote:
>> On 06/09/16 09:00 +0300, Ville Voutilainen wrote:
>>>
>>>PR libstdc++/77288
>>>* include/std/optional (__is_optional_impl, __is_optional): Remove.
>>>(__converts_from_optional, __assigns_from_optional): New.
>>>(optional(_Up&&)): Use is_same instead of __is_optional.
>>>(optional(const optional<_Up>&)): Constrain with
>>>__converts_from_optional.
>>>(optional(optional<_Up>&&)): Likewise.
>>>(operator=(_Up&&)): Use is_same instead of __is_optional, check
>>>is_same and is_scalar.
>>>(operator=(const optional<_Up>&)): Constrain with
>>>__converts_from_optional and __assigns_from_optional.
>>>(operator=(optional<_Up>&&)): Likewise.
>>>* testsuite/20_util/optional/77288.cc: New.
>>>* testsuite/20_util/optional/cons/value.cc: Adjust.
>>
>>
>> OK for trunk, thanks.
>
> Thanks, applied - I will cook up a separate patch for making the same
> fix for experimental::optional.
> The plan is to then backport that one to the gcc-6 branch.


The new test 77288.cc fails on old arm targets (armv5t):
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:
In function 'void test01()':
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:31:
error: 'exception_ptr' is not a member of 'std'
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:31:
error: template argument 1 is invalid
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:31:
error: template argument 1 is invalid
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:32:
error: 'exception_ptr' is not a member of 'std'
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/testsuite/20_util/optional/77288.cc:32:
error: template argument 1 is invalid

Christophe


Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-21 Thread Ville Voutilainen
On 21 September 2016 at 12:31, Jonathan Wakely  wrote:
> On 06/09/16 09:00 +0300, Ville Voutilainen wrote:
>>
>>PR libstdc++/77288
>>* include/std/optional (__is_optional_impl, __is_optional): Remove.
>>(__converts_from_optional, __assigns_from_optional): New.
>>(optional(_Up&&)): Use is_same instead of __is_optional.
>>(optional(const optional<_Up>&)): Constrain with
>>__converts_from_optional.
>>(optional(optional<_Up>&&)): Likewise.
>>(operator=(_Up&&)): Use is_same instead of __is_optional, check
>>is_same and is_scalar.
>>(operator=(const optional<_Up>&)): Constrain with
>>__converts_from_optional and __assigns_from_optional.
>>(operator=(optional<_Up>&&)): Likewise.
>>* testsuite/20_util/optional/77288.cc: New.
>>* testsuite/20_util/optional/cons/value.cc: Adjust.
>
>
> OK for trunk, thanks.

Thanks, applied - I will cook up a separate patch for making the same
fix for experimental::optional.
The plan is to then backport that one to the gcc-6 branch.


Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-21 Thread Jonathan Wakely

On 06/09/16 09:00 +0300, Ville Voutilainen wrote:

   PR libstdc++/77288
   * include/std/optional (__is_optional_impl, __is_optional): Remove.
   (__converts_from_optional, __assigns_from_optional): New.
   (optional(_Up&&)): Use is_same instead of __is_optional.
   (optional(const optional<_Up>&)): Constrain with
   __converts_from_optional.
   (optional(optional<_Up>&&)): Likewise.
   (operator=(_Up&&)): Use is_same instead of __is_optional, check
   is_same and is_scalar.
   (operator=(const optional<_Up>&)): Constrain with
   __converts_from_optional and __assigns_from_optional.
   (operator=(optional<_Up>&&)): Likewise.
   * testsuite/20_util/optional/77288.cc: New.
   * testsuite/20_util/optional/cons/value.cc: Adjust.


OK for trunk, thanks.


Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-09-06 Thread Ville Voutilainen
On 23 August 2016 at 17:17, Ville Voutilainen
 wrote:
> Tested on Linux-x64.
>
> N.B. I know that the assignment operators have constraints in template
> parameters, I want to move them to the return type separately.
>
> N.B2. This fixes the bug for std::optional only; I plan to port the fix
> to std::experimental::optional in a separate patch, and then backport
> that separate fix to 6.x.
>
> N.B3. The newest p/r for LWG 2756 is not up yet in the issue list,
> and hasn't been looked at by LEWG/LWG, but neither was the previous
> one. :) Nevertheless, this new p/r and the patch are a massive
> improvement, and keeps
> existing code and expectations working, makes all sorts of interesting types
> work, and keeps the conversion functionality.


A minor addition to avoid problems with scalars.

2016-09-06  Ville Voutilainen  

PR libstdc++/77288
* include/std/optional (__is_optional_impl, __is_optional): Remove.
(__converts_from_optional, __assigns_from_optional): New.
(optional(_Up&&)): Use is_same instead of __is_optional.
(optional(const optional<_Up>&)): Constrain with
__converts_from_optional.
(optional(optional<_Up>&&)): Likewise.
(operator=(_Up&&)): Use is_same instead of __is_optional, check
is_same and is_scalar.
(operator=(const optional<_Up>&)): Constrain with
__converts_from_optional and __assigns_from_optional.
(operator=(optional<_Up>&&)): Likewise.
* testsuite/20_util/optional/77288.cc: New.
* testsuite/20_util/optional/cons/value.cc: Adjust.
diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index 2ff75ea..efb0eb6 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -423,19 +423,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
   class optional;
 
-  template
-struct __is_optional_impl : false_type
-{ };
-
-  template
-  struct __is_optional_impl> : true_type
-{ };
-
-  template
-struct __is_optional
-: public __is_optional_impl>>
-{ };
-
+  template
+using __converts_from_optional =
+  __or_&>,
+   is_constructible<_Tp, optional<_Up>&>,
+   is_constructible<_Tp, const optional<_Up>&&>,
+   is_constructible<_Tp, optional<_Up>&&>,
+   is_convertible&, _Tp>,
+   is_convertible&, _Tp>,
+   is_convertible&&, _Tp>,
+   is_convertible&&, _Tp>>;
+
+  template
+using __assigns_from_optional =
+  __or_&>,
+   is_assignable<_Tp&, optional<_Up>&>,
+   is_assignable<_Tp&, const optional<_Up>&&>,
+   is_assignable<_Tp&, optional<_Up>&&>>;
 
   /**
 * @brief Class template for optional values.
@@ -474,7 +478,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Converting constructors for engaged optionals.
   template >>,
+ __not_, decay_t<_Up>>>,
  is_constructible<_Tp, _Up&&>,
  is_convertible<_Up&&, _Tp>
  >::value, bool> = true>
@@ -483,7 +487,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template >>,
+ __not_, decay_t<_Up>>>,
  is_constructible<_Tp, _Up&&>,
  __not_>
  >::value, bool> = false>
@@ -494,7 +498,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 enable_if_t<__and_<
__not_>,
is_constructible<_Tp, const _Up&>,
-   is_convertible
+   is_convertible,
+   __not_<__converts_from_optional<_Tp, _Up>>
>::value, bool> = true>
   constexpr optional(const optional<_Up>& __t)
 : _Base(__t ? _Base(std::in_place, *__t) : _Base()) { }
@@ -503,7 +508,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  enable_if_t<__and_<
   __not_>,
   is_constructible<_Tp, const _Up&>,
-  __not_
+  __not_,
+  __not_<__converts_from_optional<_Tp, _Up>>
   >::value, bool> = false>
   explicit constexpr optional(const optional<_Up>& __t)
 : _Base(__t ? _Base(std::in_place, *__t) : _Base()) { }
@@ -512,7 +518,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 enable_if_t<__and_<
  __not_>,
  is_constructible<_Tp, _Up&&>,
- is_convertible<_Up&&, 

[v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756

2016-08-23 Thread Ville Voutilainen
Tested on Linux-x64.

N.B. I know that the assignment operators have constraints in template
parameters, I want to move them to the return type separately.

N.B2. This fixes the bug for std::optional only; I plan to port the fix
to std::experimental::optional in a separate patch, and then backport
that separate fix to 6.x.

N.B3. The newest p/r for LWG 2756 is not up yet in the issue list,
and hasn't been looked at by LEWG/LWG, but neither was the previous
one. :) Nevertheless, this new p/r and the patch are a massive
improvement, and keeps
existing code and expectations working, makes all sorts of interesting types
work, and keeps the conversion functionality.

2016-08-23  Ville Voutilainen  

PR libstdc++/77288
* include/std/optional (__is_optional_impl, __is_optional): Remove.
(__converts_from_optional, __assigns_from_optional): New.
(optional(_Up&&)): Use is_same instead of __is_optional.
(optional(const optional<_Up>&)): Constrain with
__converts_from_optional.
(optional(optional<_Up>&&)): Likewise.
(operator=(_Up&&)): Use is_same instead of __is_optional.
(operator=(const optional<_Up>&)): Constrain with
__converts_from_optional and __assigns_from_optional.
(operator=(optional<_Up>&&)): Likewise.
* testsuite/20_util/optional/77288.cc: New.
* testsuite/20_util/optional/cons/value.cc: Adjust.
diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index 2ff75ea..af716f7 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -423,19 +423,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
   class optional;
 
-  template
-struct __is_optional_impl : false_type
-{ };
-
-  template
-  struct __is_optional_impl> : true_type
-{ };
-
-  template
-struct __is_optional
-: public __is_optional_impl>>
-{ };
-
+  template
+using __converts_from_optional =
+  __or_&>,
+   is_constructible<_Tp, optional<_Up>&>,
+   is_constructible<_Tp, const optional<_Up>&&>,
+   is_constructible<_Tp, optional<_Up>&&>,
+   is_convertible&, _Tp>,
+   is_convertible&, _Tp>,
+   is_convertible&&, _Tp>,
+   is_convertible&&, _Tp>>;
+
+  template
+using __assigns_from_optional =
+  __or_&>,
+   is_assignable<_Tp&, optional<_Up>&>,
+   is_assignable<_Tp&, const optional<_Up>&&>,
+   is_assignable<_Tp&, optional<_Up>&&>>;
 
   /**
 * @brief Class template for optional values.
@@ -474,7 +478,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Converting constructors for engaged optionals.
   template >>,
+ __not_, decay_t<_Up>>>,
  is_constructible<_Tp, _Up&&>,
  is_convertible<_Up&&, _Tp>
  >::value, bool> = true>
@@ -483,7 +487,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template >>,
+ __not_, decay_t<_Up>>>,
  is_constructible<_Tp, _Up&&>,
  __not_>
  >::value, bool> = false>
@@ -494,7 +498,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 enable_if_t<__and_<
__not_>,
is_constructible<_Tp, const _Up&>,
-   is_convertible
+   is_convertible,
+   __not_<__converts_from_optional<_Tp, _Up>>
>::value, bool> = true>
   constexpr optional(const optional<_Up>& __t)
 : _Base(__t ? _Base(std::in_place, *__t) : _Base()) { }
@@ -503,7 +508,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  enable_if_t<__and_<
   __not_>,
   is_constructible<_Tp, const _Up&>,
-  __not_
+  __not_,
+  __not_<__converts_from_optional<_Tp, _Up>>
   >::value, bool> = false>
   explicit constexpr optional(const optional<_Up>& __t)
 : _Base(__t ? _Base(std::in_place, *__t) : _Base()) { }
@@ -512,7 +518,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 enable_if_t<__and_<
  __not_>,
  is_constructible<_Tp, _Up&&>,
- is_convertible<_Up&&, _Tp>
+ is_convertible<_Up&&, _Tp>,
+ __not_<__converts_from_optional<_Tp, _Up>>
  >::value, bool> = true>