Skip to content

Commit 399ae0d

Browse files
committed
Replace throw() with _NOEXCEPT defined in libcxx
This deletes `_NOTHROW` defined in libcxxabi by emscripten-core#10577 and uses `_NOEXCEPT` already defined in libcxx/include/__config. This also replaces some existing `throw()`s with `_NOEXCEPT`. `_NOEXCEPT` becomes `noexcept` when it is available, i.e., this is C++11 or above, and falls back to `throw()` if not. The current libcxx/libcxxabi is a bit messy that many parts of libcxx/libcxxabi are already using this `_NOEXCEPT` but not all of them. This replaces most `throw()` with `_NOEXCEPT` but leaves some `throw()`, the ones in files that are not built at all by Emscripten or not used by wasm EH, to reduce deviations from the original library. This is mostly for wasm EH to work because wasm EH does not support exception specifications yet and does not have a short-term plan to support it, but I think this is better in general (because exception specification is deprecated already in C++11 and will be removed later) and does not change semantics for users. I'm planning to make a Clang change that ignores exception specifications for wasm for a temporary measure (Windows frontend ignores it too, so that shouldn't be a very serious problem for now). So after this PR and that Clang change, Wasm EH will use `noexcept` with C++11 or above and will ignore `throw()` in C++03 or below.
1 parent fb64aea commit 399ae0d

File tree

10 files changed

+84
-88
lines changed

10 files changed

+84
-88
lines changed

system/include/libcxx/__sso_allocator

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public:
4040
typedef _Tp* pointer;
4141
typedef _Tp value_type;
4242

43-
_LIBCPP_INLINE_VISIBILITY __sso_allocator() throw() : __allocated_(false) {}
44-
_LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator&) throw() : __allocated_(false) {}
45-
template <class _Up> _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator<_Up, _Np>&) throw()
43+
_LIBCPP_INLINE_VISIBILITY __sso_allocator() _NOEXCEPT : __allocated_(false) {}
44+
_LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator&) _NOEXCEPT : __allocated_(false) {}
45+
template <class _Up> _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator<_Up, _Np>&) _NOEXCEPT
4646
: __allocated_(false) {}
4747
private:
4848
__sso_allocator& operator=(const __sso_allocator&);
@@ -63,7 +63,7 @@ public:
6363
else
6464
_VSTD::__libcpp_deallocate(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
6565
}
66-
_LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}
66+
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT {return size_type(~0) / sizeof(_Tp);}
6767

6868
_LIBCPP_INLINE_VISIBILITY
6969
bool operator==(__sso_allocator& __a) const {return &buf_ == &__a.buf_;}

system/include/libcxx/codecvt

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ protected:
102102
virtual result
103103
do_unshift(state_type& __st,
104104
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
105-
virtual int do_encoding() const throw();
106-
virtual bool do_always_noconv() const throw();
105+
virtual int do_encoding() const _NOEXCEPT;
106+
virtual bool do_always_noconv() const _NOEXCEPT;
107107
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
108108
size_t __mx) const;
109-
virtual int do_max_length() const throw();
109+
virtual int do_max_length() const _NOEXCEPT;
110110
};
111111

112112
template <>
@@ -137,11 +137,11 @@ protected:
137137
virtual result
138138
do_unshift(state_type& __st,
139139
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
140-
virtual int do_encoding() const throw();
141-
virtual bool do_always_noconv() const throw();
140+
virtual int do_encoding() const _NOEXCEPT;
141+
virtual bool do_always_noconv() const _NOEXCEPT;
142142
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
143143
size_t __mx) const;
144-
virtual int do_max_length() const throw();
144+
virtual int do_max_length() const _NOEXCEPT;
145145
};
146146

147147
template <>
@@ -172,11 +172,11 @@ protected:
172172
virtual result
173173
do_unshift(state_type& __st,
174174
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
175-
virtual int do_encoding() const throw();
176-
virtual bool do_always_noconv() const throw();
175+
virtual int do_encoding() const _NOEXCEPT;
176+
virtual bool do_always_noconv() const _NOEXCEPT;
177177
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
178178
size_t __mx) const;
179-
virtual int do_max_length() const throw();
179+
virtual int do_max_length() const _NOEXCEPT;
180180
};
181181

