Sujet : Re: ({
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.c++Date : 21. Mar 2025, 09:58:53
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vrj9o2$176cr$1@raubtier-asyl.eternal-september.org>
References : 1
User-Agent : Mozilla Thunderbird
Am 20.03.2025 um 19:27 schrieb Alan Mackenzie:
Hello, C++.
I'm having some difficulty (amending Emacs's C++ Mode) reconciling the
two conflicting uses in C++ of ({.
Firstly, it is used as a "statement expression", a GCC enhancement also
found in C, allowing a more relaxed and natural way to write an
expression as the end result of a sequence of statements:
({ int y = foo (); int z;
if (y > 0) z = y;
else z = - y;
z; })
If the sign of y is badly predictible you may chose:
z = (y >> sizeof(y) * CHAR_BIT - 1) * y;
. I think this usage is very old.
Secondly, there's initialisation expressions like:
void f4 (int a, int b, int c)
{
std::vector<ABC> abcList2(
{{a+6,
b+6,
c+6}
}
);
....
}
. Here the ( on the std::vector line, together with the next {, can be
confused as a statement expression, though it's clearly not meant that
way. I think this syntax is much newer than the other one, though I may
be wrong here.
In calculating the indentation for source lines in these constructs, the
ambiguity causes mis-indentation for one or the other of them.
Now to my question: how common is GCC's statement expression in the wide
world of C++ source code? How much would be lost if I simply removed the
statement expression from C++ Mode's parsing functions?