diff --git a/client/crash_report_database_win.cc b/client/crash_report_database_win.cc index 1e1b4d7a..538eff5f 100644 --- a/client/crash_report_database_win.cc +++ b/client/crash_report_database_win.cc @@ -43,8 +43,8 @@ constexpr wchar_t kSettings[] = L"settings.dat"; constexpr wchar_t kCrashReportFileExtension[] = L"dmp"; -const uint32_t kMetadataFileHeaderMagic = 'CPAD'; -const uint32_t kMetadataFileVersion = 1; +constexpr uint32_t kMetadataFileHeaderMagic = 'CPAD'; +constexpr uint32_t kMetadataFileVersion = 1; using OperationStatus = CrashReportDatabase::OperationStatus; diff --git a/minidump/minidump_extensions.cc b/minidump/minidump_extensions.cc index a956817e..bfb0e60e 100644 --- a/minidump/minidump_extensions.cc +++ b/minidump/minidump_extensions.cc @@ -16,7 +16,7 @@ namespace crashpad { -const uint32_t MinidumpModuleCrashpadInfo::kVersion; -const uint32_t MinidumpCrashpadInfo::kVersion; +constexpr uint32_t MinidumpModuleCrashpadInfo::kVersion; +constexpr uint32_t MinidumpCrashpadInfo::kVersion; } // namespace crashpad diff --git a/minidump/minidump_extensions.h b/minidump/minidump_extensions.h index 245ef8b5..f3615669 100644 --- a/minidump/minidump_extensions.h +++ b/minidump/minidump_extensions.h @@ -290,7 +290,7 @@ struct ALIGNAS(4) PACKED MinidumpModuleCrashpadInfo { //! \brief The structure’s currently-defined version number. //! //! \sa version - static const uint32_t kVersion = 1; + static constexpr uint32_t kVersion = 1; //! \brief The structure’s version number. //! @@ -387,7 +387,7 @@ struct ALIGNAS(4) PACKED MinidumpCrashpadInfo { //! \brief The structure’s currently-defined version number. //! //! \sa version - static const uint32_t kVersion = 1; + static constexpr uint32_t kVersion = 1; //! \brief The structure’s version number. //! diff --git a/minidump/minidump_memory_writer_test.cc b/minidump/minidump_memory_writer_test.cc index 4d3dc57c..ffa56d51 100644 --- a/minidump/minidump_memory_writer_test.cc +++ b/minidump/minidump_memory_writer_test.cc @@ -35,7 +35,7 @@ namespace crashpad { namespace test { namespace { -const MinidumpStreamType kBogusStreamType = +constexpr MinidumpStreamType kBogusStreamType = static_cast(1234); // expected_streams is the expected number of streams in the file. The memory diff --git a/minidump/minidump_writable.cc b/minidump/minidump_writable.cc index 47e21ff4..42a714f1 100644 --- a/minidump/minidump_writable.cc +++ b/minidump/minidump_writable.cc @@ -24,7 +24,7 @@ namespace { -const size_t kMaximumAlignment = 16; +constexpr size_t kMaximumAlignment = 16; } // namespace @@ -82,7 +82,7 @@ void MinidumpWritable::RegisterLocationDescriptor( registered_location_descriptors_.push_back(location_descriptor); } -const size_t MinidumpWritable::kInvalidSize = +constexpr size_t MinidumpWritable::kInvalidSize = std::numeric_limits::max(); MinidumpWritable::MinidumpWritable() diff --git a/snapshot/mac/mach_o_image_reader.cc b/snapshot/mac/mach_o_image_reader.cc index f16aa554..7cb4040f 100644 --- a/snapshot/mac/mach_o_image_reader.cc +++ b/snapshot/mac/mach_o_image_reader.cc @@ -33,7 +33,7 @@ namespace { -const uint32_t kInvalidSegmentIndex = std::numeric_limits::max(); +constexpr uint32_t kInvalidSegmentIndex = std::numeric_limits::max(); } // namespace diff --git a/snapshot/mac/mach_o_image_reader_test.cc b/snapshot/mac/mach_o_image_reader_test.cc index 6d6e49d0..d6b801f8 100644 --- a/snapshot/mac/mach_o_image_reader_test.cc +++ b/snapshot/mac/mach_o_image_reader_test.cc @@ -47,16 +47,16 @@ namespace { // are different. #if defined(ARCH_CPU_64_BITS) using MachHeader = mach_header_64; -const uint32_t kMachMagic = MH_MAGIC_64; +constexpr uint32_t kMachMagic = MH_MAGIC_64; using SegmentCommand = segment_command_64; -const uint32_t kSegmentCommand = LC_SEGMENT_64; +constexpr uint32_t kSegmentCommand = LC_SEGMENT_64; using Section = section_64; using Nlist = nlist_64; #else using MachHeader = mach_header; -const uint32_t kMachMagic = MH_MAGIC; +constexpr uint32_t kMachMagic = MH_MAGIC; using SegmentCommand = segment_command; -const uint32_t kSegmentCommand = LC_SEGMENT; +constexpr uint32_t kSegmentCommand = LC_SEGMENT; using Section = section; // This needs to be called “struct nlist” because “nlist” without the struct @@ -65,9 +65,9 @@ using Nlist = struct nlist; #endif #if defined(ARCH_CPU_X86_64) -const int kCPUType = CPU_TYPE_X86_64; +constexpr int kCPUType = CPU_TYPE_X86_64; #elif defined(ARCH_CPU_X86) -const int kCPUType = CPU_TYPE_X86; +constexpr int kCPUType = CPU_TYPE_X86; #endif // Verifies that |expect_section| and |actual_section| agree. @@ -327,7 +327,8 @@ void ExpectSegmentCommands(const MachHeader* expect_image, // In some cases, the expected slide value for an image is unknown, because no // reasonable API to return it is provided. When this happens, use kSlideUnknown // to avoid checking the actual slide value against anything. -const mach_vm_size_t kSlideUnknown = std::numeric_limits::max(); +constexpr mach_vm_size_t kSlideUnknown = + std::numeric_limits::max(); // Verifies that |expect_image| is a vaild Mach-O header for the current system // by checking its |magic| and |cputype| fields. Then, verifies that the diff --git a/test/scoped_temp_dir_win.cc b/test/scoped_temp_dir_win.cc index 0413ec42..d9707af6 100644 --- a/test/scoped_temp_dir_win.cc +++ b/test/scoped_temp_dir_win.cc @@ -38,7 +38,7 @@ base::FilePath GenerateCandidateName() { return system_temp_dir.Append(new_dir_name); } -const int kRetries = 50; +constexpr int kRetries = 50; } // namespace diff --git a/util/file/file_io.h b/util/file/file_io.h index c70dff30..044a0a69 100644 --- a/util/file/file_io.h +++ b/util/file/file_io.h @@ -45,11 +45,12 @@ using FileOffset = off_t; //! \brief Scoped wrapper of a FileHandle. using ScopedFileHandle = base::ScopedFD; +//! \brief The return value of read and write calls. +using FileOperationResult = ssize_t; + //! \brief A value that can never be a valid FileHandle. const FileHandle kInvalidFileHandle = -1; -using FileOperationResult = ssize_t; - #elif defined(OS_WIN) using FileHandle = HANDLE; @@ -109,19 +110,28 @@ enum class StdioStream { namespace internal { +#if defined(OS_POSIX) || DOXYGEN + //! \brief The name of the native read function used by ReadFile(). //! //! This value may be useful for logging. //! //! \sa kNativeWriteFunctionName -extern const char kNativeReadFunctionName[]; +constexpr char kNativeReadFunctionName[] = "read"; //! \brief The name of the native write function used by WriteFile(). //! //! This value may be useful for logging. //! //! \sa kNativeReadFunctionName -extern const char kNativeWriteFunctionName[]; +constexpr char kNativeWriteFunctionName[] = "write"; + +#elif defined(OS_WIN) + +constexpr char kNativeReadFunctionName[] = "ReadFile"; +constexpr char kNativeWriteFunctionName[] = "WriteFile"; + +#endif //! \brief The internal implementation of ReadFileExactly() and its wrappers. //! diff --git a/util/file/file_io_posix.cc b/util/file/file_io_posix.cc index 49441244..60a36996 100644 --- a/util/file/file_io_posix.cc +++ b/util/file/file_io_posix.cc @@ -96,9 +96,6 @@ FileHandle OpenFileForOutput(int rdwr_or_wronly, namespace internal { -const char kNativeReadFunctionName[] = "read"; -const char kNativeWriteFunctionName[] = "write"; - FileOperationResult NativeWriteFile(FileHandle file, const void* buffer, size_t size) { diff --git a/util/file/file_io_win.cc b/util/file/file_io_win.cc index 467fc3c8..7428034a 100644 --- a/util/file/file_io_win.cc +++ b/util/file/file_io_win.cc @@ -84,9 +84,6 @@ FileHandle OpenFileForOutput(DWORD access, namespace internal { -const char kNativeReadFunctionName[] = "ReadFile"; -const char kNativeWriteFunctionName[] = "WriteFile"; - FileOperationResult NativeWriteFile(FileHandle file, const void* buffer, size_t size) { diff --git a/util/mach/child_port_server_test.cc b/util/mach/child_port_server_test.cc index d579ce91..984d64ac 100644 --- a/util/mach/child_port_server_test.cc +++ b/util/mach/child_port_server_test.cc @@ -32,12 +32,12 @@ using testing::Return; // Fake Mach ports. These aren’t used as ports in these tests, they’re just used // as cookies to make sure that the correct values get passed to the correct // places. -const mach_port_t kServerLocalPort = 0x05050505; -const mach_port_t kCheckInPort = 0x06060606; +constexpr mach_port_t kServerLocalPort = 0x05050505; +constexpr mach_port_t kCheckInPort = 0x06060606; // Other fake values. -const mach_msg_type_name_t kCheckInPortRightType = MACH_MSG_TYPE_PORT_SEND; -const child_port_token_t kCheckInToken = 0xfedcba9876543210; +constexpr mach_msg_type_name_t kCheckInPortRightType = MACH_MSG_TYPE_PORT_SEND; +constexpr child_port_token_t kCheckInToken = 0xfedcba9876543210; // The definition of the request structure from child_port.h isn’t available // here. It needs custom initialization code, so duplicate the expected diff --git a/util/mach/exc_server_variants_test.cc b/util/mach/exc_server_variants_test.cc index a947b45e..358cd1ec 100644 --- a/util/mach/exc_server_variants_test.cc +++ b/util/mach/exc_server_variants_test.cc @@ -43,28 +43,28 @@ using testing::Return; // Fake Mach ports. These aren’t used as ports in these tests, they’re just used // as cookies to make sure that the correct values get passed to the correct // places. -const mach_port_t kClientRemotePort = 0x01010101; -const mach_port_t kServerLocalPort = 0x02020202; -const thread_t kExceptionThreadPort = 0x03030303; -const task_t kExceptionTaskPort = 0x04040404; +constexpr mach_port_t kClientRemotePort = 0x01010101; +constexpr mach_port_t kServerLocalPort = 0x02020202; +constexpr thread_t kExceptionThreadPort = 0x03030303; +constexpr task_t kExceptionTaskPort = 0x04040404; // Other fake exception values. -const exception_type_t kExceptionType = EXC_BAD_ACCESS; +constexpr exception_type_t kExceptionType = EXC_BAD_ACCESS; // Test using an exception code with the high bit set to ensure that it gets // promoted to the wider mach_exception_data_type_t type as a signed quantity. -const exception_data_type_t kTestExceptonCodes[] = { +constexpr exception_data_type_t kTestExceptonCodes[] = { KERN_PROTECTION_FAILURE, implicit_cast(0xfedcba98), }; -const mach_exception_data_type_t kTestMachExceptionCodes[] = { +constexpr mach_exception_data_type_t kTestMachExceptionCodes[] = { KERN_PROTECTION_FAILURE, implicit_cast(0xfedcba9876543210), }; -const thread_state_flavor_t kThreadStateFlavor = MACHINE_THREAD_STATE; -const mach_msg_type_number_t kThreadStateFlavorCount = +constexpr thread_state_flavor_t kThreadStateFlavor = MACHINE_THREAD_STATE; +constexpr mach_msg_type_number_t kThreadStateFlavorCount = MACHINE_THREAD_STATE_COUNT; void InitializeMachMsgPortDescriptor(mach_msg_port_descriptor_t* descriptor, diff --git a/util/mach/mach_extensions.cc b/util/mach/mach_extensions.cc index 9e505736..5450ab28 100644 --- a/util/mach/mach_extensions.cc +++ b/util/mach/mach_extensions.cc @@ -34,9 +34,9 @@ struct BootstrapCheckInTraits { mach_port_t* service_port) { return bootstrap_check_in(bootstrap_port, service_name, service_port); } - static const char kName[]; + static constexpr char kName[] = "bootstrap_check_in"; }; -const char BootstrapCheckInTraits::kName[] = "bootstrap_check_in"; +constexpr char BootstrapCheckInTraits::kName[]; struct BootstrapLookUpTraits { using Type = base::mac::ScopedMachSendRight; @@ -45,9 +45,9 @@ struct BootstrapLookUpTraits { mach_port_t* service_port) { return bootstrap_look_up(bootstrap_port, service_name, service_port); } - static const char kName[]; + static constexpr char kName[] = "bootstrap_look_up"; }; -const char BootstrapLookUpTraits::kName[] = "bootstrap_look_up"; +constexpr char BootstrapLookUpTraits::kName[]; template typename Traits::Type BootstrapCheckInOrLookUp( diff --git a/util/mach/mach_extensions.h b/util/mach/mach_extensions.h index 5eeca9ae..25e401c2 100644 --- a/util/mach/mach_extensions.h +++ b/util/mach/mach_extensions.h @@ -30,7 +30,7 @@ namespace crashpad { //! are not performed, use kMachPortNull instead of an explicit `implicit_cast` //! of `MACH_PORT_NULL` to `mach_port_t`. This is useful for logging and testing //! assertions. -const mach_port_t kMachPortNull = MACH_PORT_NULL; +constexpr mach_port_t kMachPortNull = MACH_PORT_NULL; //! \brief `MACH_EXCEPTION_CODES` with the correct type for a Mach exception //! behavior, `exception_behavior_t`. @@ -38,7 +38,7 @@ const mach_port_t kMachPortNull = MACH_PORT_NULL; //! Signedness problems can occur when ORing `MACH_EXCEPTION_CODES` as a signed //! integer, because a signed integer overflow results. This constant can be //! used instead of `MACH_EXCEPTION_CODES` in such cases. -const exception_behavior_t kMachExceptionCodes = MACH_EXCEPTION_CODES; +constexpr exception_behavior_t kMachExceptionCodes = MACH_EXCEPTION_CODES; // Because exception_mask_t is an int and has one bit for each defined // exception_type_t, it’s reasonable to assume that there cannot be any @@ -49,7 +49,7 @@ const exception_behavior_t kMachExceptionCodes = MACH_EXCEPTION_CODES; // EXC_MASK_CRASH. //! \brief An exception type to use for simulated exceptions. -const exception_type_t kMachExceptionSimulated = 'CPsx'; +constexpr exception_type_t kMachExceptionSimulated = 'CPsx'; //! \brief A const version of `thread_state_t`. //! diff --git a/util/mach/mach_extensions_test.cc b/util/mach/mach_extensions_test.cc index 289a1999..1c5b368c 100644 --- a/util/mach/mach_extensions_test.cc +++ b/util/mach/mach_extensions_test.cc @@ -62,7 +62,7 @@ TEST(MachExtensions, NewMachPort_DeadName) { EXPECT_EQ(type, MACH_PORT_TYPE_DEAD_NAME); } -const exception_mask_t kExcMaskBasic = +constexpr exception_mask_t kExcMaskBasic = EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION | EXC_MASK_ARITHMETIC | diff --git a/util/mach/mach_message.cc b/util/mach/mach_message.cc index a5617830..5294c035 100644 --- a/util/mach/mach_message.cc +++ b/util/mach/mach_message.cc @@ -28,7 +28,7 @@ namespace crashpad { namespace { -const int kNanosecondsPerMillisecond = 1E6; +constexpr int kNanosecondsPerMillisecond = 1E6; // TimerRunning() determines whether |deadline| has passed. If |deadline| is // kMachMessageDeadlineWaitIndefinitely, |*timeout_options| is set to diff --git a/util/mach/mach_message.h b/util/mach/mach_message.h index df4b6b4f..e0fc6f6f 100644 --- a/util/mach/mach_message.h +++ b/util/mach/mach_message.h @@ -26,7 +26,7 @@ namespace crashpad { //! //! This constant is provided because the macros normally used to request this //! behavior are cumbersome. -const mach_msg_option_t kMachMessageReceiveAuditTrailer = +constexpr mach_msg_option_t kMachMessageReceiveAuditTrailer = MACH_RCV_TRAILER_TYPE(MACH_MSG_TRAILER_FORMAT_0) | MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_AUDIT); diff --git a/util/mach/symbolic_constants_mach_test.cc b/util/mach/symbolic_constants_mach_test.cc index c8d6d48e..32711412 100644 --- a/util/mach/symbolic_constants_mach_test.cc +++ b/util/mach/symbolic_constants_mach_test.cc @@ -147,9 +147,9 @@ struct ConvertExceptionTraits { ValueType* value) { return StringToException(string, options, value); } - static const char kValueName[]; + static constexpr char kValueName[] = "exception"; }; -const char ConvertExceptionTraits::kValueName[] = "exception"; +constexpr char ConvertExceptionTraits::kValueName[]; void TestExceptionToString(exception_type_t value, const char* expect_full, @@ -322,9 +322,9 @@ struct ConvertExceptionMaskTraits { ValueType* value) { return StringToExceptionMask(string, options, value); } - static const char kValueName[]; + static constexpr char kValueName[] = "exception_mask"; }; -const char ConvertExceptionMaskTraits::kValueName[] = "exception_mask"; +constexpr char ConvertExceptionMaskTraits::kValueName[]; void TestExceptionMaskToString(exception_mask_t value, const char* expect_full, @@ -565,9 +565,9 @@ struct ConvertExceptionBehaviorTraits { ValueType* value) { return StringToExceptionBehavior(string, options, value); } - static const char kValueName[]; + static constexpr char kValueName[] = "behavior"; }; -const char ConvertExceptionBehaviorTraits::kValueName[] = "behavior"; +constexpr char ConvertExceptionBehaviorTraits::kValueName[]; void TestExceptionBehaviorToString(exception_behavior_t value, const char* expect_full, @@ -828,9 +828,9 @@ struct ConvertThreadStateFlavorTraits { ValueType* value) { return StringToThreadStateFlavor(string, options, value); } - static const char kValueName[]; + static constexpr char kValueName[] = "flavor"; }; -const char ConvertThreadStateFlavorTraits::kValueName[] = "flavor"; +constexpr char ConvertThreadStateFlavorTraits::kValueName[]; void TestThreadStateFlavorToString(exception_type_t value, const char* expect_full, diff --git a/util/misc/clock_posix.cc b/util/misc/clock_posix.cc index 24171091..51c1406d 100644 --- a/util/misc/clock_posix.cc +++ b/util/misc/clock_posix.cc @@ -22,7 +22,7 @@ namespace { -const uint64_t kNanosecondsPerSecond = 1E9; +constexpr uint64_t kNanosecondsPerSecond = 1E9; } // namespace diff --git a/util/net/http_headers.cc b/util/net/http_headers.cc deleted file mode 100644 index 37d84c67..00000000 --- a/util/net/http_headers.cc +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2014 The Crashpad Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "util/net/http_headers.h" - -namespace crashpad { - -const char kContentType[] = "Content-Type"; -const char kContentLength[] = "Content-Length"; -const char kContentEncoding[] = "Content-Encoding"; - -} // namespace crashpad diff --git a/util/net/http_headers.h b/util/net/http_headers.h index 851ff31c..50335063 100644 --- a/util/net/http_headers.h +++ b/util/net/http_headers.h @@ -24,13 +24,13 @@ namespace crashpad { using HTTPHeaders = std::map; //! \brief The header name `"Content-Type"`. -extern const char kContentType[]; +constexpr char kContentType[] = "Content-Type"; //! \brief The header name `"Content-Length"`. -extern const char kContentLength[]; +constexpr char kContentLength[] = "Content-Length"; //! \brief The header name `"Content-Encoding"`. -extern const char kContentEncoding[]; +constexpr char kContentEncoding[] = "Content-Encoding"; } // namespace crashpad diff --git a/util/net/http_transport_win.cc b/util/net/http_transport_win.cc index ecbe8ea2..27cd4048 100644 --- a/util/net/http_transport_win.cc +++ b/util/net/http_transport_win.cc @@ -39,7 +39,7 @@ namespace crashpad { namespace { -const wchar_t kWinHttpDll[] = L"winhttp.dll"; +constexpr wchar_t kWinHttpDll[] = L"winhttp.dll"; std::string UserAgent() { std::string user_agent = diff --git a/util/numeric/in_range_cast_test.cc b/util/numeric/in_range_cast_test.cc index 6e74129f..73f5fd57 100644 --- a/util/numeric/in_range_cast_test.cc +++ b/util/numeric/in_range_cast_test.cc @@ -25,8 +25,8 @@ namespace crashpad { namespace test { namespace { -const int32_t kInt32Min = std::numeric_limits::min(); -const int64_t kInt64Min = std::numeric_limits::min(); +constexpr int32_t kInt32Min = std::numeric_limits::min(); +constexpr int64_t kInt64Min = std::numeric_limits::min(); TEST(InRangeCast, Uint32) { EXPECT_EQ(InRangeCast(0, 1), 0u); diff --git a/util/thread/worker_thread_test.cc b/util/thread/worker_thread_test.cc index 2070c6ad..9b11fef1 100644 --- a/util/thread/worker_thread_test.cc +++ b/util/thread/worker_thread_test.cc @@ -22,7 +22,7 @@ namespace crashpad { namespace test { namespace { -const uint64_t kNanosecondsPerSecond = static_cast(1E9); +constexpr uint64_t kNanosecondsPerSecond = static_cast(1E9); class WorkDelegate : public WorkerThread::Delegate { public: diff --git a/util/util.gyp b/util/util.gyp index 5facdaeb..80d5e117 100644 --- a/util/util.gyp +++ b/util/util.gyp @@ -140,7 +140,6 @@ 'net/http_body.h', 'net/http_body_gzip.cc', 'net/http_body_gzip.h', - 'net/http_headers.cc', 'net/http_headers.h', 'net/http_multipart_builder.cc', 'net/http_multipart_builder.h', diff --git a/util/win/time.cc b/util/win/time.cc index 6d3c9c08..f3c2360a 100644 --- a/util/win/time.cc +++ b/util/win/time.cc @@ -22,7 +22,7 @@ namespace crashpad { namespace { -const uint64_t kMicrosecondsPerSecond = static_cast(1E6); +constexpr uint64_t kMicrosecondsPerSecond = static_cast(1E6); uint64_t FiletimeToMicroseconds(const FILETIME& filetime) { uint64_t t = (static_cast(filetime.dwHighDateTime) << 32) |