https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92551
Bug ID: 92551
Summary: accepts invalid code in function template
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Darrell.Wright at gmail dot com
Target Milestone: ---
I accidently produced this invalid code and it worked as intended until I
tested further. However, the integer_sequence should never have been deduced
https://gcc.godbolt.org/z/hp4crn
This will return 20, but should be an error
#include <algorithm>
#include <type_traits>
namespace algorithm_impl {
template <typename Function, typename... Args, size_t... Is>
constexpr void do_n(Function &&func, Args &&... args,
std::integer_sequence<size_t, Is...>) {
if constexpr (sizeof...(Is) > 0) {
(void)((func(args...), Is) + ...);
}
}
} // namespace algorithm_impl
template <size_t count, typename Function, typename... Args>
constexpr void do_n(Function &&func,
Args &&... args) noexcept(noexcept(func(args...))) {
algorithm_impl::do_n(std::forward<Function>(func),
std::forward<Args>(args)...,
std::make_integer_sequence<size_t, count>{});
}
constexpr int do_n_1_test() {
int n = 0;
do_n<20>([&n] { ++n; });
return n;
}
int main() { return do_n_1_test(); }