182182
template <class _Elem, unsigned long _Maxcode = 0x10ffff,
@@ -225,11 +225,11 @@ protected:
225225
virtual result
226226
do_unshift(state_type& __st,
227227
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
228-
virtual int do_encoding() const throw();
229-
virtual bool do_always_noconv() const throw();
228+
virtual int do_encoding() const _NOEXCEPT;
229+
virtual bool do_always_noconv() const _NOEXCEPT;
230230
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
231231
size_t __mx) const;
232-
virtual int do_max_length() const throw();
232+
virtual int do_max_length() const _NOEXCEPT;
233233
};
234234

235235
template <>
@@ -260,11 +260,11 @@ protected:
260260
virtual result
261261
do_unshift(state_type& __st,
262262
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
263-
virtual int do_encoding() const throw();
264-
virtual bool do_always_noconv() const throw();
263+
virtual int do_encoding() const _NOEXCEPT;
264+
virtual bool do_always_noconv() const _NOEXCEPT;
265265
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
266266
size_t __mx) const;
267-
virtual int do_max_length() const throw();
267+
virtual int do_max_length() const _NOEXCEPT;
268268
};
269269

270270
template <>
@@ -295,11 +295,11 @@ protected:
295295
virtual result
296296
do_unshift(state_type& __st,
297297
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
298-
virtual int do_encoding() const throw();
299-
virtual bool do_always_noconv() const throw();
298+
virtual int do_encoding() const _NOEXCEPT;
299+
virtual bool do_always_noconv() const _NOEXCEPT;
300300
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
301301
size_t __mx) const;
302-
virtual int do_max_length() const throw();
302+
virtual int do_max_length() const _NOEXCEPT;
303303
};
304304

305305
template <>
@@ -330,11 +330,11 @@ protected:
330330
virtual result
331331
do_unshift(state_type& __st,
332332
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
333-
virtual int do_encoding() const throw();
334-
virtual bool do_always_noconv() const throw();
333+
virtual int do_encoding() const _NOEXCEPT;
334+
virtual bool do_always_noconv() const _NOEXCEPT;
335335
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
336336
size_t __mx) const;
337-
virtual int do_max_length() const throw();
337+
virtual int do_max_length() const _NOEXCEPT;
338338
};
339339

340340
template <>
@@ -365,11 +365,11 @@ protected:
365365
virtual result
366366
do_unshift(state_type& __st,
367367
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
368-
virtual int do_encoding() const throw();
369-
virtual bool do_always_noconv() const throw();
368+
virtual int do_encoding() const _NOEXCEPT;
369+
virtual bool do_always_noconv() const _NOEXCEPT;
370370
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
371371
size_t __mx) const;
372-
virtual int do_max_length() const throw();
372+
virtual int do_max_length() const _NOEXCEPT;
373373
};
374374

375375
template <>
@@ -400,11 +400,11 @@ protected:
400400
virtual result
401401
do_unshift(state_type& __st,
402402
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
403-
virtual int do_encoding() const throw();
404-
virtual bool do_always_noconv() const throw();
403+
virtual int do_encoding() const _NOEXCEPT;
404+
virtual bool do_always_noconv() const _NOEXCEPT;
405405
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
406406
size_t __mx) const;
407-
virtual int do_max_length() const throw();
407+
virtual int do_max_length() const _NOEXCEPT;
408408
};
409409

410410
template <class _Elem, unsigned long _Maxcode = 0x10ffff,
@@ -453,11 +453,11 @@ protected:
453453
virtual result
454454
do_unshift(state_type& __st,
455455
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
456-
virtual int do_encoding() const throw();
457-
virtual bool do_always_noconv() const throw();
456+
virtual int do_encoding() const _NOEXCEPT;
457+
virtual bool do_always_noconv() const _NOEXCEPT;
458458
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
459459
size_t __mx) const;
460-
virtual int do_max_length() const throw();
460+
virtual int do_max_length() const _NOEXCEPT;
461461
};
462462

463463
template <>
@@ -488,11 +488,11 @@ protected:
488488
virtual result
489489
do_unshift(state_type& __st,
490490
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
491-
virtual int do_encoding() const throw();
492-
virtual bool do_always_noconv() const throw();
491+
virtual int do_encoding() const _NOEXCEPT;
492+
virtual bool do_always_noconv() const _NOEXCEPT;
493493
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
494494
size_t __mx) const;
495-
virtual int do_max_length() const throw();
495+
virtual int do_max_length() const _NOEXCEPT;
496496
};
497497

