<div dir="ltr"><div>+  "cannot assign to const data member %1 with const qualified type %2|"<br></div><div><br></div><div>Replace the "const data member" with "data member" here; we don't need to point out the constness twice. (Likewise below)<br>
</div><div><br></div><div>+  "cannot assign to data member within const member function %1|"</div><div><br></div><div>"data member" is not the right term here. Use either "non-static data member" or "field" (we tend to use the latter in diagnostics that might appear in C, and the former in exclusively C++ diagnostics).</div>
<div><br></div><div>+  "cannot assign to const data member %1 with const qualified type %2 in a "</div><div>+  "const member function %3}0">;</div><div><br></div><div>I don't think this last variant is useful: I think we should either point out that the field's type is const, or that we're in a const member function, not both. The way the diagnostic is phrased now might lead to people thinking that removing *either* const would solve the problem. Diagnosing the constness of the field seems better to me, since seems in some sense more fundamental.</div>
<div><br></div><div><div>+def note_function_returns_const_ref : Note<</div><div>+  "function %0 which returns const qualified type %1 declared here">;</div><div>+def note_const_variable : Note<</div><div>
+  "variable %0 declared const here">;</div><div>+def note_const_field : Note<</div><div>+  "field %0 declared const here">;</div><div>+def note_const_method : Note<</div><div>+  "member function %q0 is declared const here">;</div>
</div><div><br></div><div>Could you use a single diagnostic with a %select here?</div><div><br></div><div><div>+enum {</div><div>+  ConstUnknown,</div><div>+  ConstFunction,</div><div>+  ConstVariable,</div><div>+  ConstField,</div>
<div>+  ConstMethod,</div><div>+  ConstFieldAndMethod</div><div>+};</div></div><div><br></div><div>Move this inside the function.</div><div><br></div><div><div>+  PartialDiagnostic PD = S.PDiag(diag::err_typecheck_assign_const)</div>
<div>+                         << E->getSourceRange();</div></div><div><br></div><div>Seems like weird indentation for the <<.</div><div><br></div><div><br></div><div><div>+  // Handle class fields and methods.</div>
<div>+  if (const MemberExpr *Member = dyn_cast<MemberExpr>(E)) {</div><div>+    const Expr *Base = E;</div><div>+    while (Member) {</div><div>+      ValueDecl *VD = Member->getMemberDecl();</div><div>+      // Class field is const.</div>
<div>+      if (VD->getType().isConstQualified()) {</div><div>+        ME = Member;</div><div>+        break;</div><div>+      }</div><div>+      Base = Member->getBase();</div><div>+      Member = dyn_cast<MemberExpr>(Base);</div>
<div>+    }</div></div><div><br></div><div>This loop should go before all the other checks, so that we can diagnose</div><div><br></div><div>  const X x;</div><div>  x.y.z = 3;</div><div><br></div><div>  const X &f();</div>
<div>  f().y.z = 3;</div><div><br></div><div>properly.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 1, 2014 at 5:43 PM, Richard Trieu <span dir="ltr"><<a href="mailto:rtrieu@google.com" target="_blank">rtrieu@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Improve the wording of the error message.  Make the error more informative by taking the information from the notes and moving it to the error message.<br>

<div class="HOEnZb"><div class="h5"><br>
<a href="http://reviews.llvm.org/D4479" target="_blank">http://reviews.llvm.org/D4479</a><br>
<br>
Files:<br>
  include/clang/Basic/DiagnosticSemaKinds.td<br>
  lib/Sema/SemaExpr.cpp<br>
  test/CXX/temp/temp.decls/temp.mem/p5.cpp<br>
  test/Sema/block-misc.c<br>
  test/SemaCXX/anonymous-union.cpp<br>
  test/SemaCXX/captured-statements.cpp<br>
  test/SemaCXX/cxx0x-constexpr-const.cpp<br>
  test/SemaCXX/err_typecheck_assign_const.cpp<br>
  test/SemaCXX/function-type-qual.cpp<br>
  test/SemaObjC/arc.m<br>
  test/SemaTemplate/dependent-type-identity.cpp<br>
</div></div><br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>