Consider the following snippet to test the upcoming C++17 feature decomposition declarations (formerly known as structured bindings)
#include <cassert>
#include <utility>
constexpr auto divmod(int n, int d)
{
return std::make_pair(n / d, n % d); // in g++7, also just std::pair{n/d, n%d}
}
int main()
{
constexpr auto [q, r] = divmod(10, 3);
static_assert(q == 3 && r ==1);
}
This fails on both g++7-SVN and clang-4.0-SVN with the message:
decomposition declaration cannot be declared 'constexpr'
Dropping the constexpr
definition and changing to a regular assert()
works on both compilers.
None of the WG21 papers on this feature mention the constexpr
keyword, neither in the positive nor the negative.
Question: why aren't decomposition declarations be allowed to be constexpr
? (apart from "because the Standard says so").