[cfe-commits] r153026 - in /cfe/trunk: lib/Parse/ParseDecl.cpp test/SemaCXX/cxx98-compat.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Sun Mar 18 16:12:22 PDT 2012

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

> Hold on,
> On Sun, Mar 18, 2012 at 3:25 PM, Sebastian Redl <sebastian.redl at getdesigned.at> 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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120319/ea273ef4/attachment.html>

More information about the cfe-commits mailing list