throw specs on Standard destructors
Benjamin Kosnik
bkoz@redhat.com
Tue Dec 10 10:44:00 GMT 2002
>#include <string>
>
>struct Base
>{
> virtual ~Base() throw() {}
>};
>
>struct Der : Base
>{
> std::string foo;
>};
>
>int main()
>{
> Der d;
>}
Ouch.
>The problem here is that the default destructor for
>Der will have a throw spec which is the union of all
>bases and members. Since std::basic_string has no
>throw spec, Der::~Der also will have none, which
>violates Base's destructor's spec.
%g++ simpson.cc
simpson.cc:9: looser throw specifier for `virtual Der::~Der()'
simpson.cc:5: overriding `virtual Base::~Base() throw ()'
simpson.cc:9: looser throw specifier for `virtual Der::~Der()'
simpson.cc:5: overriding `virtual Base::~Base() throw ()'
simpson.cc:9: looser throw specifier for `virtual Der::~Der()'
simpson.cc:5: overriding `virtual Base::~Base() throw ()'
>My local work-around was to add the empty throw spec
>to basic_string, but I'm not clear if this is an
>ABI-breaking change, or if there is some other
>subtlety here. I can't find the ABI FAQ for this.
Well, I've added it too, and then run 'make check-abi', which seem to
indicate that this is not an ABI breaking change, at least at the
exported symbol level.
15.4 - Exception specifications p12 also supports this.
As you've indicated, it would change the interface. I believe this is
explicitly allowd via
17.4.4.8 - Restrictions on exception handling p 3.
>I would assume the same should be done for auto_ptr.
Where would it stop? That part is unclear to me.
I think patches of this type are acceptable. Interested?
-benjamin
More information about the Libstdc++
mailing list