498498
template <>
@@ -523,11 +523,11 @@ protected:
523523
virtual result
524524
do_unshift(state_type& __st,
525525
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
526-
virtual int do_encoding() const throw();
527-
virtual bool do_always_noconv() const throw();
526+
virtual int do_encoding() const _NOEXCEPT;
527+
virtual bool do_always_noconv() const _NOEXCEPT;
528528
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
529529
size_t __mx) const;
530-
virtual int do_max_length() const throw();
530+
virtual int do_max_length() const _NOEXCEPT;
531531
};
532532

533533
template <class _Elem, unsigned long _Maxcode = 0x10ffff,

system/include/libcxx/ios

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ class _LIBCPP_EXCEPTION_ABI ios_base::failure
431431
public:
432432
explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
433433
explicit failure(const char* __msg, const error_code& __ec = io_errc::stream);
434-
virtual ~failure() throw();
434+
virtual ~failure() _NOEXCEPT;
435435
};
436436

437437
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY

system/include/libcxx/memory

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,39 +2083,39 @@ private:
20832083
public:
20842084
typedef _Tp element_type;
20852085

2086-
_LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2087-
_LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2088-
template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2086+
_LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) _NOEXCEPT : __ptr_(__p) {}
2087+
_LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) _NOEXCEPT : __ptr_(__p.release()) {}
2088+
template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) _NOEXCEPT
20892089
: __ptr_(__p.release()) {}
2090-
_LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2090+
_LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) _NOEXCEPT
20912091
{reset(__p.release()); return *this;}
2092-
template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2092+
template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) _NOEXCEPT
20932093
{reset(__p.release()); return *this;}
2094-
_LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2094+
_LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) _NOEXCEPT
20952095
{reset(__p.__ptr_); return *this;}
2096-
_LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2096+
_LIBCPP_INLINE_VISIBILITY ~auto_ptr() _NOEXCEPT {delete __ptr_;}
20972097

2098-
_LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2098+
_LIBCPP_INLINE_VISIBILITY _Tp& operator*() const _NOEXCEPT
20992099
{return *__ptr_;}
2100-
_LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2101-
_LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2102-
_LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2100+
_LIBCPP_INLINE_VISIBILITY _Tp* operator->() const _NOEXCEPT {return __ptr_;}
2101+
_LIBCPP_INLINE_VISIBILITY _Tp* get() const _NOEXCEPT {return __ptr_;}
2102+
_LIBCPP_INLINE_VISIBILITY _Tp* release() _NOEXCEPT
21032103
{
21042104
_Tp* __t = __ptr_;
21052105
__ptr_ = 0;
21062106
return __t;
21072107
}
2108-
_LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2108+
_LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) _NOEXCEPT
21092109
{
21102110
if (__ptr_ != __p)
21112111
delete __ptr_;
21122112
__ptr_ = __p;
21132113
}
21142114

2115-
_LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2116-
template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2115+
_LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) _NOEXCEPT : __ptr_(__p.__ptr_) {}
2116+
template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() _NOEXCEPT
21172117
{auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2118-
template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2118+
template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() _NOEXCEPT
21192119
{return auto_ptr<_Up>(release());}
21202120
};
21212121

system/include/libcxx/regex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ class _LIBCPP_EXCEPTION_ABI regex_error
976976
regex_constants::error_type __code_;
977977
public:
978978
explicit regex_error(regex_constants::error_type __ecode);
979-
virtual ~regex_error() throw();
979+
virtual ~regex_error() _NOEXCEPT;
980980
_LIBCPP_INLINE_VISIBILITY
981981
regex_constants::error_type code() const {return __code_;}
982982
};

system/lib/libcxx/ios.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ ios_base::failure::failure(const char* msg, const error_code& ec)
8484
{
8585
}
8686

87-
ios_base::failure::~failure() throw()
87+
ios_base::failure::~failure() _NOEXCEPT
8888
{
8989
}
9090

system/lib/libcxx/regex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ regex_error::regex_error(regex_constants::error_type ecode)
6464
__code_(ecode)
6565
{}
6666

