[PATCH] Diagnose declspecs occuring after virt-specifier-seq and generate fixit hints

Richard Smith richard at metafoo.co.uk
Wed Jan 14 17:20:25 PST 2015


Thanks, this is a nice improvement. Have you considered also handling ref-qualifiers here?


================
Comment at: lib/Parse/ParseDeclCXX.cpp:2100-2113
@@ +2099,16 @@
+    bool DeclIsRestrict = Function.TypeQuals & DeclSpec::TQ_restrict;
+    if (DS.getTypeQualifiers() & DeclSpec::TQ_const) {
+      if (!DeclIsConst) {
+        Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), "const ");
+        // Mark the declaration as const.
+        Function.TypeQuals |= DeclSpec::TQ_const;
+        Function.ConstQualifierLoc = DS.getConstSpecLoc().getRawEncoding();
+      }
+      Diag(DS.getConstSpecLoc(),
+           diag::err_declspec_after_virtspec)
+        << "const"
+        << VirtSpecifiers::getSpecifierName(VS.getLastSpecifier())
+        << FixItHint::CreateRemoval(DS.getConstSpecLoc())
+        << Insertion;
+    }
+    if (DS.getTypeQualifiers() & DeclSpec::TQ_volatile) {
----------------
Please factor this out into a loop or a lambda rather than duplicating it three times.

http://reviews.llvm.org/D6828

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list