diff --git a/executable_semantics/ast/declaration.h b/executable_semantics/ast/declaration.h index 3c49ea04d47d..9909533257d4 100644 --- a/executable_semantics/ast/declaration.h +++ b/executable_semantics/ast/declaration.h @@ -6,6 +6,7 @@ #define EXECUTABLE_SEMANTICS_AST_DECLARATION_H_ #include +#include #include #include "common/ostream.h" @@ -38,7 +39,7 @@ class Declaration { }; Declaration(const Member&) = delete; - Declaration& operator=(const Member&) = delete; + auto operator=(const Member&) -> Declaration& = delete; void Print(llvm::raw_ostream& out) const; LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); } @@ -152,7 +153,7 @@ class ChoiceDeclaration : public Declaration { class Alternative { public: Alternative(std::string name, Nonnull signature) - : name_(name), signature_(signature) {} + : name_(std::move(name)), signature_(signature) {} auto name() const -> const std::string& { return name_; } auto signature() const -> const Expression& { return *signature_; } diff --git a/executable_semantics/ast/member.h b/executable_semantics/ast/member.h index c8c2a88d9989..0a57500e3fb4 100644 --- a/executable_semantics/ast/member.h +++ b/executable_semantics/ast/member.h @@ -28,7 +28,7 @@ class Member { enum class Kind { FieldMember }; Member(const Member&) = delete; - Member& operator=(const Member&) = delete; + auto operator=(const Member&) -> Member& = delete; void Print(llvm::raw_ostream& out) const; LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); } diff --git a/executable_semantics/ast/pattern.h b/executable_semantics/ast/pattern.h index be60e9e1f4f5..a6917a7d48a1 100644 --- a/executable_semantics/ast/pattern.h +++ b/executable_semantics/ast/pattern.h @@ -37,7 +37,7 @@ class Pattern { }; Pattern(const Pattern&) = delete; - Pattern& operator=(const Pattern&) = delete; + auto operator=(const Pattern&) -> Pattern& = delete; void Print(llvm::raw_ostream& out) const; LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); } @@ -206,7 +206,7 @@ class AlternativePattern : public Pattern { // expression. class ExpressionPattern : public Pattern { public: - ExpressionPattern(Nonnull expression) + explicit ExpressionPattern(Nonnull expression) : Pattern(Kind::ExpressionPattern, expression->source_loc()), expression_(expression) {} diff --git a/executable_semantics/ast/source_location.h b/executable_semantics/ast/source_location.h index 2d9b8d00654c..aab6ce4e5c61 100644 --- a/executable_semantics/ast/source_location.h +++ b/executable_semantics/ast/source_location.h @@ -26,7 +26,7 @@ class SourceLocation { auto operator=(const SourceLocation&) -> SourceLocation& = default; auto operator=(SourceLocation&&) -> SourceLocation& = default; - bool operator==(SourceLocation other) const { + auto operator==(SourceLocation other) const -> bool { return filename_ == other.filename_ && line_num_ == other.line_num_; } diff --git a/executable_semantics/interpreter/interpreter.cpp b/executable_semantics/interpreter/interpreter.cpp index 55230cda01fe..22fa52f9d631 100644 --- a/executable_semantics/interpreter/interpreter.cpp +++ b/executable_semantics/interpreter/interpreter.cpp @@ -24,7 +24,6 @@ #include "llvm/Support/Casting.h" using llvm::cast; -using llvm::dyn_cast; namespace Carbon { diff --git a/executable_semantics/interpreter/type_checker.cpp b/executable_semantics/interpreter/type_checker.cpp index 725cfb63700c..52e6582478c1 100644 --- a/executable_semantics/interpreter/type_checker.cpp +++ b/executable_semantics/interpreter/type_checker.cpp @@ -1191,7 +1191,7 @@ void TypeChecker::TypeCheck(Nonnull d, const TypeEnv& types, void TypeChecker::TopLevel(Nonnull d, TypeCheckContext* tops) { switch (d->kind()) { case Declaration::Kind::FunctionDeclaration: { - FunctionDeclaration& func_def = cast(*d); + auto& func_def = cast(*d); auto t = TypeOfFunDef(tops->types, tops->values, &func_def); tops->types.Set(func_def.name(), t); interpreter_.InitEnv(*d, &tops->values); @@ -1199,8 +1199,7 @@ void TypeChecker::TopLevel(Nonnull d, TypeCheckContext* tops) { } case Declaration::Kind::ClassDeclaration: { - const ClassDefinition& class_def = - cast(*d).definition(); + const auto& class_def = cast(*d).definition(); auto st = TypeOfClassDef(&class_def, tops->types, tops->values); Address a = interpreter_.AllocateValue(st); tops->values.Set(class_def.name(), a); // Is this obsolete? diff --git a/executable_semantics/interpreter/type_checker.h b/executable_semantics/interpreter/type_checker.h index 95c47532a91c..ab82888fbabc 100644 --- a/executable_semantics/interpreter/type_checker.h +++ b/executable_semantics/interpreter/type_checker.h @@ -71,7 +71,7 @@ class TypeChecker { }; struct TCResult { - TCResult(TypeEnv types) : types(types) {} + explicit TCResult(TypeEnv types) : types(types) {} TypeEnv types; }; diff --git a/executable_semantics/main.cpp b/executable_semantics/main.cpp index de77b5044dda..97ede3d0911c 100644 --- a/executable_semantics/main.cpp +++ b/executable_semantics/main.cpp @@ -11,12 +11,12 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/InitLLVM.h" -int main(int argc, char* argv[]) { +auto main(int argc, char* argv[]) -> int { llvm::setBugReportMsg( "Please report issues to " "https://github.com/carbon-language/carbon-lang/issues and include the " "crash backtrace.\n"); - llvm::InitLLVM(argc, argv); + llvm::InitLLVM init_llvm(argc, argv); // Printing to stderr should flush stdout. This is most noticeable when stderr // is piped to stdout. diff --git a/executable_semantics/syntax/bison_wrap.h b/executable_semantics/syntax/bison_wrap.h index 8fb284c1fea8..f01de972d915 100644 --- a/executable_semantics/syntax/bison_wrap.h +++ b/executable_semantics/syntax/bison_wrap.h @@ -24,6 +24,7 @@ class BisonWrap { } // Support transparent conversion to the wrapped type. + // NOLINTNEXTLINE(google-explicit-constructor) operator T() { return Release(); } // Deliberately releases the contained value. Errors if not initialized. diff --git a/executable_semantics/syntax/parse_and_lex_context.h b/executable_semantics/syntax/parse_and_lex_context.h index 406c776bfdb0..9799717ad42d 100644 --- a/executable_semantics/syntax/parse_and_lex_context.h +++ b/executable_semantics/syntax/parse_and_lex_context.h @@ -44,10 +44,10 @@ class ParseAndLexContext { } // namespace Carbon // Gives flex the yylex prototype we want. -#define YY_DECL \ - Carbon::Parser::symbol_type yylex(Carbon::Nonnull arena, \ - yyscan_t yyscanner, \ - Carbon::ParseAndLexContext& context) +#define YY_DECL \ + auto yylex(Carbon::Nonnull arena, yyscan_t yyscanner, \ + Carbon::ParseAndLexContext& context) \ + -> Carbon::Parser::symbol_type // Declares yylex for the parser's sake. YY_DECL;