Thanks for all the really great feedback. This addresses all the issues except
for checking if the translation unit is C instead of C++. I will add that and
update the review.
http://reviews.llvm.org/D7639
Files:
clang-tidy/readability/CMakeLists.txt
clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tidy/readability/RemoveVoidArg.cpp
clang-tidy/readability/RemoveVoidArg.h
test/clang-tidy/readability-remove-void-arg.cpp
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
Index: clang-tidy/readability/CMakeLists.txt
===================================================================
--- clang-tidy/readability/CMakeLists.txt
+++ clang-tidy/readability/CMakeLists.txt
@@ -8,6 +8,7 @@
NamespaceCommentCheck.cpp
ReadabilityTidyModule.cpp
RedundantSmartptrGet.cpp
+ RemoveVoidArg.cpp
ShrinkToFitCheck.cpp
LINK_LIBS
Index: clang-tidy/readability/ReadabilityTidyModule.cpp
===================================================================
--- clang-tidy/readability/ReadabilityTidyModule.cpp
+++ clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -15,6 +15,7 @@
#include "ElseAfterReturnCheck.h"
#include "FunctionSize.h"
#include "RedundantSmartptrGet.h"
+#include "RemoveVoidArg.h"
#include "ShrinkToFitCheck.h"
namespace clang {
@@ -36,6 +37,7 @@
"readability-redundant-smartptr-get");
CheckFactories.registerCheck<ShrinkToFitCheck>(
"readability-shrink-to-fit");
+ CheckFactories.registerCheck<RemoveVoidArg>("readability-remove-void-arg");
}
};
Index: clang-tidy/readability/RemoveVoidArg.cpp
===================================================================
--- /dev/null
+++ clang-tidy/readability/RemoveVoidArg.cpp
@@ -0,0 +1,283 @@
+//===- RemoveVoidArg.cpp - clang-tidy -------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "RemoveVoidArg.h"
+#include "clang/Lex/Lexer.h"
+
+#include <string>
+
+using namespace clang;
+using namespace clang::ast_matchers;
+using namespace llvm;
+using clang::tooling::newFrontendActionFactory;
+using clang::tooling::Replacement;
+using clang::tooling::CompilationDatabase;
+
+namespace {
+
+// Returns the source text for a source range
+inline StringRef getText(const MatchFinder::MatchResult &Result,
+ SourceRange Range) {
+ return Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
+ *Result.SourceManager,
+ Result.Context->getLangOpts());
+}
+
+// Returns the source text for a pair of source locations.
+inline StringRef getText(const MatchFinder::MatchResult &Result,
+ SourceLocation Begin, SourceLocation End) {
+ return getText(Result, SourceRange(Begin, End));
+}
+
+// Returns the text that makes up 'node' in the source.
+// Returns an empty string if the text cannot be found.
+
+template <typename T>
+StringRef getText(const MatchFinder::MatchResult &Result, const T &Node) {
+ return getText(Result, Node.getSourceRange());
+}
+
+char const *const FunctionId = "fn";
+char const *const TypedefId = "td";
+char const *const FieldId = "fd";
+char const *const VarId = "var";
+char const *const NamedCastId = "nc";
+char const *const CStyleCastId = "csc";
+char const *const ExplicitCastId = "cast";
+char const *const FunctionalCastId = "fncast";
+char const *const LambdaId = "lambda";
+
+} // namespace
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+void RemoveVoidArg::registerMatchers(MatchFinder *Finder) {
+ Finder->addMatcher(functionDecl(parameterCountIs(0), isExpansionInMainFile(),
+ unless(isExternC())).bind(FunctionId),
+ this);
+ Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
+ this);
+ auto ParenFunctionType = parenType(innerType(functionType()));
+ auto PointerToFunctionType = pointee(ParenFunctionType);
+ auto FunctionOrMemberPointer =
+ anyOf(hasType(pointerType(PointerToFunctionType)),
+ hasType(memberPointerType(PointerToFunctionType)));
+ Finder->addMatcher(
+ fieldDecl(isExpansionInMainFile(), FunctionOrMemberPointer).bind(FieldId),
+ this);
+ Finder->addMatcher(
+ varDecl(isExpansionInMainFile(), FunctionOrMemberPointer).bind(VarId),
+ this);
+ auto CastDestinationIsFunction =
+ hasDestinationType(pointsTo(ParenFunctionType));
+ Finder->addMatcher(
+ cStyleCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+ .bind(CStyleCastId),
+ this);
+ Finder->addMatcher(
+ staticCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+ .bind(NamedCastId),
+ this);
+ Finder->addMatcher(
+ reinterpretCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+ .bind(NamedCastId),
+ this);
+ Finder->addMatcher(constCastExpr(isExpansionInMainFile(),
+ CastDestinationIsFunction).bind(NamedCastId),
+ this);
+ Finder->addMatcher(
+ functionalCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+ .bind(FunctionalCastId),
+ this);
+ Finder->addMatcher(lambdaExpr(isExpansionInMainFile()).bind(LambdaId), this);
+}
+
+void RemoveVoidArg::check(const MatchFinder::MatchResult &Result) {
+ const BoundNodes &Nodes = Result.Nodes;
+ if (const auto Function = Nodes.getNodeAs<FunctionDecl>(FunctionId)) {
+ processFunctionDecl(Result, Function);
+ } else if (const auto Typedef = Nodes.getNodeAs<TypedefDecl>(TypedefId)) {
+ processTypedefDecl(Result, Typedef);
+ } else if (const auto Member = Nodes.getNodeAs<FieldDecl>(FieldId)) {
+ processFieldDecl(Result, Member);
+ } else if (const auto Var = Nodes.getNodeAs<VarDecl>(VarId)) {
+ processVarDecl(Result, Var);
+ } else if (const auto NamedCast =
+ Nodes.getNodeAs<CXXNamedCastExpr>(NamedCastId)) {
+ processNamedCastExpr(Result, NamedCast);
+ } else if (const auto CStyleCast =
+ Nodes.getNodeAs<CStyleCastExpr>(CStyleCastId)) {
+ processCStyleCastExpr(Result, CStyleCast);
+ } else if (const auto FunctionalCast =
+ Nodes.getNodeAs<CXXFunctionalCastExpr>(FunctionalCastId)) {
+ processFunctionalCast(Result, FunctionalCast);
+ } else if (const auto ExplicitCast =
+ Nodes.getNodeAs<ExplicitCastExpr>(ExplicitCastId)) {
+ processExplicitCastExpr(Result, ExplicitCast);
+ } else if (const auto Lambda = Nodes.getNodeAs<LambdaExpr>(LambdaId)) {
+ processLambdaExpr(Result, Lambda);
+ }
+}
+
+void RemoveVoidArg::processFunctionDecl(const MatchFinder::MatchResult &Result,
+ const FunctionDecl *const Function) {
+ const SourceLocation Start = Function->getLocStart();
+ if (Function->isThisDeclarationADefinition()) {
+ const SourceLocation BeforeBody =
+ Function->getBody()->getLocStart().getLocWithOffset(-1);
+ const std::string DeclText = getText(Result, Start, BeforeBody);
+ removeVoidArgumentTokens(Result, Start, DeclText, "function definition");
+ } else {
+ const std::string Text = getText(Result, *Function);
+ removeVoidArgumentTokens(Result, Start, Text, "function declaration");
+ }
+}
+
+void RemoveVoidArg::removeVoidArgumentTokens(
+ const MatchFinder::MatchResult &Result, SourceLocation StartLoc,
+ const std::string &DeclText, const std::string &GrammarLocation) {
+ clang::Lexer PrototypeLexer(StartLoc, Result.Context->getLangOpts(),
+ DeclText.c_str(), DeclText.c_str(),
+ DeclText.c_str() + DeclText.length());
+ enum TokenState {
+ NothingYet,
+ SawLeftParen,
+ SawVoid,
+ };
+ TokenState State = NothingYet;
+ Token VoidToken;
+ Token ProtoToken;
+ const std::string Diagnostic =
+ "redundant void argument list in " + GrammarLocation;
+ while (!PrototypeLexer.LexFromRawLexer(ProtoToken)) {
+ switch (State) {
+ case NothingYet:
+ if (ProtoToken.is(tok::TokenKind::l_paren)) {
+ State = SawLeftParen;
+ }
+ break;
+ case SawLeftParen:
+ if (ProtoToken.is(tok::TokenKind::kw_void) ||
+ (ProtoToken.is(tok::TokenKind::raw_identifier) &&
+ ProtoToken.getRawIdentifier() == "void")) {
+ State = SawVoid;
+ VoidToken = ProtoToken;
+ } else {
+ State = NothingYet;
+ }
+ break;
+ case SawVoid:
+ State = NothingYet;
+ if (ProtoToken.is(tok::TokenKind::r_paren)) {
+ removeVoidToken(VoidToken, Diagnostic);
+ } else if (ProtoToken.is(tok::TokenKind::l_paren)) {
+ State = SawLeftParen;
+ }
+ break;
+ }
+ }
+ if (State == SawVoid && ProtoToken.is(tok::TokenKind::r_paren)) {
+ removeVoidToken(VoidToken, Diagnostic);
+ }
+}
+
+void RemoveVoidArg::removeVoidToken(Token VoidToken,
+ const std::string &Diagnostic) {
+ const SourceLocation VoidLoc(VoidToken.getLocation());
+ const SourceRange VoidRange =
+ SourceRange(VoidLoc, VoidLoc.getLocWithOffset(3));
+ diag(VoidLoc, Diagnostic) << FixItHint::CreateRemoval(VoidRange);
+}
+
+void RemoveVoidArg::processTypedefDecl(const MatchFinder::MatchResult &Result,
+ const TypedefDecl *const Typedef) {
+ const std::string Text = getText(Result, *Typedef);
+ removeVoidArgumentTokens(Result, Typedef->getLocStart(), Text, "typedef");
+}
+
+void RemoveVoidArg::processFieldDecl(const MatchFinder::MatchResult &Result,
+ const FieldDecl *const Member) {
+ const std::string Text = getText(Result, *Member);
+ removeVoidArgumentTokens(Result, Member->getLocStart(), Text,
+ "field declaration");
+}
+
+void RemoveVoidArg::processVarDecl(const MatchFinder::MatchResult &Result,
+ const VarDecl *const Var) {
+ const SourceLocation Begin = Var->getLocStart();
+ if (Var->hasInit()) {
+ const SourceLocation InitStart =
+ Var->getInit()->getLocStart().getLocWithOffset(-1);
+ const std::string Text = getText(Result, Begin, InitStart);
+ removeVoidArgumentTokens(Result, Begin, Text,
+ "variable "
+ "declaration with initializer");
+ } else {
+ const std::string Text = getText(Result, *Var);
+ removeVoidArgumentTokens(Result, Begin, Text, "variable declaration");
+ }
+}
+
+void
+RemoveVoidArg::processNamedCastExpr(const MatchFinder::MatchResult &Result,
+ const CXXNamedCastExpr *const NamedCast) {
+ const SourceRange AngleBrackets = NamedCast->getAngleBrackets();
+ const SourceLocation Begin = AngleBrackets.getBegin().getLocWithOffset(1);
+ const SourceLocation End = AngleBrackets.getEnd().getLocWithOffset(-1);
+ const std::string TemplateArgument = getText(Result, Begin, End);
+ removeVoidArgumentTokens(Result, Begin, TemplateArgument, "named cast");
+}
+
+void
+RemoveVoidArg::processCStyleCastExpr(const MatchFinder::MatchResult &Result,
+ const CStyleCastExpr *const CStyleCast) {
+ const SourceLocation Begin = CStyleCast->getLParenLoc().getLocWithOffset(1);
+ const SourceLocation End = CStyleCast->getRParenLoc().getLocWithOffset(-1);
+ const std::string ExprText = getText(Result, Begin, End);
+ removeVoidArgumentTokens(Result, Begin, ExprText, "C style cast");
+}
+
+void RemoveVoidArg::processFunctionalCast(
+ const MatchFinder::MatchResult &Result,
+ const CXXFunctionalCastExpr *const FunctionalCast) {
+ const SourceLocation Begin = FunctionalCast->getLocStart();
+ const std::string ExprText = getText(
+ Result, Begin, FunctionalCast->getLParenLoc().getLocWithOffset(-1));
+ removeVoidArgumentTokens(Result, Begin, ExprText, "functional cast");
+}
+
+void RemoveVoidArg::processExplicitCastExpr(
+ const MatchFinder::MatchResult &Result,
+ const ExplicitCastExpr *const ExplicitCast) {
+ const std::string ExprText = getText(Result, *ExplicitCast);
+ removeVoidArgumentTokens(Result, ExplicitCast->getLocStart(), ExprText,
+ "explicit cast");
+}
+
+void RemoveVoidArg::processLambdaExpr(
+ const ast_matchers::MatchFinder::MatchResult &Result,
+ const LambdaExpr *const Lambda) {
+ const bool HasNoParams =
+ Lambda->getLambdaClass()->getLambdaCallOperator()->getNumParams() == 0;
+ if (Lambda->hasExplicitParameters() && HasNoParams) {
+ const SourceLocation Begin =
+ Lambda->getIntroducerRange().getEnd().getLocWithOffset(1);
+ const SourceLocation End =
+ Lambda->getBody()->getLocStart().getLocWithOffset(-1);
+ const std::string LambdaProtoText = getText(Result, Begin, End);
+ removeVoidArgumentTokens(Result, Begin, LambdaProtoText,
+ "lambda expression");
+ }
+}
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
Index: clang-tidy/readability/RemoveVoidArg.h
===================================================================
--- /dev/null
+++ clang-tidy/readability/RemoveVoidArg.h
@@ -0,0 +1,79 @@
+//===--- RemoveVoidArg.h - clang-tidy ---------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REMOVEVOIDARG_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REMOVEVOIDARG_H
+
+#include <string>
+
+#include "../ClangTidy.h"
+#include "clang/Lex/Token.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// \brief Find and remove redundant void argument lists.
+///
+/// Examples:
+/// int foo(void); ==> int foo();
+class RemoveVoidArg : public ClangTidyCheck {
+public:
+ RemoveVoidArg(StringRef Name, ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context) {}
+
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+ void processFunctionDecl(const ast_matchers::MatchFinder::MatchResult &Result,
+ const FunctionDecl *Function);
+
+ void processTypedefDecl(const ast_matchers::MatchFinder::MatchResult &Result,
+ const TypedefDecl *Typedef);
+
+ void processFieldDecl(const ast_matchers::MatchFinder::MatchResult &Result,
+ const FieldDecl *Member);
+
+ void processVarDecl(const ast_matchers::MatchFinder::MatchResult &Result,
+ const VarDecl *Var);
+
+ void
+ processNamedCastExpr(const ast_matchers::MatchFinder::MatchResult &Result,
+ const CXXNamedCastExpr *NamedCast);
+
+ void
+ processCStyleCastExpr(const ast_matchers::MatchFinder::MatchResult &Result,
+ const CStyleCastExpr *CStyleCast);
+
+ void
+ processFunctionalCast(const ast_matchers::MatchFinder::MatchResult &Result,
+ const CXXFunctionalCastExpr *FunctionalCast);
+
+ void
+ processExplicitCastExpr(const ast_matchers::MatchFinder::MatchResult &Result,
+ const ExplicitCastExpr *ExplicitCast);
+
+ void processLambdaExpr(const ast_matchers::MatchFinder::MatchResult &Result,
+ const LambdaExpr *Lambda);
+
+ void
+ removeVoidArgumentTokens(const ast_matchers::MatchFinder::MatchResult &Result,
+ SourceLocation StartLoc, const std::string &DeclText,
+ const std::string &GrammarLocation);
+
+ void removeVoidToken(Token VoidToken, const std::string &Diagnostic);
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REMOVEVOIDARG_H
Index: test/clang-tidy/readability-remove-void-arg.cpp
===================================================================
--- /dev/null
+++ test/clang-tidy/readability-remove-void-arg.cpp
@@ -0,0 +1,376 @@
+// RUN: $(dirname %s)/check_clang_tidy.sh %s readability-remove-void-arg %t
+// REQUIRES: shell
+
+#include <iostream>
+
+int foo();
+
+void bar();
+
+void bar2();
+
+extern "C" void ecfoo(void);
+
+extern int i;
+
+int j = 1;
+
+int foo(void)
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant void argument list in function definition [readability-remove-void-arg]
+// CHECK-FIXES: {{^}}int foo(){{$}}
+{
+ return 0;
+}
+
+typedef unsigned int my_uint;
+
+typedef void my_void;
+
+// A function taking void and returning a pointer to function taking void
+// and returning int.
+int (*returns_fn_void_int(void))(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}} in function declaration
+// CHECK-MESSAGES: :[[@LINE-2]]:34: warning: {{.*}} in function declaration
+// CHECK-FIXES: {{^}}int (*returns_fn_void_int())();{{$}}
+
+typedef int (*returns_fn_void_int_t(void))(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: {{.*}} in typedef
+// CHECK-MESSAGES: :[[@LINE-2]]:44: warning: {{.*}} in typedef
+// CHECK-FIXES: {{^}}typedef int (*returns_fn_void_int_t())();{{$}}
+
+int (*returns_fn_void_int(void))(void)
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}} in function definition
+// CHECK-MESSAGES: :[[@LINE-2]]:34: warning: {{.*}} in function definition
+// CHECK-FIXES: {{^}}int (*returns_fn_void_int())(){{$}}
+{
+ return nullptr;
+}
+
+// A function taking void and returning a pointer to a function taking void
+// and returning a pointer to a function taking void and returning void.
+void (*(*returns_fn_returns_fn_void_void(void))(void))(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: {{.*}} in function declaration
+// CHECK-MESSAGES: :[[@LINE-2]]:49: warning: {{.*}} in function declaration
+// CHECK-MESSAGES: :[[@LINE-3]]:56: warning: {{.*}} in function declaration
+// CHECK-FIXES: {{^}}void (*(*returns_fn_returns_fn_void_void())())();{{$}}
+
+typedef void (*(*returns_fn_returns_fn_void_void_t(void))(void))(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:52: warning: {{.*}} in typedef
+// CHECK-MESSAGES: :[[@LINE-2]]:59: warning: {{.*}} in typedef
+// CHECK-MESSAGES: :[[@LINE-3]]:66: warning: {{.*}} in typedef
+// CHECK-FIXES: {{^}}typedef void (*(*returns_fn_returns_fn_void_void_t())())();{{$}}
+
+void (*(*returns_fn_returns_fn_void_void(void))(void))(void)
+// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: {{.*}} in function definition
+// CHECK-MESSAGES: :[[@LINE-2]]:49: warning: {{.*}} in function definition
+// CHECK-MESSAGES: :[[@LINE-3]]:56: warning: {{.*}} in function definition
+// CHECK-FIXES: {{^}}void (*(*returns_fn_returns_fn_void_void())())(){{$}}
+{
+ return nullptr;
+}
+
+void bar(void)
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: {{.*}} in function definition
+// CHECK-FIXES: {{^}}void bar(){{$}}
+{
+}
+
+class gronk
+{
+public:
+ gronk();
+ ~gronk();
+
+ void foo();
+ void bar();
+ void bar2
+ ();
+
+private:
+ int m_i;
+ int *m_pi;
+ float m_f;
+ float *m_pf;
+ double m_d;
+ double *m_pd;
+
+ void (*f1)(void);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in field declaration
+ // CHECK-FIXES: {{^ }}void (*f1)();{{$}}
+
+ void (gronk::*p1)(void);
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: {{.*}} in field declaration
+ // CHECK-FIXES: {{^ }}void (gronk::*p1)();{{$}}
+
+ int (gronk::*p_mi);
+};
+
+int i;
+int *pi;
+void *pv = (void *) pi;
+float f;
+float *fi;
+double d;
+double *pd;
+
+void (*f1)(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}} in variable declaration
+// CHECK-FIXES: {{^}}void (*f1)();{{$}}
+
+void (*f2)(void) = nullptr;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}} in variable declaration with initializer
+// CHECK-FIXES: {{^}}void (*f2)() = nullptr;{{$}}
+
+void (*f2b)(void)(nullptr);
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} in variable declaration with initializer
+// CHECK-FIXES: {{^}}void (*f2b)()(nullptr);{{$}}
+
+void (*f2c)(void){nullptr};
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} in variable declaration with initializer
+// CHECK-FIXES: {{^}}void (*f2c)(){nullptr};{{$}}
+
+void (*f3)(void) = bar;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}} in variable declaration with initializer
+// CHECK-FIXES: {{^}}void (*f3)() = bar;{{$}}
+
+void (*fa)();
+
+void (*fb)() = nullptr;
+
+void (*fc)() = bar;
+
+typedef void (function_ptr)(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: {{.*}} in typedef
+// CHECK-FIXES: {{^}}typedef void (function_ptr)();{{$}}
+
+typedef void (function_ptr2)
+ (
+ void
+ );
+// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: {{.*}} in typedef
+// CHECK-FIXES: {{^typedef void \(function_ptr2\)$}}
+// CHECK-FIXES-NEXT: {{^ \($}}
+// CHECK-FIXES-NEXT: {{^ $}}
+// CHECK-FIXES-NEXT: {{^ \);$}}
+
+typedef
+void
+(
+*
+(
+*
+returns_fn_returns_fn_void_void_t2
+(
+void
+)
+)
+(
+void
+)
+)
+(
+void
+)
+;
+// CHECK-MESSAGES: :[[@LINE-11]]:1: warning: {{.*}} in typedef
+// CHECK-MESSAGES: :[[@LINE-8]]:1: warning: {{.*}} in typedef
+// CHECK-MESSAGES: :[[@LINE-5]]:1: warning: {{.*}} in typedef
+// CHECK-FIXES: {{^typedef$}}
+// CHECK-FIXES-NEXT: {{^void$}}
+// CHECK-FIXES-NEXT: {{^\($}}
+// CHECK-FIXES-NEXT: {{^\*$}}
+// CHECK-FIXES-NEXT: {{^\($}}
+// CHECK-FIXES-NEXT: {{^\*$}}
+// CHECK-FIXES-NEXT: {{^returns_fn_returns_fn_void_void_t2$}}
+// CHECK-FIXES-NEXT: {{^\($}}
+// CHECK-FIXES-NOT: {{[^ ]}}
+// CHECK-FIXES: {{^\)$}}
+// CHECK-FIXES-NEXT: {{^\)$}}
+// CHECK-FIXES-NEXT: {{^\($}}
+// CHECK-FIXES-NOT: {{[^ ]}}
+// CHECK-FIXES: {{^\)$}}
+// CHECK-FIXES-NEXT: {{^\)$}}
+// CHECK-FIXES-NEXT: {{^\($}}
+// CHECK-FIXES-NOT: {{[^ ]}}
+// CHECK-FIXES: {{^\)$}}
+// CHECK-FIXES-NEXT: {{^;$}}
+
+
+void (gronk::*p1)(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: {{.*}} in variable declaration
+// CHECK-FIXES: {{^}}void (gronk::*p1)();{{$}}
+
+void (gronk::*p2)(void) = &gronk::foo;
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: {{.*}} in variable declaration with initializer
+// CHECK-FIXES: {{^}}void (gronk::*p2)() = &gronk::foo;{{$}}
+
+typedef void (gronk::*member_function_ptr)(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: {{.*}} in typedef
+// CHECK-FIXES: {{^}}typedef void (gronk::*member_function_ptr)();{{$}}
+
+typedef void (gronk::*member_function_ptr2)
+ (
+ void
+ );
+// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: {{.*}} in typedef
+// CHECK-FIXES: {{^typedef void \(gronk::\*member_function_ptr2\)$}}
+// CHECK-FIXES-NEXT: {{^ \($}}
+// CHECK-FIXES-NEXT: {{^ $}}
+// CHECK-FIXES-NEXT: {{^ \);$}}
+
+void gronk::foo()
+{
+ void (*f1)(void) = &::bar;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in variable declaration with initializer
+ // CHECK-FIXES: {{^ }}void (*f1)() = &::bar;{{$}}
+
+ void (*f2)(void);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in variable declaration
+ // CHECK-FIXES: {{^ }}void (*f2)();{{$}}
+
+ void (*f3)
+ (
+ void
+ );
+ // CHECK-MESSAGES: :[[@LINE-2]]:13: warning: {{.*}} in variable declaration
+ // CHECK-FIXES: {{^ }}void (*f3){{$}}
+ // CHECK-FIXES-NEXT: {{^ \($}}
+ // CHECK-FIXES-NEXT: {{^ $}}
+ // CHECK-FIXES-NEXT: {{^ \);$}}
+}
+
+void gronk::bar(void)
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} in function definition
+// CHECK-FIXES: {{^}}void gronk::bar(){{$}}
+{
+ void (gronk::*p3)(void) = &gronk::foo;
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: {{.*}} in variable declaration with initializer
+ // CHECK-FIXES: {{^ }}void (gronk::*p3)() = &gronk::foo;{{$}}
+
+ void (gronk::*p4)(void);
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: {{.*}} in variable declaration
+ // CHECK-FIXES: {{^ }}void (gronk::*p4)();{{$}}
+
+ void (gronk::*p5)
+ (
+ void
+ );
+ // CHECK-MESSAGES: :[[@LINE-2]]:13: warning: {{.*}} in variable declaration
+ // CHECK-FIXES: {{^ }}void (gronk::*p5){{$}}
+ // CHECK-FIXES-NEXT: {{^ \($}}
+ // CHECK-FIXES-NExT: {{^ $}}
+ // CHECK-FIXES-NExT: {{^ \);$}}
+}
+
+void gronk::bar2
+ (
+ void
+ )
+// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: {{.*}} in function definition
+// CHECK-FIXES: {{^void gronk::bar2$}}
+// CHECK-FIXES-NEXT: {{^ \($}}
+// CHECK-FIXES-NEXT: {{^ $}}
+// CHECK-FIXES-NEXT: {{^ \)$}}
+{
+}
+
+gronk::gronk(void)
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in function definition
+// CHECK-FIXES: {{^}}gronk::gronk(){{$}}
+ : f1(nullptr),
+ p1(nullptr)
+{
+}
+
+gronk::~gronk(void)
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}} in function definition
+// CHECK-FIXES: {{^}}gronk::~gronk(){{$}}
+{
+}
+
+class nutter
+{
+public:
+ nutter();
+};
+
+nutter::nutter(void)
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in function definition
+// CHECK-FIXES: {{^}}nutter::nutter(){{$}}
+{
+ void (*f3)(void) = static_cast<void (*)(void)>(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in variable declaration with initializer
+ // CHECK-MESSAGES: :[[@LINE-2]]:45: warning: {{.*}} in named cast
+ // CHECK-FIXES: void (*f3)() = static_cast<void (*)()>(0);{{$}}
+
+ void (*f4)(void) = (void (*)(void)) 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in variable declaration with initializer
+ // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: {{.*}} in C style cast
+ // CHECK-FIXES: void (*f4)() = (void (*)()) 0;{{$}}
+
+ void (*f5)(void) = reinterpret_cast<void (*)(void)>(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in variable declaration with initializer
+ // CHECK-MESSAGES: :[[@LINE-2]]:50: warning: {{.*}} in named cast
+ // CHECK-FIXES: void (*f5)() = reinterpret_cast<void (*)()>(0);{{$}}
+
+ void (*f6)(void) = static_cast<void (*)
+ (
+ void
+ )>(0);
+ // CHECK-MESSAGES: :[[@LINE-4]]:16: warning: {{.*}} in variable declaration with initializer
+ // CHECK-MESSAGES: :[[@LINE-3]]:13: warning: {{.*}} in named cast
+ // CHECK-FIXES: {{^ }}void (*f6)() = static_cast<void (*){{$}}
+ // CHECK-FIXES-NEXT: {{^ \($}}
+ // CHECK-FIXES-NEXT: {{^ $}}
+ // CHECK-FIXES-NEXT: {{^ }})>(0);{{$}}
+
+ void (*f7)(void) = (void (*)
+ (
+ void
+ )) 0;
+ // CHECK-MESSAGES: :[[@LINE-4]]:16: warning: {{.*}} in variable declaration with initializer
+ // CHECK-MESSAGES: :[[@LINE-3]]:13: warning: {{.*}} in C style cast
+ // CHECK-FIXES: {{^ }}void (*f7)() = (void (*){{$}}
+ // CHECK-FIXES-NEXT: {{^ \($}}
+ // CHECK-FIXES-NEXT: {{^ $}}
+ // CHECK-FIXES-NEXT: {{^ \)\) 0;$}}
+
+ void (*f8)(void) = reinterpret_cast<void (*)
+ (
+ void
+ )>(0);
+ // CHECK-MESSAGES: :[[@LINE-4]]:16: warning: {{.*}} in variable declaration with initializer
+ // CHECK-MESSAGES: :[[@LINE-3]]:13: warning: {{.*}} in named cast
+ // CHECK-FIXES: {{^ }}void (*f8)() = reinterpret_cast<void (*){{$}}
+ // CHECK-FIXES-NEXT: {{^ \($}}
+ // CHECK-FIXES-NEXT: {{^ $}}
+ // CHECK-FIXES-NEXT: {{^ \)>\(0\);$}}
+}
+
+class generator
+{
+public:
+ int operator()(void) { return 1; }
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: {{.*}} in function definition
+ // CHECK-FIXES: {{^ }}int operator()() { return 1; }{{$}}
+};
+
+void test_lambda_functions()
+{
+ auto lamb_duh = [](void (*fn)(void)) { (*fn)(); };
+ // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: {{.*}} in variable declaration
+ // CHECK-FIXES: {{^ }}auto lamb_duh = [](void (*fn)()) { (*fn)(); };{{$}}
+
+ auto lambda_generator = [](void) { return 1; };
+ // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} in lambda expression
+ // CHECK-FIXES: {{^ }}auto lambda_generator = []() { return 1; };{{$}}
+
+ auto gen2 = []() { return 1; };
+
+ auto gen3 = []{ return 1; };
+
+ auto void_returner = [](void) -> void (*)(void) { return f1; };
+ // CHECK-MESSAGES: [[@LINE-1]]:29: warning: {{.*}} in lambda expression
+ // CHECK-MESSAGES: [[@LINE-2]]:47: warning: {{.*}} in lambda expression
+ // CHECK-FIXES: {{^ }}auto void_returner = []() -> void (*)() { return f1; };{{$}}
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits