[llvm-bugs] [Bug 44034] New: Clang++ accepts invalid template code
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Nov 17 12:14:08 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=44034
Bug ID: 44034
Summary: Clang++ accepts invalid template code
Product: clang
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: Darrell.Wright at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
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/dn5s4v
Affects older clang too.
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(); }
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191117/e1974ce8/attachment.html>
More information about the llvm-bugs
mailing list