[PATCH] Better diagnostic for re-initialization of static data members

Richard Smith richard at metafoo.co.uk
Wed Nov 20 16:48:01 PST 2013


On Wed, Nov 20, 2013 at 4:31 PM, Hans Wennborg <hans at chromium.org> wrote:

>
>   > I like this change, but I wonder if we can come up with a better
> wording
>   > for the diagnostic than "re-initialization". Strawman:
>   >
>   > "static data member %0 already has an initializer"
>
>   Sounds good to me. New patch coming up.
>
>
> ================
> Comment at: lib/Sema/SemaDecl.cpp:8187
> @@ -8186,4 +8186,3 @@
>      if (VDecl->isStaticDataMember() &&
> VDecl->getAnyInitializer(PrevInit)) {
> -      Diag(VDecl->getLocation(), diag::err_redefinition)
> -        << VDecl->getDeclName();
> -      Diag(PrevInit->getLocation(), diag::note_previous_definition);
> +      Diag(Init->getExprLoc(),
> diag::err_static_data_member_reinitialization) << VDecl->getDeclName();
> +      Diag(PrevInit->getInit()->getExprLoc(),
> diag::note_previous_initializer) << 0;
> ----------------
> Richard Smith wrote:
> > You can use just `VDecl`, not `VDecl->getDeclName()`, here.
> Hmm, when I tried this, I got:
>
> error: 'error' diagnostics seen but not expected:
>   File
> D:\src\llvm\tools\clang\test\SemaCXX\cxx1y-variable-templates_in_class.cpp
> Line 46: static data member 'right<type-parameter-0-0, int>' already has an
> initializer


Hmm, looks like a bug in variable templates: we should be preserving the
template arguments as written and using them in the declaration name here.
Anyway, updated patch LGTM, thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131120/b1a833f7/attachment.html>


More information about the cfe-commits mailing list