<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jan 26, 2015 at 7:38 AM, Ehsan Akhgari <span dir="ltr"><<a href="mailto:ehsan.akhgari@gmail.com" target="_blank">ehsan.akhgari@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">================<br>
Comment at: lib/Parse/ParseDeclCXX.cpp:2100-2139<br>
@@ +2099,42 @@<br>
+                              unsigned* QualifierLoc) {<br>
+      FixItHint Insertion;<br>
+      if (DS.getTypeQualifiers() & TypeQual) {<br>
+        if (!(Function.TypeQuals & TypeQual)) {<br>
+          std::string Name(FixItName);<br>
+          Name += " ";<br>
+          Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name.c_str());<br>
+          Function.TypeQuals |= TypeQual;<br>
+          *QualifierLoc = SpecLoc.getRawEncoding();<br>
+        }<br>
+        Diag(SpecLoc, diag::err_declspec_after_virtspec)<br>
+          << FixItName<br>
+          << VirtSpecifiers::getSpecifierName(VS.getLastSpecifier())<br>
+          << FixItHint::CreateRemoval(SpecLoc)<br>
+          << Insertion;<br>
+      }<br>
+    };<br>
+    DeclSpecCheck(DeclSpec::TQ_const, "const", DS.getConstSpecLoc(),<br>
+                  &Function.ConstQualifierLoc);<br>
+    DeclSpecCheck(DeclSpec::TQ_volatile, "volatile", DS.getVolatileSpecLoc(),<br>
+                  &Function.VolatileQualifierLoc);<br>
+    DeclSpecCheck(DeclSpec::TQ_restrict, "restrict", DS.getRestrictSpecLoc(),<br>
+                  &Function.RestrictQualifierLoc);<br>
+  }<br>
+<br>
+  // Parse ref-qualifiers.<br>
+  bool RefQualifierIsLValueRef = true;<br>
+  SourceLocation RefQualifierLoc;<br>
+  if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc)) {<br>
+    const char *Name = (RefQualifierIsLValueRef ? "& " : "&& ");<br>
+    FixItHint Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name);<br>
+    Function.RefQualifierIsLValueRef = RefQualifierIsLValueRef;<br>
+    Function.RefQualifierLoc = RefQualifierLoc.getRawEncoding();<br>
+<br>
+    Diag(RefQualifierLoc, diag::err_declspec_after_virtspec)<br>
+      << (RefQualifierIsLValueRef ? "&" : "&&")<br>
+      << VirtSpecifiers::getSpecifierName(VS.getLastSpecifier())<br>
+      << FixItHint::CreateRemoval(RefQualifierLoc)<br>
+      << Insertion;<br>
+    D.SetRangeEnd(RefQualifierLoc);<br>
+  }<br>
+}<br>
----------------<br>
</div></div><span class="">rsmith wrote:<br>
> Maybe only produce a single diagnostic no matter how many specifiers were provided? You can then also use `FixItHint::CreateInsertionFromRange` to produce a fixit that copies the complete range of specifiers from after the virt-specifier to before (this will preserve things like macro names and whitespace between the tokens).<br>
</span>Can you please tell me how that would work?  My fixit hints are careful so that if you have something like: `void foo() override final &;` you would get `void foo() final & override;` whereas if you have `void foo() final override final &;` you would get `void foo() final & override;` (IOW you won't get two final keywords.)<br></blockquote><div><br></div><div>Hmm, yes, this is tricky. It would be great if we remembered fixit hints across diagnostics; then you could first emit removal fixits for the redundant qualifiers and later emit an insertion-from-range hint (which would pick up whatever remains of that range after the redundant qualifiers are removed). This same issue will affect *any* insertion-from-range fixit hint, though, so I think you should go ahead with CreateInsertionFromRange and we can fix the issue with that interacting with other fixits separately.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I don't know how to do the same with a range based insertion fixit hint...<br>
<div class="HOEnZb"><div class="h5"><br>
<a href="http://reviews.llvm.org/D7012" target="_blank">http://reviews.llvm.org/D7012</a><br>
<br>
EMAIL PREFERENCES<br>
  <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
<br>
<br>
</div></div></blockquote></div><br></div></div>