Rodrigo Rivas | 3 Aug 2010 12:46
Picon

system_error::what

Hi all.

The std::system_error from C++0x is lacking the "what()" function.
The attached patch adds it.
Also, it looks like the testsuite works fine with it.

What do you think?

Regards
--
Rodrigo.
Index: libstdc++-v3/src/system_error.cc
===================================================================
--- libstdc++-v3/src/system_error.cc	(revision 162786)
+++ libstdc++-v3/src/system_error.cc	(working copy)
 <at>  <at>  -80,6 +80,23  <at>  <at> 

   system_error::~system_error() throw() { }

+  const char *
+  system_error::what() const throw()
+  {
+    if (_M_string.empty()) {
+      try {
+        _M_string = runtime_error::what();
+        if (!_M_string.empty())
+          _M_string += ": ";
+        _M_string += _M_code.message();
(Continue reading)

Rodrigo Rivas | 3 Aug 2010 15:27
Picon

Re: system_error::what

> Anyway, before any further details, do you have a Copyright assignment
> in place? It's a requirement for contributions more than 5-10 lines long.

No, I don't. But I am willing to to have it for all future changes if
you can point me how to do it.

> Well, I wish we can figure out a better strategy for this, because as-is it
> obviously breaks the binary compatibility with existing C++0x binaries
> already using system_error, due to the added string member.

Oh... right. You could build the error string when passing it to the
"runtime_error" constructor, then the inherited what() would just
work.
But the problem is that the contents of the string depends on the
_M_code.message(), and _M_code is not yet constructed!

Unless... we add an undocumented protected function to runtime_error
that changes the message "after" construction (hey, it may be useful
elsewhere). Something like:

class runtime_error : public exception
{
    string _M_msg;
protected:
    /* for internal use only */
    void __set_msg(const string &__msg)
    { _M_msg = __msg; }
public:
    ...
};
(Continue reading)

Rodrigo Rivas | 3 Aug 2010 18:21
Picon

Re: system_error::what

What about this? It is ready for delegation.

By the way, I copied your patches to the testsuites. But I don't
understand why there was the call to the "runtime_error::what()" in
cons-1.cc. I don't think this should be there.
Also, I added the missing constructors with "const char *". Don't know
if there was a reason of omitting them.

Regards.
--
Rodrigo.
Index: include/std/system_error
===================================================================
--- include/std/system_error	(revisión: 162786)
+++ include/std/system_error	(copia de trabajo)
 <at>  <at>  -308,30 +308,37  <at>  <at> 
   {
   private:
     error_code 	_M_code;
+    static string __make_error_string(const error_code &__ec, string __what)
+    {
+        try {
+          if (!__what.empty())
+            __what += ": ";
+          __what += __ec.message();
+        }
+        catch (...) {
+        }
(Continue reading)

Rodrigo Rivas | 4 Aug 2010 09:07
Picon

Re: system_error::what

> As a matter of fact, why going through __make_error_string?
That was to make all the string formatting in just only one place. And
maybe in the future you'll want that ": " localized too (" : " in
French, for example). Sure, with constructor delegation this will
hardly matter.

> simply apply my simpler version for this issue, while waiting for you
> Copyright assignment and therefore your future contributions.
Ok, that's fine for me. And I'm already managing my CA.

> And well, for the future, remember
> to never pass std::string by value!
Oh! I know that, it was just a too-clever way to avoid a local variable!

Regards and thank you for your comments.
--
Rodrigo.

Paolo Carlini | 8 Aug 2010 16:59
Picon
Favicon

[v3] libstdc++/44963

Hi,

tested x86_64-linux, committed to mainline and 4_5-branch.

Paolo.

///////////////////////
2010-08-08  Paolo Carlini  <paolo.carlini <at> oracle.com>

	PR libstdc++/44963
	* include/bits/stl_iterator.h (insert_iterator<>::
	operator=(const typename _Container::value_type&,
	back_insert_iterator<>::
	operator=(const typename _Container::value_type&),
	front_insert_iterator<>::
	operator=(const typename _Container::value_type&))): Add
	in C++0x mode.
	* testsuite/ext/rope/44963.cc: New.
	* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust
	dg-error line number.
Index: include/bits/stl_iterator.h
===================================================================
--- include/bits/stl_iterator.h	(revision 162994)
+++ include/bits/stl_iterator.h	(working copy)
 <at>  <at>  -416,14 +416,21  <at>  <at> 
        *  the end, if you like).  Assigning a value to the %iterator will
(Continue reading)

Paolo Carlini | 10 Aug 2010 09:22
Picon
Favicon

[v3] Fix libstdc++/45228

Hi,

tested x86_64-linux, committed to mainline. Maybe we can even better
here, but the cleanest solution I can see is adding constrains for
sizeof...(_UElements) == sizeof...(_Elements) to the converting
constructors and assignment operators of the primary template (something
that the FCD even encourages) and adding a quite short tuple
specialization for single element. That also allows to resolve the long
standing XXX fixme.

Paolo.
2010-08-10  Paolo Carlini  <paolo.carlini <at> oracle.com>

	PR libstdc++/45228
	* include/std/tuple (tuple<typename... _Elements>): Constrain
	converting constructors and assignment operators with
	sizeof...(_UElements) == sizeof...(_Elements).
	(tuple(tuple<_UElements...>&): Remove.
	(tuple<typename _T1>): Add.
	* testsuite/20_util/tuple/cons/45228.cc: New.
	* testsuite/20_util/tuple/cons/converting.cc: Likewise.
	* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust
	dg-error line number.

	* include/std/tuple (_Tuple_impl<>::_Tuple_impl(const _Tuple_impl&)):
	Defaulted.

	* include/std/tuple (tuple<typename _T1, typename _T2>
(Continue reading)

Paolo Carlini | 10 Aug 2010 12:13
Picon
Favicon

[v3] Add unique_ptr(auto_ptr<_Up>&&) + contraints

Hi,

I checked our smart pointers vs US 108 and went add adding the
unique_ptr constructor from auto_ptr which we were missing. I also added
some missing constraining to the member functions of those classes.

Tested x86_64-linux, committed to mainline.

Paolo.

/////////////////////////
2010-08-10  Paolo Carlini  <paolo.carlini <at> oracle.com>

	* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Avoid -Wall
	warnings.

	* include/bits/shared_ptr.h (shared_ptr<>::shared_ptr
	(const shared_ptr<>&), shared_ptr(shared_ptr<>&&), weak_ptr<>::
	weak_ptr(const weak_ptr<>&), weak_ptr(const shared_ptr<>&)):
	Constrain appropriately via std::is_convertible, etc.
	* include/bits/shared_ptr_base.h: Likewise.
	* include/bits/unique_ptr.h (default_delete<>::
	default_delete(const default_delete<>&),
	unique_ptr<>::unique_ptr(unique_ptr<>&&), operator=(unique_ptr<>&&)):
	Likewise.

	* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error
	line numbers.
(Continue reading)

Kostya Serebryany | 11 Aug 2010 09:31
Picon
Favicon

Re: libstdc++ and race detectors

Ping?
How do we proceed with the patch
http://codereview.appspot.com/download/issue1800042_16001.diff ?
Thanks,
--kcc

Index: tr1_impl/boost_sp_counted_base.h
===================================================================
--- tr1_impl/boost_sp_counted_base.h	(revision 162071)
+++ tr1_impl/boost_sp_counted_base.h	(working copy)
 <at>  <at>  -139,8 +139,11  <at>  <at> 
       void
       _M_release() // nothrow
       {
+        // Be race-detector-friendly. For more info see bits/c++config.
+        _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_use_count);
 	if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, -1) == 1)
 	  {
+            _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_use_count);
 	    _M_dispose();
 	    // There must be a memory barrier between dispose() and destroy()
 	    // to ensure that the effects of dispose() are observed in the
 <at>  <at>  -152,9 +155,14  <at>  <at> 
 	        _GLIBCXX_WRITE_MEM_BARRIER;
 	      }

+            // Be race-detector-friendly. For more info see bits/c++config.
+            _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count);
 	    if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count,
 						       -1) == 1)
(Continue reading)

Paolo Carlini | 11 Aug 2010 09:38
Picon
Favicon

Re: libstdc++ and race detectors

On 08/11/2010 09:31 AM, Kostya Serebryany wrote:
> Ping?
>   
I'm essentially ok with it. Can we take out those "Move to docs" bits
from the comment and put it somewhere actually in the docs, Jon? Missing
that, let's take it out and pen an enhancement PR, category
Documentation, about it.

Also, I'd like to see those 'foo', 'bar' actually replaced by something
meaningful and 'a' in the macros replaced by, say '__a' and no non-GNU
style code in the comment too (I see an open curly bracket at the end of
a line)

Thanks,
Paolo.

Paolo Carlini | 11 Aug 2010 12:21
Picon
Favicon

Re: libstdc++ and race detectors

... by the way, why are you touching only those two headers? Didn't we
agree to change consistently all the occurrences of
__exchange_and_add_dispatch(..., -1)?

Paolo.


Gmane