[PATCH] D14204: Fix crash in redundant-void-arg check.

Angel Garcia via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 2 03:41:35 PST 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL251792: Fix crash in redundant-void-arg check. (authored by angelgarcia).

Changed prior to commit:
  http://reviews.llvm.org/D14204?vs=38889&id=38890#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14204

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp

Index: clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-                                  unless(isImplicit()),
-                                  unless(isExternC())).bind(FunctionId),
+                                  unless(isImplicit()), unless(isExternC()))
+                         .bind(FunctionId),
                      this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
                      this);
@@ -77,9 +77,10 @@
       cxxReinterpretCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
           .bind(NamedCastId),
       this);
-  Finder->addMatcher(cxxConstCastExpr(isExpansionInMainFile(),
-                                   CastDestinationIsFunction).bind(NamedCastId),
-                     this);
+  Finder->addMatcher(
+      cxxConstCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+          .bind(NamedCastId),
+      this);
   Finder->addMatcher(lambdaExpr(isExpansionInMainFile()).bind(LambdaId), this);
 }
 
@@ -128,11 +129,14 @@
 void RedundantVoidArgCheck::removeVoidArgumentTokens(
     const ast_matchers::MatchFinder::MatchResult &Result, SourceRange Range,
     StringRef GrammarLocation) {
-  std::string DeclText =
-      Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
-                           *Result.SourceManager,
-                           Result.Context->getLangOpts()).str();
-  Lexer PrototypeLexer(Range.getBegin(), Result.Context->getLangOpts(),
+  CharSourceRange CharRange = Lexer::makeFileCharRange(
+      CharSourceRange::getTokenRange(Range), *Result.SourceManager,
+      Result.Context->getLangOpts());
+
+  std::string DeclText = Lexer::getSourceText(CharRange, *Result.SourceManager,
+                                              Result.Context->getLangOpts())
+                             .str();
+  Lexer PrototypeLexer(CharRange.getBegin(), Result.Context->getLangOpts(),
                        DeclText.data(), DeclText.data(),
                        DeclText.data() + DeclText.size());
   enum TokenState {
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,19 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; };{{$}}
 }
+
+#define M(x) x
+
+M(void inmacro(void) {})
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in function definition
+// CHECK-FIXES: M(void inmacro() {})
+
+#define F(A, B)        \
+  struct F_##A##_##B { \
+    F_##A##_##B(void); \
+  };                   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14204.38890.patch
Type: text/x-patch
Size: 3267 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151102/c3c5b668/attachment-0001.bin>


More information about the cfe-commits mailing list