This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: exception header file changes





On Thu, 8 Nov 2001, Rupert Wood wrote:

> Andrew Munro wrote:
> 
> > I notice that the exception header file has changed - the destructor
> > has an empty throw() spec.
> >
> > This is causing me problems as derived exceptions from
> > std::exception must know also provided an empty throw() spec. (the
> > compiler gives an error of "looser throw specification" for the
> > derived class.
> >
> > Is there any way around this other than by changing my code - such
> > as a compiler flag?
> 
> The C++ standard defines exception as (section 18.6.1):
> 
>         namespace std {
>           class exception {
>           public:
>             exception() throw();
>             exception(const exception&) throw();
>             exception& operator=(const exception&) throw();
>             virtual ~exception() throw();
>             virtual const char* what() const throw();
>           };
>         }
> 
> i.e. with the throw() specification, so in the long term it is probably
> better to fix your code.
> 
> In the short term, I'm afraid there is no option; see the final section
> of check_final_overrider in gcc/cp/search.c. If you're willing to hack
> your own copy of gcc then you just change 'cp_error_at' to
> 'cp_warning_at' and remove the return value, but I couldn't say if this
> will break assumptions elsewhere in the code; it may be safest to copy
> properties from base_throw to over_throw if you don't abort.

I used following hack in my code (I want be able to compile it with both
with gcc-2.95.X and gcc-3.0.X):

#if __GNUC__>=3
#define THROWS_NOTHING throw()
#else
#define THROWS_NOTHING
#endif

and I used macro THROWS_NOTHING in classes derived from std::exception	

Andris



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]