Procházet zdrojové kódy

Enable a couple of boring warnings. (#4018)

Just spotted these while looking at warnings that seem to fire on our
code are probably are things we'd fix if we saw them. None of these seem
important FWIW.

Also removes a redundant flag that is part of `-Wall`.

I have a follow-up for the high-value warning I spotted that motivated
me to look at all of this. But it's noisy so kept it as a separate PR.
Chandler Carruth před 1 rokem
rodič
revize
dd0890619a

+ 2 - 1
bazel/cc_toolchains/clang_cc_toolchain_config.bzl

@@ -141,7 +141,8 @@ def _impl(ctx):
                             "-Wself-assign",
                             "-Wself-assign",
                             "-Wimplicit-fallthrough",
                             "-Wimplicit-fallthrough",
                             "-Wctad-maybe-unsupported",
                             "-Wctad-maybe-unsupported",
-                            "-Wdelete-non-virtual-dtor",
+                            "-Wextra-semi",
+                            "-Wzero-as-null-pointer-constant",
                             # Don't warn on external code as we can't
                             # Don't warn on external code as we can't
                             # necessarily patch it easily. Note that these have
                             # necessarily patch it easily. Note that these have
                             # to be initial directories in the `#include` line.
                             # to be initial directories in the `#include` line.

+ 1 - 1
common/struct_reflection.h

@@ -72,7 +72,7 @@ constexpr auto CanListInitialize(...) -> bool {
 // 2) Add more AnyField<T>s until we can't initialize any more.
 // 2) Add more AnyField<T>s until we can't initialize any more.
 template <typename T, bool AnyWorkedSoFar = false, typename... Fields>
 template <typename T, bool AnyWorkedSoFar = false, typename... Fields>
 constexpr auto CountFields() -> int {
 constexpr auto CountFields() -> int {
-  if constexpr (CanListInitialize<T, Fields...>(0)) {
+  if constexpr (CanListInitialize<T, Fields...>(nullptr)) {
     return CountFields<T, true, Fields..., AnyField<T>>();
     return CountFields<T, true, Fields..., AnyField<T>>();
   } else if constexpr (AnyWorkedSoFar) {
   } else if constexpr (AnyWorkedSoFar) {
     constexpr int NumFields = sizeof...(Fields) - 1;
     constexpr int NumFields = sizeof...(Fields) - 1;

+ 1 - 1
explorer/ast/bindings.cpp

@@ -63,7 +63,7 @@ void Bindings::Print(llvm::raw_ostream& out) const {
     out << sep << "`" << *binding << "`: `" << *value << "`";
     out << sep << "`" << *binding << "`: `" << *value << "`";
   }
   }
   out << "]";
   out << "]";
-};
+}
 
 
 auto Bindings::None() -> Nonnull<const Bindings*> {
 auto Bindings::None() -> Nonnull<const Bindings*> {
   static Nonnull<const Bindings*> bindings = new Bindings;
   static Nonnull<const Bindings*> bindings = new Bindings;

+ 1 - 1
explorer/ast/statement.h

@@ -264,7 +264,7 @@ class VariableDefinition : public Statement {
     return expression_category_;
     return expression_category_;
   }
   }
 
 
-  auto is_returned() const -> bool { return def_type_ == Returned; };
+  auto is_returned() const -> bool { return def_type_ == Returned; }
 
 
  private:
  private:
   Nonnull<Pattern*> pattern_;
   Nonnull<Pattern*> pattern_;

+ 1 - 1
explorer/file_test.cpp

@@ -108,6 +108,6 @@ class ExplorerFileTest : public FileTestBase {
 
 
 }  // namespace
 }  // namespace
 
 
-CARBON_FILE_TEST_FACTORY(ExplorerFileTest);
+CARBON_FILE_TEST_FACTORY(ExplorerFileTest)
 
 
 }  // namespace Carbon::Testing
 }  // namespace Carbon::Testing

+ 1 - 1
explorer/interpreter/heap.h

@@ -30,7 +30,7 @@ class Heap : public HeapAllocationInterface, public Printable<Heap> {
 
 
   // Constructs an empty Heap.
   // Constructs an empty Heap.
   explicit Heap(Nonnull<TraceStream*> trace_stream, Nonnull<Arena*> arena)
   explicit Heap(Nonnull<TraceStream*> trace_stream, Nonnull<Arena*> arena)
-      : arena_(arena), trace_stream_(trace_stream){};
+      : arena_(arena), trace_stream_(trace_stream) {}
 
 
   Heap(const Heap&) = delete;
   Heap(const Heap&) = delete;
   auto operator=(const Heap&) -> Heap& = delete;
   auto operator=(const Heap&) -> Heap& = delete;

+ 1 - 0
explorer/syntax/BUILD

@@ -88,6 +88,7 @@ cc_library(
         "-Wno-unused-but-set-variable",
         "-Wno-unused-but-set-variable",
         "-Wno-unused-function",
         "-Wno-unused-function",
         "-Wno-writable-strings",
         "-Wno-writable-strings",
+        "-Wno-zero-as-null-pointer-constant",
     ],
     ],
     # Running clang-tidy is slow, and explorer is currently feature frozen, so
     # Running clang-tidy is slow, and explorer is currently feature frozen, so
     # don't spend time linting it.
     # don't spend time linting it.

+ 3 - 3
explorer/syntax/lex_scan_helper.h

@@ -24,11 +24,11 @@ class StringLexHelper {
   // EOF.
   // EOF.
   auto Advance() -> bool;
   auto Advance() -> bool;
   // Returns the last scanned char.
   // Returns the last scanned char.
-  auto last_char() -> char { return str_.back(); };
+  auto last_char() -> char { return str_.back(); }
   // Returns the scanned string.
   // Returns the scanned string.
-  auto str() -> const std::string& { return str_; };
+  auto str() -> const std::string& { return str_; }
 
 
-  auto is_eof() -> bool { return is_eof_; };
+  auto is_eof() -> bool { return is_eof_; }
 
 
  private:
  private:
   std::string str_;
   std::string str_;

+ 1 - 1
language_server/language_server.cpp

@@ -35,7 +35,7 @@ void LanguageServer::OnInitialize(
 
 
   llvm::json::Object reply{{"capabilities", std::move(capabilities)}};
   llvm::json::Object reply{{"capabilities", std::move(capabilities)}};
   cb(reply);
   cb(reply);
-};
+}
 
 
 auto LanguageServer::onNotify(llvm::StringRef method, llvm::json::Value value)
 auto LanguageServer::onNotify(llvm::StringRef method, llvm::json::Value value)
     -> bool {
     -> bool {

+ 1 - 1
testing/file_test/file_test_base_test.cpp

@@ -162,6 +162,6 @@ class FileTestBaseTest : public FileTestBase {
 
 
 }  // namespace
 }  // namespace
 
 
-CARBON_FILE_TEST_FACTORY(FileTestBaseTest);
+CARBON_FILE_TEST_FACTORY(FileTestBaseTest)
 
 
 }  // namespace Carbon::Testing
 }  // namespace Carbon::Testing

