https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113158
Bug ID: 113158
Summary: Erroneous "looser exception specification" error for
class template
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: sim.f.nilsson at gmail dot com
Target Milestone: ---
The following code is not accepted by GCC 13.2.0 (among other versions):
#include <type_traits>
struct base {
virtual int f() const = 0;
};
template<typename T>
struct derived : base {
int f() const noexcept(std::is_nothrow_copy_constructible_v<T>) override
{
return sizeof(T);
}
};
int g()
{
return derived<double>{}.f();
}
I've tested versions 9 through 13 and trunk. Version 9.5 seems to be the last
version that accepts the code. The code is accepted by both Clang and MSVC. To
the best of my knowledge Clang and MSVC are correct to accept the code as
base::f is a "potentially throwing function" without the noexcept specifier.
What flags are used when compiling the code does not seem to influence the
behaviour, but for reference I've mostly used '-Wall -Wextra -O1 -std=c++17' in
comparisons.
The following compiler-explorer link also demonstrates the error:
https://compiler-explorer.com/z/1c48Yr76P
Adding 'noexcept(false)' in the base-class declaration of f, or either
'noexcept' or 'noexcept(false)' to the derived definition, makes GCC accept it.