67-
regex_error::~regex_error() throw() {}
67+
regex_error::~regex_error() _NOEXCEPT {}
6868

6969
namespace {
7070

system/lib/libcxxabi/include/cxxabi.h

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,15 @@ class type_info; // forward declaration
3232
#endif
3333
}
3434

35-
// XXX EMSCRIPTEN: Wasm exception handling has not yet implemented support for
36-
// exception specification. This temporarily changes 'throw()` with 'noexcept'
37-
// to make wasm EH working in the interim.
38-
#ifdef __USING_WASM_EXCEPTIONS__
39-
#define _NOTHROW noexcept
40-
#else
41-
#define _NOTHROW throw()
42-
#endif
43-
4435
// runtime routines use C calling conventions, but are in __cxxabiv1 namespace
4536
namespace __cxxabiv1 {
4637
extern "C" {
4738

4839
// 2.4.2 Allocating the Exception Object
4940
extern _LIBCXXABI_FUNC_VIS void *
50-
__cxa_allocate_exception(size_t thrown_size) _NOTHROW;
41+
__cxa_allocate_exception(size_t thrown_size) _NOEXCEPT;
5142
extern _LIBCXXABI_FUNC_VIS void
52-
__cxa_free_exception(void *thrown_exception) _NOTHROW;
43+
__cxa_free_exception(void *thrown_exception) _NOEXCEPT;
5344

5445
// 2.4.3 Throwing the Exception Object
5546
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
@@ -62,9 +53,9 @@ __cxa_throw(void *thrown_exception, std::type_info *tinfo,
6253

6354
// 2.5.3 Exception Handlers
6455
extern _LIBCXXABI_FUNC_VIS void *
65-
__cxa_get_exception_ptr(void *exceptionObject) _NOTHROW;
56+
__cxa_get_exception_ptr(void *exceptionObject) _NOEXCEPT;
6657
extern _LIBCXXABI_FUNC_VIS void *
67-
__cxa_begin_catch(void *exceptionObject) _NOTHROW;
58+
__cxa_begin_catch(void *exceptionObject) _NOEXCEPT;
6859
extern _LIBCXXABI_FUNC_VIS void __cxa_end_catch();
6960
#if defined(_LIBCXXABI_ARM_EHABI)
7061
extern _LIBCXXABI_FUNC_VIS bool
@@ -159,17 +150,17 @@ extern _LIBCXXABI_FUNC_VIS char *__cxa_demangle(const char *mangled_name,
159150

160151
// Apple additions to support C++ 0x exception_ptr class
161152
// These are primitives to wrap a smart pointer around an exception object
162-
extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() _NOTHROW;
153+
extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() _NOEXCEPT;
163154
extern _LIBCXXABI_FUNC_VIS void
164155
__cxa_rethrow_primary_exception(void *primary_exception);
165156
extern _LIBCXXABI_FUNC_VIS void
166-
__cxa_increment_exception_refcount(void *primary_exception) _NOTHROW;
157+
__cxa_increment_exception_refcount(void *primary_exception) _NOEXCEPT;
167158
extern _LIBCXXABI_FUNC_VIS void
168-
__cxa_decrement_exception_refcount(void *primary_exception) _NOTHROW;
159+
__cxa_decrement_exception_refcount(void *primary_exception) _NOEXCEPT;
169160

170161
// Apple extension to support std::uncaught_exception()
171-
extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() _NOTHROW;
172-
extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() _NOTHROW;
162+
extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() _NOEXCEPT;
163+
extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() _NOEXCEPT;
173164

174165
#if defined(__linux__) || defined(__Fuchsia__)
175166
// Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI.

system/lib/libcxxabi/readme.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ Local modifications are marked with the comment: 'XXX EMSCRIPTEN'
1818
2. Duplicate __isOurExceptionClass in cxa_handlers.cpp since we don't compile
1919
cxa_exception.cpp in Emscripten EH mode.
2020

21-
3. Define and use _NOTHROW macro in cxxabi.h
21+
The following changes are not marked with 'XXX EMSCRIPTEN'.
22+
23+
3. Replace throw() with _NOEXCEPT macro defined in libcxx/include/__config.
24+
25+
4. Wasm exception handling support code is added and guarded by
26+
'#ifdef __USING_WASM_EXCEPTIONS__'.

0 commit comments

Comments
 (0)