We can find the answer to this in the std-discussion group Comma operator in constant-expression thread where Gabriel Dos Reis says:
For C++11 I proposed to allow it because the restriction appeared
arbitrary and all reasons I've heard as rationale for its ban appear
very unconvincing and specious to me.
and Richard Smith earlier in the thread notes some of the uses of the comma operator in a constant expression in both C++11 and C++14:
I disagree with your argument and your conclusion. In C++11, the comma
operator is useful within constexpr functions, because we aren't
allowed multiple statements:
template<typename T> constexpr T my_array<T>::at(size_type n) {
return (n < size() || throw "n too large"), (*this)[n]; }
In C++14, it's useful in essentially all of the cases where it's
useful outside of constant expressions:
constexpr void do_stuff(int x[]) {
for (int i = 0, j = 100; i != j; ++i, --j)
x[i] = x[j]; }
More philosophically, we shouldn't ban things from constant
expressions simply because we're not imaginative enough to find the
cases where they're genuinely useful. Constant expressions should not
be a semi-random sublanguage of C++, missing random features, to the
extent that we can avoid that. These days, top-level commas are
prohibited mostly because constant-expressions tend to occur in
contexts where a comma would mean something else.
Note it was argued that his C++11 example is not correct since the the expression containing the comma operator should be in ()
but his example gives the essence of the argument. The argument would be based on the grammar from section 5.19
Constant expressions:
constant-expression:
conditional-expression
we can not get to comma operator from a conditional-expression but we can get to primary-expression which gets us to ( expression )
and we can then get to the comma operator from expression.
T.C. points out that this may not be the case since the relevant section seems vague on this point.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…