+ 1 - 1
toolchain/check/context.cpp

@@ -821,7 +821,7 @@ class TypeCompleter {
     CARBON_CHECK(value_rep.kind != SemIR::ValueRepr::Unknown)
     CARBON_CHECK(value_rep.kind != SemIR::ValueRepr::Unknown)
         << "Complete type should have a value representation";
         << "Complete type should have a value representation";
     return value_rep;
     return value_rep;
-  };
+  }
 
 
   auto BuildBuiltinValueRepr(SemIR::TypeId type_id,
   auto BuildBuiltinValueRepr(SemIR::TypeId type_id,
                              SemIR::Builtin builtin) const -> SemIR::ValueRepr {
                              SemIR::Builtin builtin) const -> SemIR::ValueRepr {

+ 1 - 1
toolchain/install/install_paths.h

@@ -91,7 +91,7 @@ class InstallPaths {
   // in the `StringRef` for inclusion in any user report.
   // in the `StringRef` for inclusion in any user report.
   [[nodiscard]] auto error() const -> std::optional<llvm::StringRef> {
   [[nodiscard]] auto error() const -> std::optional<llvm::StringRef> {
     return error_;
     return error_;
-  };
+  }
 
 
   // The computed installation prefix. This should correspond to the
   // The computed installation prefix. This should correspond to the
   // `prefix_root` directory in Bazel's output, or to some prefix the toolchain
   // `prefix_root` directory in Bazel's output, or to some prefix the toolchain

+ 1 - 1
toolchain/lex/lex.cpp

@@ -600,7 +600,7 @@ static constexpr auto MakeDispatchTable() -> DispatchTableT {
   table['\n'] = &DispatchLexVerticalWhitespace;
   table['\n'] = &DispatchLexVerticalWhitespace;
 
 
   return table;
   return table;
-};
+}
 
 
 static constexpr DispatchTableT DispatchTable = MakeDispatchTable();
 static constexpr DispatchTableT DispatchTable = MakeDispatchTable();
 
 

+ 1 - 1
toolchain/lex/numeric_literal.cpp

@@ -379,7 +379,7 @@ auto NumericLiteral::Parser::CheckDigitSeparatorPlacement(
   if (remaining_digit_separators) {
   if (remaining_digit_separators) {
     diagnose_irregular_digit_separators();
     diagnose_irregular_digit_separators();
   }
   }
-};
+}
 
 
 // Check that we don't have a '0' prefix on a non-zero decimal integer.
 // Check that we don't have a '0' prefix on a non-zero decimal integer.
 auto NumericLiteral::Parser::CheckLeadingZero() -> bool {
 auto NumericLiteral::Parser::CheckLeadingZero() -> bool {

+ 4 - 4
toolchain/lex/token_kind.h

@@ -71,23 +71,23 @@ class TokenKind : public CARBON_ENUM_BASE(TokenKind) {
 
 
   // Test whether this kind of token is a one-character symbol whose character
   // Test whether this kind of token is a one-character symbol whose character
   // is not part of any other symbol.
   // is not part of any other symbol.
-  auto is_one_char_symbol() const -> bool { return IsOneCharSymbol[AsInt()]; };
+  auto is_one_char_symbol() const -> bool { return IsOneCharSymbol[AsInt()]; }
 
 
   // Test whether this kind of token is a keyword.
   // Test whether this kind of token is a keyword.
-  auto is_keyword() const -> bool { return IsKeyword[AsInt()]; };
+  auto is_keyword() const -> bool { return IsKeyword[AsInt()]; }
 
 
   // Test whether this kind of token is a sized type literal.
   // Test whether this kind of token is a sized type literal.
   auto is_sized_type_literal() const -> bool {
   auto is_sized_type_literal() const -> bool {
     return *this == TokenKind::IntTypeLiteral ||
     return *this == TokenKind::IntTypeLiteral ||
            *this == TokenKind::UnsignedIntTypeLiteral ||
            *this == TokenKind::UnsignedIntTypeLiteral ||
            *this == TokenKind::FloatTypeLiteral;
            *this == TokenKind::FloatTypeLiteral;
-  };
+  }
 
 
   // If this token kind has a fixed spelling when in source code, returns it.
   // If this token kind has a fixed spelling when in source code, returns it.
   // Otherwise returns an empty string.
   // Otherwise returns an empty string.
   auto fixed_spelling() const -> llvm::StringLiteral {
   auto fixed_spelling() const -> llvm::StringLiteral {
     return FixedSpelling[AsInt()];
     return FixedSpelling[AsInt()];
-  };
+  }
 
 
   // Get the expected number of parse tree nodes that will be created for this
   // Get the expected number of parse tree nodes that will be created for this
   // token.
   // token.

+ 1 - 1
toolchain/parse/context.h

@@ -56,7 +56,7 @@ class Context {
     auto Print(llvm::raw_ostream& output) const -> void {
     auto Print(llvm::raw_ostream& output) const -> void {
       output << state << " @" << token << " subtree_start=" << subtree_start
       output << state << " @" << token << " subtree_start=" << subtree_start
              << " has_error=" << has_error;
              << " has_error=" << has_error;
-    };
+    }
 
 
     // The state.
     // The state.
     State state;
     State state;

+ 1 - 1
toolchain/testing/file_test.cpp

@@ -161,7 +161,7 @@ class ToolchainFileTest : public FileTestBase {
 
 
 }  // namespace
 }  // namespace
 
 
-CARBON_FILE_TEST_FACTORY(ToolchainFileTest);
+CARBON_FILE_TEST_FACTORY(ToolchainFileTest)
 
 
 }  // namespace Carbon::Testing
 }  // namespace Carbon::Testing