Compatibility breaking changes in C++
GNU Compiler Collection (GCC) 12 and later introduce compatibility-breaking changes for C++ code that depends on condition variables not being able to throw exceptions and for code that relies on deprecated standard library class templates.
std::condition_variable::waitis now a thread cancellation point- In GCC 11 and earlier, the
std::condition_variable::waitfunction wasnoexcept, which made it incompatible with thread cancellation. As a result, if a call topthread_cancelcanceled a thread blocked instd::condition_variable::wait, the process would be terminated. In GCC 12 and later,std::condition_variable::waitcan be canceled by calls to thepthread_cancelfunction, which unwinds the stack. If you have code that depends onwaitnever throwing an exception, review the code and take appropriate action. - Deprecated class templates
-
Certain class templates have been deprecated in new versions of C++ and produce warning diagnostics in GCC 12 and later.
- The following class templates have been deprecated in C++11 and later:
std::unary_functionstd::binary_function
- The
std::iteratorclass template has been deprecated in C++17 and later.
- The following class templates have been deprecated in C++11 and later:
To prevent the warning diagnostics, you can take one of the following actions:
- When you do not want to make other changes to the code, silence the warning diagnostics by using GCC’s diagnostic pragmas. For example:
#pragma GCC diagnostic push #pragma GCC diagnostic ignored “-Wdeprecated-declarations" class Functor : public std::unary_function<int, int> { /* … */ }; #pragma GCC diagnostic pop - When you want your code to be compatible with later versions of C++, replace these class templates in the code with nested typedefs.
For example, you can replace a
std::unary_functionbase class withresult_typeandargument_typetypedefs:class Functor { using result_type = int; using argument_type = int; /* … */ };