Open BengtGustafsson opened 10 months ago
Pro's:
Con's:
=
will generate output that compiles successfully when it shouldn't. For example if they copy-paste from a auto some_member_var=foo();
incorrectly, into a F"val={some_member_var=}";
. {}
braces need to be brace-escaped as well.Did I miss anything?
I agree that con #2 is not to be neglected: The more things that have a meaning the less things that are probably bugs the compiler can complain about.
Re con #3: Regardless of how LEWG/EWG decide on handling escaping of quotes and braces in expression-fields this should not affect this particular idea, the = is always after any of those nested literals or brace levels have ended.
Did I miss anything?
This syntax is actually ambiguous since you can have a valid expression ending in =
today, not just in mis-pasting:
struct X
{
void operator==(int);
void operator=(int);
};
template<>
struct std::formatter<void (X::*)(int), char> { /* ... */ };
F"Test {&X::operator==}" // <- {(&X::operator==)} or {(&X::operator=)=}?
Though, I'm confident absolutely no one writes code like this, and this can be resolved by simply requiring a parenthesis if the expression ends in =. Just mentioning it in case someone ask about potential conflicts.
Thanks for pointing this out. I forgot about those nasty take-the-address-of-an-operator cases where almost any token can end an expression.
It seems a rather ridiculous thing to do to format the address of an assignment operator or comparison operator so I don't know, it seems fairly useful to use the = syntax as in Python, and as you remarked, if you really want to format the address of one of the affected operators you can use a parenthesis.
Actually, if tokenization is used this would only react to &operator=
as ==
is a separate token, as are all the other assignment operators as well as !=
.
This means that the extracted expression is actually &operator
which always a syntax error, so apart from the possible confusion in this very odd case there is no big problem, the address of one operator can never transmogrify to the address of another.
Do we want this.
Pros and cons.