https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87999
Bug ID: 87999
Summary: Constexpr eval. in static_assert makes string_view
comparison non constexpr
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: wieichdashasse at gmail dot com
Target Milestone: ---
Hey,
I see an inconsistency when using gcc compared to other compilers when using a
constexpr return directly in a (constexpr) static_assert
Minimal repro:
#include
constexpr bool IsValid_impl
(std::string_view name)
{
return name == "Steve";
}
template
constexpr void IsValid(F func)
{
// Using it via intermediate will make it work
// constexpr auto tmp = IsValid_impl(func());
// static_assert(tmp);
static_assert(IsValid_impl(func()));
}
int main()
{
IsValid([]{ return "Steve";});
}
(as featured in
https://godbolt.org/z/YCVMRp)
Output:
test.cpp: In instantiation of 'constexpr void IsValid(F) [with F =
main()::]':
prog.cpp: In instantiation of 'constexpr void IsValid(F) [with F =
main()::]':
prog.cpp:20:46: required from here
prog.cpp:15:31: error: non-constant condition for static assertion
15 | static_assert(IsValid_impl(func()));
| ^~~~
Adding the intermediate makes it work, hence i think it is a bug.
I've tested this on 8.2.0, 9.0, 7.3.0 and 7.2.0
Cheers,
Justin Meyer