[PATCH] Fix clang-tidy to account of correct source location of defaulted/deleted members

Eli Bendersky eliben at google.com
Thu Mar 19 14:37:31 PDT 2015


Hi alexfh, sbenza,

Followup to http://reviews.llvm.org/D8465, which would break a test in clang-tidy. clang-tidy previously assumes that source locations of defaulted/deleted members are (incorrectly) not including the '= ...' part.

http://reviews.llvm.org/D8466

Files:
  clang-tidy/misc/UseOverrideCheck.cpp

Index: clang-tidy/misc/UseOverrideCheck.cpp
===================================================================
--- clang-tidy/misc/UseOverrideCheck.cpp
+++ clang-tidy/misc/UseOverrideCheck.cpp
@@ -144,7 +144,12 @@
       InsertLoc = Method->getBody()->getLocStart();
 
     if (!InsertLoc.isValid()) {
-      if (Tokens.size() > 2 && GetText(Tokens.back(), Sources) == "0" &&
+      // For declarations marked with "= 0" or "= [default|delete]", the end
+      // location will point until after those markings. Therefore, the override
+      // keyword shouldn't be inserted at the end, but before the '='.
+      if (Tokens.size() > 2 && (GetText(Tokens.back(), Sources) == "0" ||
+                                Tokens.back().is(tok::kw_default) ||
+                                Tokens.back().is(tok::kw_delete)) &&
           GetText(Tokens[Tokens.size() - 2], Sources) == "=") {
         InsertLoc = Tokens[Tokens.size() - 2].getLocation();
       } else if (GetText(Tokens.back(), Sources) == "ABSTRACT") {

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8466.22304.patch
Type: text/x-patch
Size: 1018 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150319/8c72e0a5/attachment.bin>


More information about the cfe-commits mailing list