https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99893
Bug ID: 99893
Summary: C++20 unexpanded parameter packs falsely not detected
(lambda is involved)
Product: gcc
Version: 10.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: bisqwit at iki dot fi
Target Milestone: ---
GCC produces false error message:
bug1.cc: In function ‘consteval void VerifyHash()’:
bug1.cc:20:70: error: operand of fold expression has no unexpanded parameter
packs
20 | [](){static_assert(hash(s.data(), s.size()) == expected_hash);}()
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
On this code:
#include <algorithm> // copy_n and size_t
static constexpr unsigned hash(const char* s, std::size_t length)
{
s=s;
return length;
}
template<std::size_t N>
struct fixed_string
{
constexpr fixed_string(const char (&s)[N]) { std::copy_n(s, N, str); }
consteval const char* data() const { return str; }
consteval std::size_t size() const { return N-1; }
char str[N];
};
template<unsigned expected_hash, fixed_string... s>
static consteval void VerifyHash()
{
(
[](){static_assert(hash(s.data(), s.size()) == expected_hash);}()
,...);
// ^ Falsely reports that there are no unexpanded parameter packs,
// while there definitely is ("s" is used).
}
void foo()
{
VerifyHash<5, "khaki", "plums">();
}
Compiler version:
g++-10 (Debian 10.2.1-6) 10.2.1 20210110