https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102262
Bug ID: 102262
Summary: No reason given for constexpr function that uses
non-constexpr destructor
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
template<typename T>
struct foo
{
constexpr foo() { }
~foo() { }
};
template<typename T>
constexpr bool check()
{
T t;
return true;
}
static_assert( check<foo<int>>() );
The error doesn't tell you what's wrong:
ce.C:15:31: error: non-constant condition for static assertion
15 | static_assert( check<foo<int>>() );
| ~~~~~~~~~~~~~~~^~
ce.C:15:31: error: 'constexpr bool check() [with T = foo<int>]' called in a
constant expression
ce.C:9:16: note: 'constexpr bool check() [with T = foo<int>]' is not usable as
a 'constexpr' function because:
9 | constexpr bool check()
| ^~~~~
The problem is that the destructor is not constexpr.