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

Hans Wennborg hans at chromium.org
Wed Nov 20 16:31:16 PST 2013


  > 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


http://llvm-reviews.chandlerc.com/D2235



More information about the cfe-commits mailing list