[PATCH] D44231: Check for sizeof that call functions

Paul Fultz II via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 7 15:10:26 PST 2018


pfultz2 created this revision.
pfultz2 added reviewers: clang-tools-extra, hokein, alexfh, aaron.ballman, ilya-biryukov.
Herald added a subscriber: jkorous-apple.

A common mistake that I have found in our codebase is calling a function to get an integer or enum that represents the type such as:

  int numBytes = numElements * sizeof(x.GetType());

So this extends the `sizeof` check to check for these cases. There is also a `WarnOnSizeOfCall` option so it can be disabled.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44231

Files:
  clangd/CodeComplete.cpp
  test/clangd/protocol.test
  unittests/clangd/CodeCompleteTests.cpp


Index: unittests/clangd/CodeCompleteTests.cpp
===================================================================
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -595,6 +595,18 @@
   EXPECT_TRUE(Results.items.empty());
 }
 
+TEST(CodeCompleteTest, NoColonColonAtTheEnd) {
+  auto Results = completions(R"cpp(
+    namespace clang { }
+    void f() {
+      clan^
+    }
+  )cpp");
+
+  EXPECT_THAT(Results.items, Contains(Labeled("clang")));
+  EXPECT_THAT(Results.items, Not(Contains(Labeled("clang::"))));
+}
+
 SignatureHelp signatures(StringRef Text) {
   MockFSProvider FS;
   MockCompilationDatabase CDB;
Index: test/clangd/protocol.test
===================================================================
--- test/clangd/protocol.test
+++ test/clangd/protocol.test
@@ -38,7 +38,7 @@
 # CHECK-NEXT:        "insertText": "fake",
 # CHECK-NEXT:        "insertTextFormat": 1,
 # CHECK-NEXT:        "kind": 7,
-# CHECK-NEXT:        "label": "fake::",
+# CHECK-NEXT:        "label": "fake",
 # CHECK-NEXT:        "sortText": "{{.*}}"
 #      CHECK:    ]
 # CHECK-NEXT:  }
@@ -67,7 +67,7 @@
 # CHECK-NEXT:        "insertText": "fake",
 # CHECK-NEXT:        "insertTextFormat": 1,
 # CHECK-NEXT:        "kind": 7,
-# CHECK-NEXT:        "label": "fake::",
+# CHECK-NEXT:        "label": "fake",
 # CHECK-NEXT:        "sortText": "{{.*}}"
 #      CHECK:    ]
 # CHECK-NEXT:  }
@@ -96,7 +96,7 @@
 # CHECK-NEXT:        "insertText": "fake",
 # CHECK-NEXT:        "insertTextFormat": 1,
 # CHECK-NEXT:        "kind": 7,
-# CHECK-NEXT:        "label": "fake::",
+# CHECK-NEXT:        "label": "fake",
 # CHECK-NEXT:        "sortText": "{{.*}}"
 #      CHECK:    ]
 # CHECK-NEXT:  }
Index: clangd/CodeComplete.cpp
===================================================================
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -470,6 +470,8 @@
       // (s.^ completes ~string, but s.~st^ is an error).
       if (dyn_cast_or_null<CXXDestructorDecl>(Result.Declaration))
         continue;
+      // We choose to never append '::' to completion results in clangd.
+      Result.StartsNestedNameSpecifier = false;
       Results.push_back(Result);
     }
     ResultsCallback();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44231.137491.patch
Type: text/x-patch
Size: 2249 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180307/16883412/attachment.bin>


More information about the cfe-commits mailing list