On 18.03.2012, at 23:51, Chandler Carruth wrote:

> Hold on,
> 
> On Sun, Mar 18, 2012 at 3:25 PM, Sebastian Redl 
> <[email protected]> wrote:
> +int InitList(int i = {}) { // expected-warning {{generalized initializer 
> lists are incompatible with C++98}} \
> +                           // expected-warning {{scalar initialized from 
> empty initializer list is incompatible with C++98}}
> 
> Why did we go from zero to two warnings? One should be enough, no?

It's a bug that's there in all instances of this pattern, because the two 
warnings are generated in very different positions. One is a parser warning, 
telling the user that a braced initializer wouldn't be valid in this position 
in C++98. The other is a sema warning, telling the user that this particular 
initializer wouldn't be valid for scalars. It would be complicated to transfer 
the information that the parser warning was emitted so that the sema warning 
won't be, and it's a minor problem under an off-by-default warning, so I 
haven't bothered to fix it.
So basically: braced initializer as default argument is one warning, {} as the 
initializer for an int the other. The two warnings have different scopes; they 
just happen to overlap here.

As a side note, the second warning was there already before my patch. It just 
didn't trigger in Eli's test case, because he didn't use an empty initializer 
as the default argument.

That reminds me though that my commit message was incomplete, because the other 
important change was to not accept init lists as default arguments in C++98 at 
all. The only place where we currently accept braced initializers as an 
extension is return statements, and there only because libstdc++ uses that.

Sebastian
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to