Q:

Why doesn't C++ allow implicit list initialization in the conditional operator?

This code compiles:
std::string f(bool a, std::string const& b)
{
    if (a) return b;
    return {};
}

This code also compiles:
std::string f(bool a, std::string const& b)
{
    return a ? b : std::string{};
}

This code does not compile:
std::string f(bool a, std::string const& b)
{
    return a ? b : {};
}

Given that both result values of the ?: operator are required to be the same type, why doesn't it infer the type like it does in the first example?

It appears that this question might have a similar answer to this (which essentially boils down to "because nobody thought about it when writing the language specification").  However I still think it's useful to retain this question as the question itself is different, it's still sufficiently surprising, and the other wouldn't come up in searches for this issue.

A:

A braced initializer is not an expression and thus it has no type. See:
https://scottmeyers.blogspot.com/2014/03/if-braced-initializers-have-no-type-why.html
A braced initializer is a grammatical construct with special rules in the standard, explicitly specifying allowed use and type deduction. These special rules are needed exactly because braced initializers have no type. Using them in ?: statements is not specified, and thus the program is ill-formed.
If you really need to hear the man himself say it three times in a row before you believe it, then:
https://youtu.be/wQxj20X-tIU?t=1792

