diff --git a/client/crash_report_database_mac.mm b/client/crash_report_database_mac.mm index 3cc2d7fe..7a9154b8 100644 --- a/client/crash_report_database_mac.mm +++ b/client/crash_report_database_mac.mm @@ -42,29 +42,30 @@ namespace crashpad { namespace { -const char kWriteDirectory[] = "new"; -const char kUploadPendingDirectory[] = "pending"; -const char kCompletedDirectory[] = "completed"; +constexpr char kWriteDirectory[] = "new"; +constexpr char kUploadPendingDirectory[] = "pending"; +constexpr char kCompletedDirectory[] = "completed"; -const char kSettings[] = "settings.dat"; +constexpr char kSettings[] = "settings.dat"; -const char* const kReportDirectories[] = { +constexpr const char* kReportDirectories[] = { kWriteDirectory, kUploadPendingDirectory, kCompletedDirectory, }; -const char kCrashReportFileExtension[] = "dmp"; +constexpr char kCrashReportFileExtension[] = "dmp"; -const char kXattrUUID[] = "uuid"; -const char kXattrCollectorID[] = "id"; -const char kXattrCreationTime[] = "creation_time"; -const char kXattrIsUploaded[] = "uploaded"; -const char kXattrLastUploadTime[] = "last_upload_time"; -const char kXattrUploadAttemptCount[] = "upload_count"; -const char kXattrIsUploadExplicitlyRequested[] = "upload_explicitly_requested"; +constexpr char kXattrUUID[] = "uuid"; +constexpr char kXattrCollectorID[] = "id"; +constexpr char kXattrCreationTime[] = "creation_time"; +constexpr char kXattrIsUploaded[] = "uploaded"; +constexpr char kXattrLastUploadTime[] = "last_upload_time"; +constexpr char kXattrUploadAttemptCount[] = "upload_count"; +constexpr char kXattrIsUploadExplicitlyRequested[] = + "upload_explicitly_requested"; -const char kXattrDatabaseInitialized[] = "initialized"; +constexpr char kXattrDatabaseInitialized[] = "initialized"; // Ensures that the node at |path| is a directory. If the |path| refers to a // file, rather than a directory, returns false. Otherwise, returns true, diff --git a/client/crash_report_database_test.cc b/client/crash_report_database_test.cc index da44ebfb..c4266961 100644 --- a/client/crash_report_database_test.cc +++ b/client/crash_report_database_test.cc @@ -51,7 +51,7 @@ class CrashReportDatabaseTest : public testing::Test { CrashReportDatabase::NewReport* new_report = nullptr; ASSERT_EQ(db_->PrepareNewCrashReport(&new_report), CrashReportDatabase::kNoError); - const char kTest[] = "test"; + static constexpr char kTest[] = "test"; ASSERT_TRUE(LoggingWriteFile(new_report->handle, kTest, sizeof(kTest))); UUID uuid; diff --git a/client/crash_report_database_win.cc b/client/crash_report_database_win.cc index a97b1cf0..1e1b4d7a 100644 --- a/client/crash_report_database_win.cc +++ b/client/crash_report_database_win.cc @@ -36,12 +36,12 @@ namespace crashpad { namespace { -const wchar_t kReportsDirectory[] = L"reports"; -const wchar_t kMetadataFileName[] = L"metadata"; +constexpr wchar_t kReportsDirectory[] = L"reports"; +constexpr wchar_t kMetadataFileName[] = L"metadata"; -const wchar_t kSettings[] = L"settings.dat"; +constexpr wchar_t kSettings[] = L"settings.dat"; -const wchar_t kCrashReportFileExtension[] = L"dmp"; +constexpr wchar_t kCrashReportFileExtension[] = L"dmp"; const uint32_t kMetadataFileHeaderMagic = 'CPAD'; const uint32_t kMetadataFileVersion = 1; diff --git a/client/crashpad_info.cc b/client/crashpad_info.cc index b7ba5490..58d30ce8 100644 --- a/client/crashpad_info.cc +++ b/client/crashpad_info.cc @@ -28,7 +28,7 @@ namespace { -static const uint32_t kCrashpadInfoVersion = 1; +constexpr uint32_t kCrashpadInfoVersion = 1; } // namespace diff --git a/client/prune_crash_reports_test.cc b/client/prune_crash_reports_test.cc index 130ea72a..54d6941e 100644 --- a/client/prune_crash_reports_test.cc +++ b/client/prune_crash_reports_test.cc @@ -147,7 +147,7 @@ class StaticCondition final : public PruneCondition { }; TEST(PruneCrashReports, BinaryCondition) { - const struct { + static constexpr struct { const char* name; BinaryPruneCondition::Operator op; bool lhs_value; diff --git a/client/settings_test.cc b/client/settings_test.cc index 866e58d7..ca961a23 100644 --- a/client/settings_test.cc +++ b/client/settings_test.cc @@ -41,7 +41,7 @@ class SettingsTest : public testing::Test { FilePermissions::kWorldReadable)); ASSERT_TRUE(handle.is_valid()); - const char kBuf[] = "test bad file"; + static constexpr char kBuf[] = "test bad file"; ASSERT_TRUE(LoggingWriteFile(handle.get(), kBuf, sizeof(kBuf))); handle.reset(); } diff --git a/client/simulate_crash_mac.cc b/client/simulate_crash_mac.cc index 27864388..1e2d8e42 100644 --- a/client/simulate_crash_mac.cc +++ b/client/simulate_crash_mac.cc @@ -196,7 +196,7 @@ void SimulateCrash(const NativeCPUContext& cpu_context) { // Look up the handler for EXC_CRASH exceptions in the same way that the // kernel would: try a thread handler, then a task handler, and finally a host // handler. 10.9.5 xnu-2422.115.4/osfmk/kern/exception.c exception_triage(). - const ExceptionPorts::TargetType kTargetTypes[] = { + static constexpr ExceptionPorts::TargetType kTargetTypes[] = { ExceptionPorts::kTargetTypeThread, ExceptionPorts::kTargetTypeTask, diff --git a/client/simulate_crash_mac_test.cc b/client/simulate_crash_mac_test.cc index c1953524..1d63ff65 100644 --- a/client/simulate_crash_mac_test.cc +++ b/client/simulate_crash_mac_test.cc @@ -307,14 +307,14 @@ class TestSimulateCrashMac final : public MachMultiprocess, }; TEST(SimulateCrash, SimulateCrash) { - const TestSimulateCrashMac::ExceptionPortsTarget kTargets[] = { + static constexpr TestSimulateCrashMac::ExceptionPortsTarget kTargets[] = { TestSimulateCrashMac::kExceptionPortsTargetNone, TestSimulateCrashMac::kExceptionPortsTargetTask, TestSimulateCrashMac::kExceptionPortsTargetThread, TestSimulateCrashMac::kExceptionPortsTargetBoth, }; - const exception_behavior_t kBehaviors[] = { + static constexpr exception_behavior_t kBehaviors[] = { EXCEPTION_DEFAULT, EXCEPTION_STATE, EXCEPTION_STATE_IDENTITY, @@ -323,7 +323,7 @@ TEST(SimulateCrash, SimulateCrash) { EXCEPTION_STATE_IDENTITY | kMachExceptionCodes, }; - const thread_state_flavor_t kFlavors[] = { + static constexpr thread_state_flavor_t kFlavors[] = { #if defined(ARCH_CPU_X86_FAMILY) x86_THREAD_STATE, x86_FLOAT_STATE, diff --git a/handler/crash_report_upload_thread.cc b/handler/crash_report_upload_thread.cc index d77cdbad..252e14fb 100644 --- a/handler/crash_report_upload_thread.cc +++ b/handler/crash_report_upload_thread.cc @@ -361,7 +361,7 @@ CrashReportUploadThread::UploadResult CrashReportUploadThread::UploadReport( HTTPMultipartBuilder http_multipart_builder; http_multipart_builder.SetGzipEnabled(upload_gzip_); - const char kMinidumpKey[] = "upload_file_minidump"; + static constexpr char kMinidumpKey[] = "upload_file_minidump"; for (const auto& kv : parameters) { if (kv.first == kMinidumpKey) { diff --git a/handler/crashpad_handler_test.cc b/handler/crashpad_handler_test.cc index 7237e8c8..125157ff 100644 --- a/handler/crashpad_handler_test.cc +++ b/handler/crashpad_handler_test.cc @@ -115,7 +115,7 @@ void CrashWithExtendedHandler::ValidateGeneratedDump() { ASSERT_TRUE(reader.ReadExactly(data.data(), data.size())); - static const char kExpectedData[] = "Injected extension stream!"; + static constexpr char kExpectedData[] = "Injected extension stream!"; EXPECT_EQ(memcmp(kExpectedData, data.data(), sizeof(kExpectedData)), 0); } } diff --git a/handler/crashpad_handler_test_extended_handler.cc b/handler/crashpad_handler_test_extended_handler.cc index ede0f6e7..e2134e78 100644 --- a/handler/crashpad_handler_test_extended_handler.cc +++ b/handler/crashpad_handler_test_extended_handler.cc @@ -39,7 +39,7 @@ class TestUserStreamDataSource : public crashpad::UserStreamDataSource { std::unique_ptr TestUserStreamDataSource::ProduceStreamData( crashpad::ProcessSnapshot* process_snapshot) { - static const char kTestData[] = "Injected extension stream!"; + static constexpr char kTestData[] = "Injected extension stream!"; return base::WrapUnique(new crashpad::test::BufferExtensionStreamDataSource( 0xCAFEBABE, kTestData, sizeof(kTestData))); diff --git a/handler/handler_main.cc b/handler/handler_main.cc index e6d05e22..f1b08ff9 100644 --- a/handler/handler_main.cc +++ b/handler/handler_main.cc @@ -436,7 +436,7 @@ int HandlerMain(int argc, kOptionVersion = -3, }; - const option long_options[] = { + static constexpr option long_options[] = { {"annotation", required_argument, nullptr, kOptionAnnotation}, {"database", required_argument, nullptr, kOptionDatabase}, #if defined(OS_MACOSX) @@ -714,7 +714,7 @@ int HandlerMain(int argc, base::GlobalHistogramAllocator* histogram_allocator = nullptr; if (!options.metrics_dir.empty()) { - static const char kMetricsName[] = "CrashpadMetrics"; + static constexpr char kMetricsName[] = "CrashpadMetrics"; const size_t kMetricsFileSize = 1 << 20; if (base::GlobalHistogramAllocator::CreateWithActiveFileInDir( options.metrics_dir, kMetricsFileSize, 0, kMetricsName)) { diff --git a/handler/win/crashy_test_program.cc b/handler/win/crashy_test_program.cc index 58afa47f..0da56cb9 100644 --- a/handler/win/crashy_test_program.cc +++ b/handler/win/crashy_test_program.cc @@ -63,20 +63,20 @@ void AllocateMemoryOfVariousProtections() { const size_t kPageSize = system_info.dwPageSize; - const uint32_t kPageTypes[] = { - PAGE_NOACCESS, - PAGE_READONLY, - PAGE_READWRITE, - PAGE_EXECUTE, - PAGE_EXECUTE_READ, - PAGE_EXECUTE_READWRITE, + static constexpr uint32_t kPageTypes[] = { + PAGE_NOACCESS, + PAGE_READONLY, + PAGE_READWRITE, + PAGE_EXECUTE, + PAGE_EXECUTE_READ, + PAGE_EXECUTE_READWRITE, - // PAGE_NOACCESS is invalid with PAGE_GUARD. - PAGE_READONLY | PAGE_GUARD, - PAGE_READWRITE | PAGE_GUARD, - PAGE_EXECUTE | PAGE_GUARD, - PAGE_EXECUTE_READ | PAGE_GUARD, - PAGE_EXECUTE_READWRITE | PAGE_GUARD, + // PAGE_NOACCESS is invalid with PAGE_GUARD. + PAGE_READONLY | PAGE_GUARD, + PAGE_READWRITE | PAGE_GUARD, + PAGE_EXECUTE | PAGE_GUARD, + PAGE_EXECUTE_READ | PAGE_GUARD, + PAGE_EXECUTE_READWRITE | PAGE_GUARD, }; // All of these allocations are leaked, we want to view them in windbg via diff --git a/minidump/minidump_crashpad_info_writer_test.cc b/minidump/minidump_crashpad_info_writer_test.cc index e24a606c..7ae0980b 100644 --- a/minidump/minidump_crashpad_info_writer_test.cc +++ b/minidump/minidump_crashpad_info_writer_test.cc @@ -130,10 +130,10 @@ TEST(MinidumpCrashpadInfoWriter, SimpleAnnotations) { auto crashpad_info_writer = base::WrapUnique(new MinidumpCrashpadInfoWriter()); - const char kKey[] = + static constexpr char kKey[] = "a thing that provides a means of gaining access to or understanding " "something"; - const char kValue[] = + static constexpr char kValue[] = "the numerical amount denoted by an algebraic term; a magnitude, " "quantity, or number"; auto simple_string_dictionary_writer = @@ -230,9 +230,9 @@ TEST(MinidumpCrashpadInfoWriter, InitializeFromSnapshot) { ASSERT_TRUE( client_id.InitializeFromString("fedcba98-7654-3210-0123-456789abcdef")); - const char kKey[] = "version"; - const char kValue[] = "40.0.2214.111"; - const char kEntry[] = "This is a simple annotation in a list."; + static constexpr char kKey[] = "version"; + static constexpr char kValue[] = "40.0.2214.111"; + static constexpr char kEntry[] = "This is a simple annotation in a list."; // Test with a useless module, one that doesn’t carry anything that would // require MinidumpCrashpadInfo or any child object. diff --git a/minidump/minidump_file_writer_test.cc b/minidump/minidump_file_writer_test.cc index 63f2ade8..04ddd4d1 100644 --- a/minidump/minidump_file_writer_test.cc +++ b/minidump/minidump_file_writer_test.cc @@ -134,7 +134,7 @@ TEST(MinidumpFileWriter, AddUserExtensionStream) { const time_t kTimestamp = 0x155d2fb8; minidump_file.SetTimestamp(kTimestamp); - static const uint8_t kStreamData[] = "Hello World!"; + static constexpr uint8_t kStreamData[] = "Hello World!"; const size_t kStreamSize = arraysize(kStreamData); const MinidumpStreamType kStreamType = static_cast(0x4d); @@ -270,7 +270,7 @@ TEST(MinidumpFileWriter, ThreeStreams) { std::string expected_stream0(kStream0Size, kStream0Value); EXPECT_EQ(memcmp(stream0_data, expected_stream0.c_str(), kStream0Size), 0); - const int kZeroes[16] = {}; + static constexpr int kZeroes[16] = {}; ASSERT_GE(sizeof(kZeroes), kStream1Padding); EXPECT_EQ(memcmp(stream0_data + kStream0Size, kZeroes, kStream1Padding), 0); diff --git a/minidump/minidump_misc_info_writer.cc b/minidump/minidump_misc_info_writer.cc index 2ea8fa90..1b775faa 100644 --- a/minidump/minidump_misc_info_writer.cc +++ b/minidump/minidump_misc_info_writer.cc @@ -101,25 +101,25 @@ std::string MinidumpMiscInfoDebugBuildString() { // plus a UTF-16 NUL terminator. Don’t let strings get longer than this, or // they will be truncated and a message will be logged. #if defined(OS_MACOSX) - const char kOS[] = "mac"; + static constexpr char kOS[] = "mac"; #elif defined(OS_ANDROID) - const char kOS[] = "android"; + static constexpr char kOS[] = "android"; #elif defined(OS_LINUX) - const char kOS[] = "linux"; + static constexpr char kOS[] = "linux"; #elif defined(OS_WIN) - const char kOS[] = "win"; + static constexpr char kOS[] = "win"; #else #error define kOS for this operating system #endif #if defined(ARCH_CPU_X86) - const char kCPU[] = "i386"; + static constexpr char kCPU[] = "i386"; #elif defined(ARCH_CPU_X86_64) - const char kCPU[] = "amd64"; + static constexpr char kCPU[] = "amd64"; #elif defined(ARCH_CPU_ARMEL) - const char kCPU[] = "arm"; + static constexpr char kCPU[] = "arm"; #elif defined(ARCH_CPU_ARM64) - const char kCPU[] = "arm64"; + static constexpr char kCPU[] = "arm64"; #else #error define kCPU for this CPU #endif diff --git a/minidump/minidump_misc_info_writer_test.cc b/minidump/minidump_misc_info_writer_test.cc index 74a41701..ec404ff5 100644 --- a/minidump/minidump_misc_info_writer_test.cc +++ b/minidump/minidump_misc_info_writer_test.cc @@ -368,10 +368,10 @@ TEST(MinidumpMiscInfoWriter, TimeZone) { const uint32_t kTimeZoneId = 2; const int32_t kBias = 300; - const char kStandardName[] = "EST"; + static constexpr char kStandardName[] = "EST"; const SYSTEMTIME kStandardDate = {0, 11, 1, 0, 2, 0, 0, 0}; const int32_t kStandardBias = 0; - const char kDaylightName[] = "EDT"; + static constexpr char kDaylightName[] = "EDT"; const SYSTEMTIME kDaylightDate = {0, 3, 2, 0, 2, 0, 0, 0}; const int32_t kDaylightBias = -60; @@ -482,8 +482,8 @@ TEST(MinidumpMiscInfoWriter, BuildStrings) { MinidumpFileWriter minidump_file_writer; auto misc_info_writer = base::WrapUnique(new MinidumpMiscInfoWriter()); - const char kBuildString[] = "build string"; - const char kDebugBuildString[] = "debug build string"; + static constexpr char kBuildString[] = "build string"; + static constexpr char kDebugBuildString[] = "debug build string"; misc_info_writer->SetBuildString(kBuildString, kDebugBuildString); @@ -622,13 +622,13 @@ TEST(MinidumpMiscInfoWriter, Everything) { const uint32_t kProtectedProcess = 1; const uint32_t kTimeZoneId = 2; const int32_t kBias = 300; - const char kStandardName[] = "EST"; + static constexpr char kStandardName[] = "EST"; const int32_t kStandardBias = 0; - const char kDaylightName[] = "EDT"; + static constexpr char kDaylightName[] = "EDT"; const int32_t kDaylightBias = -60; const SYSTEMTIME kSystemTimeZero = {}; - const char kBuildString[] = "build string"; - const char kDebugBuildString[] = "debug build string"; + static constexpr char kBuildString[] = "build string"; + static constexpr char kDebugBuildString[] = "debug build string"; misc_info_writer->SetProcessID(kProcessId); misc_info_writer->SetProcessTimes( @@ -711,14 +711,15 @@ TEST(MinidumpMiscInfoWriter, Everything) { TEST(MinidumpMiscInfoWriter, InitializeFromSnapshot) { MINIDUMP_MISC_INFO_4 expect_misc_info = {}; - const char kStandardTimeName[] = "EST"; - const char kDaylightTimeName[] = "EDT"; - const char kOSVersionFull[] = + static constexpr char kStandardTimeName[] = "EST"; + static constexpr char kDaylightTimeName[] = "EDT"; + static constexpr char kOSVersionFull[] = "Mac OS X 10.9.5 (13F34); " "Darwin 13.4.0 Darwin Kernel Version 13.4.0: " "Sun Aug 17 19:50:11 PDT 2014; " "root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"; - const char kMachineDescription[] = "MacBookPro11,3 (Mac-2BD1B31983FE1663)"; + static constexpr char kMachineDescription[] = + "MacBookPro11,3 (Mac-2BD1B31983FE1663)"; base::string16 standard_time_name_utf16 = base::UTF8ToUTF16(kStandardTimeName); base::string16 daylight_time_name_utf16 = diff --git a/minidump/minidump_module_crashpad_info_writer_test.cc b/minidump/minidump_module_crashpad_info_writer_test.cc index 74451843..39a92226 100644 --- a/minidump/minidump_module_crashpad_info_writer_test.cc +++ b/minidump/minidump_module_crashpad_info_writer_test.cc @@ -109,9 +109,9 @@ TEST(MinidumpModuleCrashpadInfoWriter, EmptyModule) { TEST(MinidumpModuleCrashpadInfoWriter, FullModule) { const uint32_t kMinidumpModuleListIndex = 1; - const char kKey[] = "key"; - const char kValue[] = "value"; - const char kEntry[] = "entry"; + static constexpr char kKey[] = "key"; + static constexpr char kValue[] = "value"; + static constexpr char kEntry[] = "entry"; std::vector vector(1, std::string(kEntry)); StringFile string_file; @@ -195,14 +195,14 @@ TEST(MinidumpModuleCrashpadInfoWriter, FullModule) { TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) { const uint32_t kMinidumpModuleListIndex0 = 0; - const char kKey0[] = "key"; - const char kValue0[] = "value"; + static constexpr char kKey0[] = "key"; + static constexpr char kValue0[] = "value"; const uint32_t kMinidumpModuleListIndex1 = 2; const uint32_t kMinidumpModuleListIndex2 = 5; - const char kKey2A[] = "K"; - const char kValue2A[] = "VVV"; - const char kKey2B[] = "river"; - const char kValue2B[] = "hudson"; + static constexpr char kKey2A[] = "K"; + static constexpr char kValue2A[] = "VVV"; + static constexpr char kKey2B[] = "river"; + static constexpr char kValue2B[] = "hudson"; StringFile string_file; @@ -339,14 +339,14 @@ TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) { } TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) { - const char kKey0A[] = "k"; - const char kValue0A[] = "value"; - const char kKey0B[] = "hudson"; - const char kValue0B[] = "estuary"; - const char kKey2[] = "k"; - const char kValue2[] = "different_value"; - const char kEntry3A[] = "list"; - const char kEntry3B[] = "erine"; + static constexpr char kKey0A[] = "k"; + static constexpr char kValue0A[] = "value"; + static constexpr char kKey0B[] = "hudson"; + static constexpr char kValue0B[] = "estuary"; + static constexpr char kKey2[] = "k"; + static constexpr char kValue2[] = "different_value"; + static constexpr char kEntry3A[] = "list"; + static constexpr char kEntry3B[] = "erine"; std::vector module_snapshots; diff --git a/minidump/minidump_module_writer_test.cc b/minidump/minidump_module_writer_test.cc index b2478d5a..2088b5cf 100644 --- a/minidump/minidump_module_writer_test.cc +++ b/minidump/minidump_module_writer_test.cc @@ -271,7 +271,7 @@ TEST(MinidumpModuleWriter, EmptyModule) { MinidumpFileWriter minidump_file_writer; auto module_list_writer = base::WrapUnique(new MinidumpModuleListWriter()); - const char kModuleName[] = "test_executable"; + static constexpr char kModuleName[] = "test_executable"; auto module_writer = base::WrapUnique(new MinidumpModuleWriter()); module_writer->SetName(kModuleName); @@ -310,7 +310,7 @@ TEST(MinidumpModuleWriter, OneModule) { MinidumpFileWriter minidump_file_writer; auto module_list_writer = base::WrapUnique(new MinidumpModuleListWriter()); - const char kModuleName[] = "statically_linked"; + static constexpr char kModuleName[] = "statically_linked"; const uint64_t kModuleBase = 0x10da69000; const uint32_t kModuleSize = 0x1000; const uint32_t kChecksum = 0x76543210; @@ -326,15 +326,15 @@ TEST(MinidumpModuleWriter, OneModule) { const uint32_t kFileOS = VOS_DOS; const uint32_t kFileType = VFT_DRV; const uint32_t kFileSubtype = VFT2_DRV_KEYBOARD; - const char kPDBName[] = "statical.pdb"; - const uint8_t kPDBUUIDBytes[16] = + static constexpr char kPDBName[] = "statical.pdb"; + static constexpr uint8_t kPDBUUIDBytes[16] = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x08, 0x19, 0x2a, 0x3b, 0x4c, 0x5d, 0x6e, 0x7f}; UUID pdb_uuid; pdb_uuid.InitializeFromBytes(kPDBUUIDBytes); const uint32_t kPDBAge = 1; const uint32_t kDebugType = IMAGE_DEBUG_MISC_EXENAME; - const char kDebugName[] = "statical.dbg"; + static constexpr char kDebugName[] = "statical.dbg"; const bool kDebugUTF16 = false; auto module_writer = base::WrapUnique(new MinidumpModuleWriter()); @@ -419,12 +419,12 @@ TEST(MinidumpModuleWriter, OneModule_CodeViewUsesPDB20_MiscUsesUTF16) { MinidumpFileWriter minidump_file_writer; auto module_list_writer = base::WrapUnique(new MinidumpModuleListWriter()); - const char kModuleName[] = "dinosaur"; - const char kPDBName[] = "d1n05.pdb"; + static constexpr char kModuleName[] = "dinosaur"; + static constexpr char kPDBName[] = "d1n05.pdb"; const time_t kPDBTimestamp = 0x386d4380; const uint32_t kPDBAge = 1; const uint32_t kDebugType = IMAGE_DEBUG_MISC_EXENAME; - const char kDebugName[] = "d1n05.dbg"; + static constexpr char kDebugName[] = "d1n05.dbg"; const bool kDebugUTF16 = true; auto module_writer = base::WrapUnique(new MinidumpModuleWriter()); @@ -480,25 +480,25 @@ TEST(MinidumpModuleWriter, ThreeModules) { MinidumpFileWriter minidump_file_writer; auto module_list_writer = base::WrapUnique(new MinidumpModuleListWriter()); - const char kModuleName0[] = "main"; + static constexpr char kModuleName0[] = "main"; const uint64_t kModuleBase0 = 0x100101000; const uint32_t kModuleSize0 = 0xf000; - const char kPDBName0[] = "main"; - const uint8_t kPDBUUIDBytes0[16] = + static constexpr char kPDBName0[] = "main"; + static constexpr uint8_t kPDBUUIDBytes0[16] = {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99}; UUID pdb_uuid_0; pdb_uuid_0.InitializeFromBytes(kPDBUUIDBytes0); const uint32_t kPDBAge0 = 0; - const char kModuleName1[] = "ld.so"; + static constexpr char kModuleName1[] = "ld.so"; const uint64_t kModuleBase1 = 0x200202000; const uint32_t kModuleSize1 = 0x1e000; - const char kModuleName2[] = "libc.so"; + static constexpr char kModuleName2[] = "libc.so"; const uint64_t kModuleBase2 = 0x300303000; const uint32_t kModuleSize2 = 0x2d000; - const char kPDBName2[] = "libc.so"; + static constexpr char kPDBName2[] = "libc.so"; const time_t kPDBTimestamp2 = 0x386d4380; const uint32_t kPDBAge2 = 2; @@ -668,7 +668,7 @@ TEST(MinidumpModuleWriter, InitializeFromSnapshot) { expect_modules[0].VersionInfo.dwFileType = VFT_APP; module_paths[0] = "/usr/bin/true"; module_pdbs[0] = "true"; - const uint8_t kUUIDBytes0[16] = + static constexpr uint8_t kUUIDBytes0[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; uuids[0].InitializeFromBytes(kUUIDBytes0); @@ -684,7 +684,7 @@ TEST(MinidumpModuleWriter, InitializeFromSnapshot) { expect_modules[1].VersionInfo.dwFileType = VFT_DLL; module_paths[1] = "/usr/lib/libSystem.B.dylib"; module_pdbs[1] = "libSystem.B.dylib.pdb"; - const uint8_t kUUIDBytes1[16] = + static constexpr uint8_t kUUIDBytes1[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; uuids[1].InitializeFromBytes(kUUIDBytes1); @@ -700,7 +700,7 @@ TEST(MinidumpModuleWriter, InitializeFromSnapshot) { expect_modules[2].VersionInfo.dwFileType = VFT_UNKNOWN; module_paths[2] = "/usr/lib/dyld"; module_pdbs[2] = "/usr/lib/dyld.pdb"; - const uint8_t kUUIDBytes2[16] = + static constexpr uint8_t kUUIDBytes2[16] = {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0}; uuids[2].InitializeFromBytes(kUUIDBytes2); diff --git a/minidump/minidump_rva_list_writer_test.cc b/minidump/minidump_rva_list_writer_test.cc index 1d26b27b..c961b735 100644 --- a/minidump/minidump_rva_list_writer_test.cc +++ b/minidump/minidump_rva_list_writer_test.cc @@ -76,7 +76,7 @@ TEST(MinidumpRVAListWriter, OneChild) { TEST(MinidumpRVAListWriter, ThreeChildren) { TestMinidumpRVAListWriter list_writer; - const uint32_t kValues[] = { 0x80000000, 0x55555555, 0x66006600 }; + static constexpr uint32_t kValues[] = {0x80000000, 0x55555555, 0x66006600}; list_writer.AddChild(kValues[0]); list_writer.AddChild(kValues[1]); diff --git a/minidump/minidump_string_writer_test.cc b/minidump/minidump_string_writer_test.cc index 6a1e5c64..25aedf13 100644 --- a/minidump/minidump_string_writer_test.cc +++ b/minidump/minidump_string_writer_test.cc @@ -49,7 +49,7 @@ TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) { base::string16()); } - const struct { + static constexpr struct { size_t input_length; const char* input_string; size_t output_length; @@ -106,7 +106,7 @@ TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) { TEST(MinidumpStringWriter, ConvertInvalidUTF8ToUTF16) { StringFile string_file; - const char* kTestData[] = { + static constexpr const char* kTestData[] = { "\200", // continuation byte "\300", // start byte followed by EOF "\310\177", // start byte without continuation @@ -160,7 +160,7 @@ TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) { std::string()); } - const struct { + static constexpr struct { size_t length; const char* string; } kTestData[] = { diff --git a/minidump/minidump_system_info_writer_test.cc b/minidump/minidump_system_info_writer_test.cc index 0dd90559..62c41933 100644 --- a/minidump/minidump_system_info_writer_test.cc +++ b/minidump/minidump_system_info_writer_test.cc @@ -129,9 +129,9 @@ TEST(MinidumpSystemInfoWriter, X86_Win) { const uint32_t kOSVersionMajor = 6; const uint32_t kOSVersionMinor = 1; const uint32_t kOSVersionBuild = 7601; - const char kCSDVersion[] = "Service Pack 1"; + static constexpr char kCSDVersion[] = "Service Pack 1"; const uint16_t kSuiteMask = VER_SUITE_SINGLEUSERTS; - const char kCPUVendor[] = "AuthenticAMD"; + static constexpr char kCPUVendor[] = "AuthenticAMD"; const uint32_t kCPUVersion = 0x00100f62; const uint32_t kCPUFeatures = 0x078bfbff; const uint32_t kAMDFeatures = 0xefd3fbff; @@ -200,8 +200,8 @@ TEST(MinidumpSystemInfoWriter, AMD64_Mac) { const uint32_t kOSVersionMajor = 10; const uint32_t kOSVersionMinor = 9; const uint32_t kOSVersionBuild = 4; - const char kCSDVersion[] = "13E28"; - const uint64_t kCPUFeatures[2] = {0x10427f4c, 0x00000000}; + static constexpr char kCSDVersion[] = "13E28"; + static constexpr uint64_t kCPUFeatures[2] = {0x10427f4c, 0x00000000}; system_info_writer->SetCPUArchitecture(kCPUArchitecture); system_info_writer->SetCPULevelAndRevision(kCPULevel, kCPURevision); @@ -248,7 +248,7 @@ TEST(MinidumpSystemInfoWriter, X86_CPUVendorFromRegisters) { auto system_info_writer = base::WrapUnique(new MinidumpSystemInfoWriter()); const MinidumpCPUArchitecture kCPUArchitecture = kMinidumpCPUArchitectureX86; - const uint32_t kCPUVendor[] = {'uneG', 'Ieni', 'letn'}; + static constexpr uint32_t kCPUVendor[] = {'uneG', 'Ieni', 'letn'}; system_info_writer->SetCPUArchitecture(kCPUArchitecture); system_info_writer->SetCPUX86Vendor( @@ -313,8 +313,8 @@ TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_X86) { expect_system_info.Cpu.X86CpuInfo.VersionInformation = kCPUSignature; expect_system_info.Cpu.X86CpuInfo.FeatureInformation = kCPUX86Features & 0xffffffff; - const char kCPUVendor[] = "GenuineIntel"; - const char kOSVersionBuild[] = "13F34"; + static constexpr char kCPUVendor[] = "GenuineIntel"; + static constexpr char kOSVersionBuild[] = "13F34"; TestSystemSnapshot system_snapshot; system_snapshot.SetCPUArchitecture(kCPUArchitectureX86); @@ -408,7 +408,7 @@ TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_AMD64) { (1 << PF_RDRAND_INSTRUCTION_AVAILABLE) | (UINT64_C(1) << PF_RDTSCP_INSTRUCTION_AVAILABLE); expect_system_info.Cpu.OtherCpuInfo.ProcessorFeatures[1] = 0; - const char kOSVersionBuild[] = "13F34"; + static constexpr char kOSVersionBuild[] = "13F34"; TestSystemSnapshot system_snapshot; system_snapshot.SetCPUArchitecture(kCPUArchitectureX86_64); diff --git a/minidump/minidump_unloaded_module_writer_test.cc b/minidump/minidump_unloaded_module_writer_test.cc index a6de044f..63cb84d8 100644 --- a/minidump/minidump_unloaded_module_writer_test.cc +++ b/minidump/minidump_unloaded_module_writer_test.cc @@ -74,7 +74,7 @@ TEST(MinidumpUnloadedModuleWriter, EmptyModule) { auto unloaded_module_list_writer = base::WrapUnique(new MinidumpUnloadedModuleListWriter()); - const char kModuleName[] = "test_dll"; + static constexpr char kModuleName[] = "test_dll"; auto unloaded_module_writer = base::WrapUnique(new MinidumpUnloadedModuleWriter()); @@ -113,7 +113,7 @@ TEST(MinidumpUnloadedModuleWriter, OneModule) { auto unloaded_module_list_writer = base::WrapUnique(new MinidumpUnloadedModuleListWriter()); - const char kModuleName[] = "statically_linked"; + static constexpr char kModuleName[] = "statically_linked"; const uint64_t kModuleBase = 0x10da69000; const uint32_t kModuleSize = 0x1000; const uint32_t kChecksum = 0x76543210; diff --git a/minidump/minidump_writable.cc b/minidump/minidump_writable.cc index 8b739060..47e21ff4 100644 --- a/minidump/minidump_writable.cc +++ b/minidump/minidump_writable.cc @@ -248,7 +248,7 @@ bool MinidumpWritable::WritePaddingAndObject(FileWriterInterface* file_writer) { // The number of elements in kZeroes must be at least one less than the // maximum Alignment() ever encountered. - const uint8_t kZeroes[kMaximumAlignment - 1] = {}; + static constexpr uint8_t kZeroes[kMaximumAlignment - 1] = {}; DCHECK_LE(leading_pad_bytes_, arraysize(kZeroes)); if (leading_pad_bytes_) { diff --git a/snapshot/linux/process_reader_test.cc b/snapshot/linux/process_reader_test.cc index 4acbb489..e3743bed 100644 --- a/snapshot/linux/process_reader_test.cc +++ b/snapshot/linux/process_reader_test.cc @@ -81,7 +81,7 @@ TEST(ProcessReader, SelfBasic) { EXPECT_EQ(process_reader.ProcessID(), getpid()); EXPECT_EQ(process_reader.ParentProcessID(), getppid()); - const char kTestMemory[] = "Some test memory"; + static constexpr char kTestMemory[] = "Some test memory"; char buffer[arraysize(kTestMemory)]; ASSERT_TRUE(process_reader.Memory()->Read( reinterpret_cast(kTestMemory), @@ -90,7 +90,7 @@ TEST(ProcessReader, SelfBasic) { EXPECT_STREQ(kTestMemory, buffer); } -const char kTestMemory[] = "Read me from another process"; +constexpr char kTestMemory[] = "Read me from another process"; class BasicChildTest : public Multiprocess { public: diff --git a/snapshot/mac/mach_o_image_annotations_reader_test.cc b/snapshot/mac/mach_o_image_annotations_reader_test.cc index c73eebbf..68d6c4e0 100644 --- a/snapshot/mac/mach_o_image_annotations_reader_test.cc +++ b/snapshot/mac/mach_o_image_annotations_reader_test.cc @@ -212,7 +212,8 @@ class TestMachOImageAnnotationsReader final // dyld exposes its error_string at least as far back as Mac OS X 10.4. if (test_type_ == kCrashDyld) { - const char kExpectedAnnotation[] = "could not load inserted library"; + static constexpr char kExpectedAnnotation[] = + "could not load inserted library"; size_t expected_annotation_length = strlen(kExpectedAnnotation); bool found = false; for (const std::string& annotation : all_annotations_vector) { diff --git a/snapshot/mac/mach_o_image_segment_reader_test.cc b/snapshot/mac/mach_o_image_segment_reader_test.cc index 6e4d415a..2da97e85 100644 --- a/snapshot/mac/mach_o_image_segment_reader_test.cc +++ b/snapshot/mac/mach_o_image_segment_reader_test.cc @@ -53,7 +53,7 @@ TEST(MachOImageSegmentReader, SegmentNameString) { // Segment names defined in . All of these should come // through SegmentNameString() cleanly and without truncation. - const char* kSegmentTestData[] = { + static constexpr const char* kSegmentTestData[] = { SEG_TEXT, SEG_DATA, SEG_OBJC, @@ -91,7 +91,7 @@ TEST(MachOImageSegmentReader, SectionNameString) { // Section names defined in . All of these should come // through SectionNameString() cleanly and without truncation. - const char* kSectionTestData[] = { + static constexpr const char* kSectionTestData[] = { SECT_TEXT, SECT_FVMLIB_INIT0, SECT_FVMLIB_INIT1, @@ -115,12 +115,11 @@ TEST(MachOImageSegmentReader, SectionNameString) { } TEST(MachOImageSegmentReader, SegmentAndSectionNameString) { - struct SegmentAndSectionTestData { + static constexpr struct { const char* segment; const char* section; const char* output; - }; - const SegmentAndSectionTestData kSegmentAndSectionTestData[] = { + } kSegmentAndSectionTestData[] = { {"segment", "section", "segment,section"}, {"Segment", "Section", "Segment,Section"}, {"SEGMENT", "SECTION", "SEGMENT,SECTION"}, @@ -172,7 +171,7 @@ TEST(MachOImageSegmentReader, SegmentAndSectionNameString) { for (size_t index = 0; index < arraysize(kSegmentAndSectionTestData); ++index) { - const SegmentAndSectionTestData& test = kSegmentAndSectionTestData[index]; + const auto& test = kSegmentAndSectionTestData[index]; EXPECT_EQ(MachOImageSegmentReader::SegmentAndSectionNameString( test.segment, test.section), test.output) diff --git a/snapshot/mac/process_reader_test.cc b/snapshot/mac/process_reader_test.cc index 3a6a1c8b..f1aa1ca2 100644 --- a/snapshot/mac/process_reader_test.cc +++ b/snapshot/mac/process_reader_test.cc @@ -58,7 +58,7 @@ namespace crashpad { namespace test { namespace { -const char kDyldPath[] = "/usr/lib/dyld"; +constexpr char kDyldPath[] = "/usr/lib/dyld"; TEST(ProcessReader, SelfBasic) { ProcessReader process_reader; @@ -73,7 +73,7 @@ TEST(ProcessReader, SelfBasic) { EXPECT_EQ(process_reader.ProcessID(), getpid()); EXPECT_EQ(process_reader.ParentProcessID(), getppid()); - const char kTestMemory[] = "Some test memory"; + static constexpr char kTestMemory[] = "Some test memory"; char buffer[arraysize(kTestMemory)]; ASSERT_TRUE(process_reader.Memory()->Read( FromPointerCast(kTestMemory), @@ -82,7 +82,7 @@ TEST(ProcessReader, SelfBasic) { EXPECT_STREQ(kTestMemory, buffer); } -const char kTestMemory[] = "Read me from another process"; +constexpr char kTestMemory[] = "Read me from another process"; class ProcessReaderChild final : public MachMultiprocess { public: diff --git a/snapshot/mac/process_types/custom.cc b/snapshot/mac/process_types/custom.cc index 7839b403..25ecf3da 100644 --- a/snapshot/mac/process_types/custom.cc +++ b/snapshot/mac/process_types/custom.cc @@ -65,7 +65,7 @@ bool ReadIntoVersioned(ProcessReader* process_reader, template size_t dyld_all_image_infos::ExpectedSizeForVersion( decltype(dyld_all_image_infos::version) version) { - const size_t kSizeForVersion[] = { + static constexpr size_t kSizeForVersion[] = { offsetof(dyld_all_image_infos, infoArrayCount), // 0 offsetof(dyld_all_image_infos, libSystemInitialized), // 1 offsetof(dyld_all_image_infos, jitInfo), // 2 diff --git a/snapshot/mac/system_snapshot_mac.cc b/snapshot/mac/system_snapshot_mac.cc index 135fe98e..2bafb274 100644 --- a/snapshot/mac/system_snapshot_mac.cc +++ b/snapshot/mac/system_snapshot_mac.cc @@ -364,9 +364,9 @@ void SystemSnapshotMac::TimeZone(DaylightSavingTimeStatus* dst_status, // no transitions to or from daylight saving time occurred or will occur // within a year of the current date. Arizona, which last observed daylight // saving time in 1967, is an example. - const int kMonthDeltas[] = - { 0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, - 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12 }; + static constexpr int kMonthDeltas[] = + {0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, + 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12}; for (size_t index = 0; index < arraysize(kMonthDeltas) && !found_transition; ++index) { diff --git a/snapshot/mac/system_snapshot_mac_test.cc b/snapshot/mac/system_snapshot_mac_test.cc index f21d9a27..fb4166f9 100644 --- a/snapshot/mac/system_snapshot_mac_test.cc +++ b/snapshot/mac/system_snapshot_mac_test.cc @@ -210,7 +210,7 @@ TEST_F(SystemSnapshotMacTest, TimeZone) { // standard_name and daylight_name can be nullptr where no name exists to // verify, as may happen when some versions of the timezone database carry // invented names and others do not. - const struct { + static constexpr struct { const char* tz; bool observes_dst; float standard_offset_hours; diff --git a/snapshot/win/pe_image_reader_test.cc b/snapshot/win/pe_image_reader_test.cc index 041d72a2..bf53279d 100644 --- a/snapshot/win/pe_image_reader_test.cc +++ b/snapshot/win/pe_image_reader_test.cc @@ -128,7 +128,7 @@ TEST(PEImageReader, VSFixedFileInfo_OneModule) { ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess(), ProcessSuspensionState::kRunning)); - const wchar_t kModuleName[] = L"kernel32.dll"; + static constexpr wchar_t kModuleName[] = L"kernel32.dll"; const HMODULE module_handle = GetModuleHandle(kModuleName); ASSERT_TRUE(module_handle) << ErrorMessage("GetModuleHandle"); diff --git a/snapshot/win/process_reader_win_test.cc b/snapshot/win/process_reader_win_test.cc index 87e72a94..9e62e118 100644 --- a/snapshot/win/process_reader_win_test.cc +++ b/snapshot/win/process_reader_win_test.cc @@ -41,14 +41,14 @@ TEST(ProcessReaderWin, SelfBasic) { EXPECT_EQ(process_reader.GetProcessInfo().ProcessID(), GetCurrentProcessId()); - const char kTestMemory[] = "Some test memory"; + static constexpr char kTestMemory[] = "Some test memory"; char buffer[arraysize(kTestMemory)]; ASSERT_TRUE(process_reader.ReadMemory( reinterpret_cast(kTestMemory), sizeof(kTestMemory), &buffer)); EXPECT_STREQ(kTestMemory, buffer); } -const char kTestMemory[] = "Read me from another process"; +constexpr char kTestMemory[] = "Read me from another process"; class ProcessReaderChild final : public WinMultiprocess { public: diff --git a/snapshot/win/process_snapshot_win.cc b/snapshot/win/process_snapshot_win.cc index f580fd09..326f199c 100644 --- a/snapshot/win/process_snapshot_win.cc +++ b/snapshot/win/process_snapshot_win.cc @@ -528,7 +528,7 @@ WinVMSize ProcessSnapshotWin::DetermineSizeOfEnvironmentBlock( &env_block[0]); env_block.resize( static_cast(bytes_read / sizeof(env_block[0]))); - const wchar_t terminator[] = { 0, 0 }; + static constexpr wchar_t terminator[] = {0, 0}; size_t at = env_block.find(std::wstring(terminator, arraysize(terminator))); if (at != std::wstring::npos) env_block.resize(at + arraysize(terminator)); diff --git a/snapshot/win/system_snapshot_win.cc b/snapshot/win/system_snapshot_win.cc index a8f6fcb1..e228905e 100644 --- a/snapshot/win/system_snapshot_win.cc +++ b/snapshot/win/system_snapshot_win.cc @@ -98,7 +98,7 @@ void SystemSnapshotWin::Initialize(ProcessReaderWin* process_reader) { os_server_ = version_info.wProductType != VER_NT_WORKSTATION; } - const wchar_t kSystemDll[] = L"kernel32.dll"; + static constexpr wchar_t kSystemDll[] = L"kernel32.dll"; VS_FIXEDFILEINFO ffi; if (GetModuleVersionAndType(base::FilePath(kSystemDll), &ffi)) { std::string flags_string = GetStringForFileFlags(ffi.dwFileFlags); diff --git a/test/file.cc b/test/file.cc index 75af744d..04b4625f 100644 --- a/test/file.cc +++ b/test/file.cc @@ -28,11 +28,11 @@ bool FileExists(const base::FilePath& path) { #if defined(OS_POSIX) struct stat st; int rv = lstat(path.value().c_str(), &st); - const char stat_function[] = "lstat"; + static constexpr char stat_function[] = "lstat"; #elif defined(OS_WIN) struct _stat st; int rv = _wstat(path.value().c_str(), &st); - const char stat_function[] = "_wstat"; + static constexpr char stat_function[] = "_wstat"; #else #error "Not implemented" #endif @@ -48,11 +48,11 @@ FileOffset FileSize(const base::FilePath& path) { #if defined(OS_POSIX) struct stat st; int rv = lstat(path.value().c_str(), &st); - const char stat_function[] = "lstat"; + static constexpr char stat_function[] = "lstat"; #elif defined(OS_WIN) struct _stati64 st; int rv = _wstati64(path.value().c_str(), &st); - const char stat_function[] = "_wstati64"; + static constexpr char stat_function[] = "_wstati64"; #else #error "Not implemented" #endif diff --git a/test/hex_string_test.cc b/test/hex_string_test.cc index 1915a856..68745e6f 100644 --- a/test/hex_string_test.cc +++ b/test/hex_string_test.cc @@ -24,7 +24,7 @@ namespace { TEST(HexString, HexString) { EXPECT_EQ(BytesToHexString(nullptr, 0), ""); - const char kBytes[] = "Abc123xyz \x0a\x7f\xf0\x9f\x92\xa9_"; + static constexpr char kBytes[] = "Abc123xyz \x0a\x7f\xf0\x9f\x92\xa9_"; EXPECT_EQ(BytesToHexString(kBytes, arraysize(kBytes)), "41626331323378797a200a7ff09f92a95f00"); } diff --git a/test/win/win_child_process.cc b/test/win/win_child_process.cc index 4c821a0c..44177f63 100644 --- a/test/win/win_child_process.cc +++ b/test/win/win_child_process.cc @@ -35,7 +35,7 @@ namespace test { namespace { -const char kIsMultiprocessChild[] = "--is-multiprocess-child"; +constexpr char kIsMultiprocessChild[] = "--is-multiprocess-child"; bool GetSwitch(const char* switch_name, std::string* value) { int num_args; diff --git a/tools/crashpad_database_util.cc b/tools/crashpad_database_util.cc index b2c4cb49..cc21698b 100644 --- a/tools/crashpad_database_util.cc +++ b/tools/crashpad_database_util.cc @@ -92,7 +92,7 @@ struct Options { // performed. Various string representations of a boolean are recognized // case-insensitively. bool StringToBool(const char* string, bool* boolean) { - const char* const kFalseWords[] = { + static constexpr const char* kFalseWords[] = { "0", "false", "no", @@ -100,7 +100,7 @@ bool StringToBool(const char* string, bool* boolean) { "disabled", "clear", }; - const char* const kTrueWords[] = { + static constexpr const char* kTrueWords[] = { "1", "true", "yes", @@ -153,7 +153,7 @@ bool StringToTime(const char* string, time_t* out_time, bool utc) { const char* end = string + strlen(string); - const char* const kFormats[] = { + static constexpr const char* kFormats[] = { "%Y-%m-%d %H:%M:%S %Z", "%Y-%m-%d %H:%M:%S", "%+", @@ -294,7 +294,7 @@ int DatabaseUtilMain(int argc, char* argv[]) { kOptionVersion = -3, }; - const option long_options[] = { + static constexpr option long_options[] = { {"create", no_argument, nullptr, kOptionCreate}, {"database", required_argument, nullptr, kOptionDatabase}, {"show-client-id", no_argument, nullptr, kOptionShowClientID}, diff --git a/tools/crashpad_http_upload.cc b/tools/crashpad_http_upload.cc index d4ec3f9c..f8a85c43 100644 --- a/tools/crashpad_http_upload.cc +++ b/tools/crashpad_http_upload.cc @@ -74,7 +74,7 @@ int HTTPUploadMain(int argc, char* argv[]) { } options = {}; options.upload_gzip = true; - const option long_options[] = { + static constexpr option long_options[] = { {"file", required_argument, nullptr, kOptionFile}, {"no-upload-gzip", no_argument, nullptr, kOptionNoUploadGzip}, {"output", required_argument, nullptr, kOptionOutput}, diff --git a/tools/generate_dump.cc b/tools/generate_dump.cc index b98b1f4f..956af81b 100644 --- a/tools/generate_dump.cc +++ b/tools/generate_dump.cc @@ -85,7 +85,7 @@ int GenerateDumpMain(int argc, char* argv[]) { } options = {}; options.suspend = true; - const option long_options[] = { + static constexpr option long_options[] = { {"no-suspend", no_argument, nullptr, kOptionNoSuspend}, {"output", required_argument, nullptr, kOptionOutput}, {"help", no_argument, nullptr, kOptionHelp}, diff --git a/tools/mac/catch_exception_tool.cc b/tools/mac/catch_exception_tool.cc index 3a535cb2..d4dc3c12 100644 --- a/tools/mac/catch_exception_tool.cc +++ b/tools/mac/catch_exception_tool.cc @@ -214,7 +214,7 @@ int CatchExceptionToolMain(int argc, char* argv[]) { Options options = {}; - const option long_options[] = { + static constexpr option long_options[] = { {"file", required_argument, nullptr, kOptionFile}, {"mach-service", required_argument, nullptr, kOptionMachService}, {"persistent", no_argument, nullptr, kOptionPersistent}, diff --git a/tools/mac/exception_port_tool.cc b/tools/mac/exception_port_tool.cc index 3faa00fe..a047e964 100644 --- a/tools/mac/exception_port_tool.cc +++ b/tools/mac/exception_port_tool.cc @@ -106,8 +106,8 @@ struct ExceptionHandlerDescription { std::string handler; }; -const char kHandlerNull[] = "NULL"; -const char kHandlerBootstrapColon[] = "bootstrap:"; +constexpr char kHandlerNull[] = "NULL"; +constexpr char kHandlerBootstrapColon[] = "bootstrap:"; // Populates |description| based on a textual representation in // |handler_string_ro|, returning true on success and false on failure (parse @@ -120,11 +120,11 @@ const char kHandlerBootstrapColon[] = "bootstrap:"; // SymbolicConstantsMach. bool ParseHandlerString(const char* handler_string_ro, ExceptionHandlerDescription* description) { - const char kTargetEquals[] = "target="; - const char kMaskEquals[] = "mask="; - const char kBehaviorEquals[] = "behavior="; - const char kFlavorEquals[] = "flavor="; - const char kHandlerEquals[] = "handler="; + static constexpr char kTargetEquals[] = "target="; + static constexpr char kMaskEquals[] = "mask="; + static constexpr char kBehaviorEquals[] = "behavior="; + static constexpr char kFlavorEquals[] = "flavor="; + static constexpr char kHandlerEquals[] = "handler="; std::string handler_string(handler_string_ro); char* handler_string_c = &handler_string[0]; @@ -400,7 +400,7 @@ int ExceptionPortToolMain(int argc, char* argv[]) { bool numeric; } options = {}; - const option long_options[] = { + static constexpr option long_options[] = { {"set-handler", required_argument, nullptr, kOptionSetPort}, {"show-bootstrap", required_argument, nullptr, kOptionShowBootstrap}, {"pid", required_argument, nullptr, kOptionPid}, diff --git a/tools/mac/on_demand_service_tool.mm b/tools/mac/on_demand_service_tool.mm index c6b69520..70de1b52 100644 --- a/tools/mac/on_demand_service_tool.mm +++ b/tools/mac/on_demand_service_tool.mm @@ -81,7 +81,7 @@ int OnDemandServiceToolMain(int argc, char* argv[]) { std::vector mach_services; } options = {}; - const option long_options[] = { + static constexpr option long_options[] = { {"load", no_argument, nullptr, kOptionLoadJob}, {"unload", no_argument, nullptr, kOptionUnloadJob}, {"label", required_argument, nullptr, kOptionJobLabel}, diff --git a/tools/mac/run_with_crashpad.cc b/tools/mac/run_with_crashpad.cc index 135d6d98..39095145 100644 --- a/tools/mac/run_with_crashpad.cc +++ b/tools/mac/run_with_crashpad.cc @@ -84,7 +84,7 @@ int RunWithCrashpadMain(int argc, char* argv[]) { kOptionVersion = -3, }; - const option long_options[] = { + static constexpr option long_options[] = { {"handler", required_argument, nullptr, kOptionHandler}, {"annotation", required_argument, nullptr, kOptionAnnotation}, {"database", required_argument, nullptr, kOptionDatabase}, diff --git a/util/file/delimited_file_reader_test.cc b/util/file/delimited_file_reader_test.cc index 84ecb846..79e331f7 100644 --- a/util/file/delimited_file_reader_test.cc +++ b/util/file/delimited_file_reader_test.cc @@ -257,7 +257,7 @@ TEST(DelimitedFileReader, ReallyLongMultiLineFile) { } TEST(DelimitedFileReader, EmbeddedNUL) { - const char kString[] = "embedded\0NUL\n"; + static constexpr char kString[] = "embedded\0NUL\n"; StringFile string_file; string_file.SetString(std::string(kString, arraysize(kString) - 1)); DelimitedFileReader delimited_file_reader(&string_file); @@ -275,7 +275,7 @@ TEST(DelimitedFileReader, EmbeddedNUL) { } TEST(DelimitedFileReader, NULDelimiter) { - const char kString[] = "aa\0b\0ccc\0"; + static constexpr char kString[] = "aa\0b\0ccc\0"; StringFile string_file; string_file.SetString(std::string(kString, arraysize(kString) - 1)); DelimitedFileReader delimited_file_reader(&string_file); @@ -299,7 +299,8 @@ TEST(DelimitedFileReader, NULDelimiter) { } TEST(DelimitedFileReader, EdgeCases) { - const size_t kSizes[] = {4094, 4095, 4096, 4097, 8190, 8191, 8192, 8193}; + static constexpr size_t kSizes[] = + {4094, 4095, 4096, 4097, 8190, 8191, 8192, 8193}; for (size_t index = 0; index < arraysize(kSizes); ++index) { size_t size = kSizes[index]; SCOPED_TRACE( diff --git a/util/file/file_io_test.cc b/util/file/file_io_test.cc index a784abd2..400cbace 100644 --- a/util/file/file_io_test.cc +++ b/util/file/file_io_test.cc @@ -660,7 +660,7 @@ TEST(FileIO, FileSizeByHandle) { ASSERT_NE(file_handle.get(), kInvalidFileHandle); EXPECT_EQ(LoggingFileSizeByHandle(file_handle.get()), 0); - const char data[] = "zippyzap"; + static constexpr char data[] = "zippyzap"; ASSERT_TRUE(LoggingWriteFile(file_handle.get(), &data, sizeof(data))); EXPECT_EQ(LoggingFileSizeByHandle(file_handle.get()), 9); diff --git a/util/linux/process_memory_test.cc b/util/linux/process_memory_test.cc index 21377553..4ad2e756 100644 --- a/util/linux/process_memory_test.cc +++ b/util/linux/process_memory_test.cc @@ -135,8 +135,8 @@ bool ReadCStringSizeLimited(const ProcessMemory& memory, FromPointerCast(pointer), size, result); } -const char kConstCharEmpty[] = ""; -const char kConstCharShort[] = "A short const char[]"; +constexpr char kConstCharEmpty[] = ""; +constexpr char kConstCharShort[] = "A short const char[]"; class ReadCStringTest : public TargetProcessTest { public: diff --git a/util/mac/checked_mach_address_range_test.cc b/util/mac/checked_mach_address_range_test.cc index 860bdff8..089f6815 100644 --- a/util/mac/checked_mach_address_range_test.cc +++ b/util/mac/checked_mach_address_range_test.cc @@ -43,7 +43,7 @@ bool ExpectationForValidity64(Validity validity) { } TEST(CheckedMachAddressRange, IsValid) { - const struct TestData { + static constexpr struct { mach_vm_address_t base; mach_vm_size_t size; Validity validity; @@ -117,7 +117,7 @@ TEST(CheckedMachAddressRange, IsValid) { }; for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& testcase = kTestData[index]; + const auto& testcase = kTestData[index]; SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx", index, testcase.base, @@ -132,7 +132,7 @@ TEST(CheckedMachAddressRange, IsValid) { } TEST(CheckedMachAddressRange, ContainsValue) { - const struct TestData { + static constexpr struct { mach_vm_address_t value; bool expectation; } kTestData[] = { @@ -167,7 +167,7 @@ TEST(CheckedMachAddressRange, ContainsValue) { ASSERT_TRUE(parent_range_32.IsValid()); for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& testcase = kTestData[index]; + const auto& testcase = kTestData[index]; SCOPED_TRACE( base::StringPrintf("index %zu, value 0x%llx", index, testcase.value)); @@ -185,7 +185,7 @@ TEST(CheckedMachAddressRange, ContainsValue) { } TEST(CheckedMachAddressRange, ContainsRange) { - const struct TestData { + static constexpr struct { mach_vm_address_t base; mach_vm_size_t size; bool expectation; @@ -224,7 +224,7 @@ TEST(CheckedMachAddressRange, ContainsRange) { ASSERT_TRUE(parent_range_32.IsValid()); for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& testcase = kTestData[index]; + const auto& testcase = kTestData[index]; SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx", index, testcase.base, diff --git a/util/mac/launchd_test.mm b/util/mac/launchd_test.mm index 8d9db762..12ed8320 100644 --- a/util/mac/launchd_test.mm +++ b/util/mac/launchd_test.mm @@ -153,7 +153,7 @@ TEST(Launchd, CFPropertyToLaunchData_Data) { @autoreleasepool { base::mac::ScopedLaunchData launch_data; - const uint8_t data_c[] = { + static constexpr uint8_t data_c[] = { 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 6, 5, 4, 3, 2}; NSData* data_ns = [NSData dataWithBytes:data_c length:sizeof(data_c)]; launch_data.reset(CFPropertyToLaunchData(data_ns)); diff --git a/util/mac/service_management_test.mm b/util/mac/service_management_test.mm index 769c32f1..55019df0 100644 --- a/util/mac/service_management_test.mm +++ b/util/mac/service_management_test.mm @@ -114,7 +114,8 @@ TEST(ServiceManagement, SubmitRemoveJob) { base::StringPrintf("sleep 10; echo %s", cookie.c_str()); NSString* shell_script_ns = base::SysUTF8ToNSString(shell_script); - const char kJobLabel[] = "org.chromium.crashpad.test.service_management"; + static constexpr char kJobLabel[] = + "org.chromium.crashpad.test.service_management"; NSDictionary* job_dictionary_ns = @{ @LAUNCH_JOBKEY_LABEL : @"org.chromium.crashpad.test.service_management", @LAUNCH_JOBKEY_RUNATLOAD : @YES, diff --git a/util/mac/xattr_test.cc b/util/mac/xattr_test.cc index 477bb138..56318d13 100644 --- a/util/mac/xattr_test.cc +++ b/util/mac/xattr_test.cc @@ -55,7 +55,7 @@ class Xattr : public testing::Test { base::FilePath path_; }; -const char kKey[] = "com.google.crashpad.test"; +constexpr char kKey[] = "org.chromium.crashpad.test"; TEST_F(Xattr, ReadNonExistentXattr) { std::string value; diff --git a/util/mach/child_port_server.cc b/util/mach/child_port_server.cc index 4fc723ac..9a34d431 100644 --- a/util/mach/child_port_server.cc +++ b/util/mach/child_port_server.cc @@ -106,7 +106,8 @@ bool ChildPortServer::MachMessageServerFunction( } std::set ChildPortServer::MachMessageServerRequestIDs() { - const mach_msg_id_t request_ids[] = {kMachMessageIDChildPortCheckIn}; + static constexpr mach_msg_id_t request_ids[] = + {kMachMessageIDChildPortCheckIn}; return std::set(&request_ids[0], &request_ids[arraysize(request_ids)]); } diff --git a/util/mach/composite_mach_message_server_test.cc b/util/mach/composite_mach_message_server_test.cc index 3a37e49b..9325ba33 100644 --- a/util/mach/composite_mach_message_server_test.cc +++ b/util/mach/composite_mach_message_server_test.cc @@ -182,13 +182,13 @@ TEST(CompositeMachMessageServer, OneHandler) { } TEST(CompositeMachMessageServer, ThreeHandlers) { - const mach_msg_id_t kRequestIDs0[] = {5}; + static constexpr mach_msg_id_t kRequestIDs0[] = {5}; const kern_return_t kReturnCode0 = KERN_SUCCESS; - const mach_msg_id_t kRequestIDs1[] = {4, 7}; + static constexpr mach_msg_id_t kRequestIDs1[] = {4, 7}; const kern_return_t kReturnCode1 = KERN_PROTECTION_FAILURE; - const mach_msg_id_t kRequestIDs2[] = {10, 0, 20}; + static constexpr mach_msg_id_t kRequestIDs2[] = {10, 0, 20}; const mach_msg_size_t kRequestSize2 = 6144; const mach_msg_size_t kReplySize2 = 16384; const kern_return_t kReturnCode2 = KERN_NOT_RECEIVER; diff --git a/util/mach/exc_client_variants_test.cc b/util/mach/exc_client_variants_test.cc index 3bf77bb5..b7288563 100644 --- a/util/mach/exc_client_variants_test.cc +++ b/util/mach/exc_client_variants_test.cc @@ -264,7 +264,7 @@ mach_exception_subcode_t TestExcClientVariants::exception_subcode_ = 0xffffffff00000000; TEST(ExcClientVariants, UniversalExceptionRaise) { - const exception_behavior_t kBehaviors[] = { + static constexpr exception_behavior_t kBehaviors[] = { EXCEPTION_DEFAULT, EXCEPTION_STATE, EXCEPTION_STATE_IDENTITY, diff --git a/util/mach/exc_server_variants_test.cc b/util/mach/exc_server_variants_test.cc index 482edac3..149184b2 100644 --- a/util/mach/exc_server_variants_test.cc +++ b/util/mach/exc_server_variants_test.cc @@ -877,7 +877,7 @@ TEST(ExcServerVariants, MockUnknownID) { // UniversalMachExcServer should not dispatch the message to // MachMessageServerFunction, but should generate a MIG_BAD_ID error reply. - const mach_msg_id_t unknown_ids[] = { + static constexpr mach_msg_id_t unknown_ids[] = { // Reasonable things to check. -101, -100, @@ -1130,11 +1130,10 @@ TEST(ExcServerVariants, ThreadStates) { // So far, all of the tests worked with MACHINE_THREAD_STATE. Now try all of // the other thread state flavors that are expected to work. - struct TestData { + static constexpr struct { thread_state_flavor_t flavor; mach_msg_type_number_t count; - }; - const TestData test_data[] = { + } test_data[] = { #if defined(ARCH_CPU_X86_FAMILY) // For the x86 family, exception handlers can only properly receive the // thread, float, and exception state flavors. There’s a bug in the kernel @@ -1179,7 +1178,7 @@ TEST(ExcServerVariants, ThreadStates) { }; for (size_t index = 0; index < arraysize(test_data); ++index) { - const TestData& test = test_data[index]; + const auto& test = test_data[index]; SCOPED_TRACE( base::StringPrintf("index %zu, flavor %d", index, test.flavor)); @@ -1195,13 +1194,12 @@ TEST(ExcServerVariants, ExcServerSuccessfulReturnValue) { const kern_return_t prefer_not_set_thread_state = MacOSXMinorVersion() < 11 ? MACH_RCV_PORT_DIED : KERN_SUCCESS; - struct TestData { + const struct { exception_type_t exception; exception_behavior_t behavior; bool set_thread_state; kern_return_t kr; - }; - const TestData kTestData[] = { + } kTestData[] = { {EXC_CRASH, EXCEPTION_DEFAULT, false, KERN_SUCCESS}, {EXC_CRASH, EXCEPTION_STATE, false, prefer_not_set_thread_state}, {EXC_CRASH, EXCEPTION_STATE_IDENTITY, false, prefer_not_set_thread_state}, @@ -1253,7 +1251,7 @@ TEST(ExcServerVariants, ExcServerSuccessfulReturnValue) { }; for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& test_data = kTestData[index]; + const auto& test_data = kTestData[index]; SCOPED_TRACE( base::StringPrintf("index %zu, behavior %d, set_thread_state %s", index, @@ -1268,7 +1266,7 @@ TEST(ExcServerVariants, ExcServerSuccessfulReturnValue) { } TEST(ExcServerVariants, ExcServerCopyState) { - const natural_t old_state[] = {1, 2, 3, 4, 5}; + static constexpr natural_t old_state[] = {1, 2, 3, 4, 5}; natural_t new_state[10] = {}; const mach_msg_type_number_t old_state_count = arraysize(old_state); diff --git a/util/mach/exception_behaviors_test.cc b/util/mach/exception_behaviors_test.cc index 3ccb2027..d45110d9 100644 --- a/util/mach/exception_behaviors_test.cc +++ b/util/mach/exception_behaviors_test.cc @@ -26,14 +26,13 @@ namespace test { namespace { TEST(ExceptionBehaviors, ExceptionBehaviors) { - struct TestData { + static constexpr struct { exception_behavior_t behavior; bool state; bool identity; bool mach_exception_codes; exception_behavior_t basic_behavior; - }; - const TestData kTestData[] = { + } kTestData[] = { {EXCEPTION_DEFAULT, false, true, false, EXCEPTION_DEFAULT}, {EXCEPTION_STATE, true, false, false, EXCEPTION_STATE}, {EXCEPTION_STATE_IDENTITY, true, true, false, EXCEPTION_STATE_IDENTITY}, @@ -55,7 +54,7 @@ TEST(ExceptionBehaviors, ExceptionBehaviors) { }; for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& test_data = kTestData[index]; + const auto& test_data = kTestData[index]; SCOPED_TRACE(base::StringPrintf( "index %zu, behavior %d", index, test_data.behavior)); diff --git a/util/mach/exception_types_test.cc b/util/mach/exception_types_test.cc index ff09164e..c24428a2 100644 --- a/util/mach/exception_types_test.cc +++ b/util/mach/exception_types_test.cc @@ -31,13 +31,12 @@ namespace test { namespace { TEST(ExceptionTypes, ExcCrashRecoverOriginalException) { - struct TestData { + static constexpr struct { mach_exception_code_t code_0; exception_type_t exception; mach_exception_code_t original_code_0; int signal; - }; - const TestData kTestData[] = { + } kTestData[] = { {0xb100001, EXC_BAD_ACCESS, KERN_INVALID_ADDRESS, SIGSEGV}, {0xb100002, EXC_BAD_ACCESS, KERN_PROTECTION_FAILURE, SIGSEGV}, {0xa100002, EXC_BAD_ACCESS, KERN_PROTECTION_FAILURE, SIGBUS}, @@ -69,7 +68,7 @@ TEST(ExceptionTypes, ExcCrashRecoverOriginalException) { }; for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& test_data = kTestData[index]; + const auto& test_data = kTestData[index]; SCOPED_TRACE(base::StringPrintf( "index %zu, code_0 0x%llx", index, test_data.code_0)); @@ -86,7 +85,7 @@ TEST(ExceptionTypes, ExcCrashRecoverOriginalException) { // Now make sure that ExcCrashRecoverOriginalException() properly ignores // optional arguments. static_assert(arraysize(kTestData) >= 1, "must have something to test"); - const TestData& test_data = kTestData[0]; + const auto& test_data = kTestData[0]; EXPECT_EQ( ExcCrashRecoverOriginalException(test_data.code_0, nullptr, nullptr), test_data.exception); @@ -133,12 +132,11 @@ TEST(ExceptionTypes, ExcCrashCouldContainException) { (static_cast(flavor) & 0x7ull) << 58))) TEST(ExceptionTypes, ExceptionCodeForMetrics) { - struct TestData { + static constexpr struct { exception_type_t exception; mach_exception_code_t code_0; int32_t metrics_code; - }; - const TestData kTestData[] = { + } kTestData[] = { #define ENCODE_EXC(type, code_0) \ { (type), (code_0), ((type) << 16) | (code_0) } ENCODE_EXC(EXC_BAD_ACCESS, KERN_INVALID_ADDRESS), @@ -241,7 +239,7 @@ TEST(ExceptionTypes, ExceptionCodeForMetrics) { }; for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& test_data = kTestData[index]; + const auto& test_data = kTestData[index]; SCOPED_TRACE(base::StringPrintf("index %zu, exception 0x%x, code_0 0x%llx", index, test_data.exception, diff --git a/util/mach/mach_message_server_test.cc b/util/mach/mach_message_server_test.cc index e42ef6a5..e0ffebe8 100644 --- a/util/mach/mach_message_server_test.cc +++ b/util/mach/mach_message_server_test.cc @@ -279,7 +279,7 @@ class TestMachMessageServer : public MachMessageServer::Interface, } std::set MachMessageServerRequestIDs() override { - const mach_msg_id_t request_ids[] = {kRequestMessageID}; + static constexpr mach_msg_id_t request_ids[] = {kRequestMessageID}; return std::set(&request_ids[0], &request_ids[arraysize(request_ids)]); } diff --git a/util/mach/notify_server.cc b/util/mach/notify_server.cc index 9ac377d1..2dbdf73e 100644 --- a/util/mach/notify_server.cc +++ b/util/mach/notify_server.cc @@ -259,7 +259,7 @@ bool NotifyServer::MachMessageServerFunction( } std::set NotifyServer::MachMessageServerRequestIDs() { - const mach_msg_id_t request_ids[] = { + static constexpr mach_msg_id_t request_ids[] = { MACH_NOTIFY_PORT_DELETED, MACH_NOTIFY_PORT_DESTROYED, MACH_NOTIFY_NO_SENDERS, diff --git a/util/mach/symbolic_constants_mach.cc b/util/mach/symbolic_constants_mach.cc index 26cc564f..b7296be2 100644 --- a/util/mach/symbolic_constants_mach.cc +++ b/util/mach/symbolic_constants_mach.cc @@ -26,7 +26,7 @@ namespace { -const char* kExceptionNames[] = { +constexpr const char* kExceptionNames[] = { nullptr, // sed -Ene 's/^#define[[:space:]]EXC_([[:graph:]]+)[[:space:]]+[[:digit:]]{1,2}([[:space:]]|$).*/ "\1",/p' @@ -48,10 +48,10 @@ const char* kExceptionNames[] = { static_assert(arraysize(kExceptionNames) == EXC_TYPES_COUNT, "kExceptionNames length"); -const char kExcPrefix[] = "EXC_"; -const char kExcMaskPrefix[] = "EXC_MASK_"; +constexpr char kExcPrefix[] = "EXC_"; +constexpr char kExcMaskPrefix[] = "EXC_MASK_"; -const char* kBehaviorNames[] = { +constexpr const char* kBehaviorNames[] = { nullptr, // sed -Ene 's/^# define[[:space:]]EXCEPTION_([[:graph:]]+)[[:space:]]+[[:digit:]]{1,2}([[:space:]]|$).*/ "\1",/p' @@ -61,11 +61,11 @@ const char* kBehaviorNames[] = { "STATE_IDENTITY", }; -const char kBehaviorPrefix[] = "EXCEPTION_"; -const char kMachExceptionCodesFull[] = "MACH_EXCEPTION_CODES"; -const char kMachExceptionCodesShort[] = "MACH"; +constexpr char kBehaviorPrefix[] = "EXCEPTION_"; +constexpr char kMachExceptionCodesFull[] = "MACH_EXCEPTION_CODES"; +constexpr char kMachExceptionCodesShort[] = "MACH"; -const char* kFlavorNames[] = { +constexpr const char* kFlavorNames[] = { "THREAD_STATE_FLAVOR_LIST", #if defined(__i386__) || defined(__x86_64__) @@ -128,7 +128,7 @@ const char* kFlavorNames[] = { // Certain generic flavors have high constants not contiguous with the flavors // above. List them separately alongside their constants. -const struct { +constexpr struct { thread_state_flavor_t flavor; const char* name; } kGenericFlavorNames[] = { @@ -139,7 +139,7 @@ const struct { // Returns the short name for a flavor name, given its full flavor name. std::string ThreadStateFlavorFullToShort(const base::StringPiece& flavor) { // For generic flavors like THREAD_STATE_NONE and THREAD_STATE_FLAVOR_LIST_*. - const char kThreadState[] = "THREAD_STATE_"; + static constexpr char kThreadState[] = "THREAD_STATE_"; size_t prefix_len = strlen(kThreadState); const char* flavor_data = flavor.data(); size_t flavor_len = flavor.size(); @@ -150,11 +150,11 @@ std::string ThreadStateFlavorFullToShort(const base::StringPiece& flavor) { // For architecture-specific flavors. #if defined(__i386__) || defined(__x86_64__) - const char kArchPrefix[] = "x86_"; + static constexpr char kArchPrefix[] = "x86_"; #elif defined(__ppc__) || defined(__ppc64__) - const char kArchPrefix[] = "PPC_"; + static constexpr char kArchPrefix[] = "PPC_"; #elif defined(__arm__) || defined(__arm64__) - const char kArchPrefix[] = "ARM_" + static constexpr char kArchPrefix[] = "ARM_" #endif prefix_len = strlen(kArchPrefix); if (flavor_len >= prefix_len && @@ -162,7 +162,7 @@ std::string ThreadStateFlavorFullToShort(const base::StringPiece& flavor) { // Shorten the suffix by removing _STATE. If the suffix contains a // significant designation like 32 or 64, keep it, so that a full name like // x86_THREAD_STATE64 becomes a short name like THREAD64. - const struct { + static constexpr struct { const char* orig; const char* repl; } kStateSuffixes[] = { @@ -343,7 +343,7 @@ bool StringToExceptionMask(const base::StringPiece& string, // EXC_MASK_ALL is a special case: it is not in kExceptionNames as it exists // only as a mask value. - const char kExcMaskAll[] = "ALL"; + static constexpr char kExcMaskAll[] = "ALL"; if ((can_match_full && short_string.compare(kExcMaskAll) == 0) || ((options & kAllowShortName) && string.compare(kExcMaskAll) == 0)) { *exception_mask = ExcMaskAll(); diff --git a/util/mach/symbolic_constants_mach_test.cc b/util/mach/symbolic_constants_mach_test.cc index f3086d25..c8d6d48e 100644 --- a/util/mach/symbolic_constants_mach_test.cc +++ b/util/mach/symbolic_constants_mach_test.cc @@ -32,7 +32,7 @@ namespace test { namespace { // Options to use for normal tests, those that don’t require kAllowOr. -const StringToSymbolicConstantOptions kNormalOptions[] = { +constexpr StringToSymbolicConstantOptions kNormalOptions[] = { 0, kAllowFullName, kAllowShortName, @@ -118,7 +118,7 @@ void TestStringToSomething(const base::StringPiece& string, } } -const struct { +constexpr struct { exception_type_t exception; const char* full_name; const char* short_name; @@ -217,7 +217,7 @@ TEST(SymbolicConstantsMach, StringToException) { } } - const char* const kNegativeTestData[] = { + static constexpr const char* kNegativeTestData[] = { "EXC_CRASH ", " EXC_BAD_INSTRUCTION", "CRASH ", @@ -235,7 +235,7 @@ TEST(SymbolicConstantsMach, StringToException) { TestStringToException(kNegativeTestData[index], options, false, 0); } - const struct { + static constexpr struct { const char* string; size_t length; } kNULTestData[] = { @@ -276,7 +276,7 @@ TEST(SymbolicConstantsMach, StringToException) { } } -const struct { +constexpr struct { exception_mask_t exception_mask; const char* full_name; const char* short_name; @@ -370,7 +370,7 @@ void TestStringToExceptionMask(const base::StringPiece& string, TEST(SymbolicConstantsMach, StringToExceptionMask) { // Don’t use kNormalOptions, because kAllowOr needs to be tested. - const StringToSymbolicConstantOptions kOptions[] = { + static constexpr StringToSymbolicConstantOptions kOptions[] = { 0, kAllowFullName, kAllowShortName, @@ -430,7 +430,7 @@ TEST(SymbolicConstantsMach, StringToExceptionMask) { } } - const char* const kNegativeTestData[] = { + static constexpr const char* kNegativeTestData[] = { "EXC_MASK_CRASH ", " EXC_MASK_BAD_INSTRUCTION", "EXC_MASK_EXC_MASK_BAD_ACCESS", @@ -450,7 +450,7 @@ TEST(SymbolicConstantsMach, StringToExceptionMask) { TestStringToExceptionMask(kNegativeTestData[index], options, false, 0); } - const struct { + static constexpr struct { const char* string; size_t length; } kNULTestData[] = { @@ -479,7 +479,7 @@ TEST(SymbolicConstantsMach, StringToExceptionMask) { } } - const struct { + static const struct { const char* string; StringToSymbolicConstantOptions options; exception_mask_t mask; @@ -531,7 +531,7 @@ TEST(SymbolicConstantsMach, StringToExceptionMask) { } } -const struct { +constexpr struct { exception_behavior_t behavior; const char* full_name; const char* short_name; @@ -643,7 +643,7 @@ TEST(SymbolicConstantsMach, StringToExceptionBehavior) { } } - const char* const kNegativeTestData[] = { + static constexpr const char* kNegativeTestData[] = { "EXCEPTION_DEFAULT ", " EXCEPTION_STATE", "EXCEPTION_EXCEPTION_STATE_IDENTITY", @@ -666,7 +666,7 @@ TEST(SymbolicConstantsMach, StringToExceptionBehavior) { kNegativeTestData[index], options, false, 0); } - const struct { + static constexpr struct { const char* string; size_t length; } kNULTestData[] = { @@ -694,7 +694,7 @@ TEST(SymbolicConstantsMach, StringToExceptionBehavior) { } } - const struct { + static constexpr struct { const char* string; StringToSymbolicConstantOptions options; exception_behavior_t behavior; @@ -763,7 +763,7 @@ TEST(SymbolicConstantsMach, StringToExceptionBehavior) { } } -const struct { +constexpr struct { thread_state_flavor_t flavor; const char* full_name; const char* short_name; @@ -917,7 +917,7 @@ TEST(SymbolicConstantsMach, StringToThreadStateFlavor) { } } - const char* const kNegativeTestData[] = { + static constexpr const char* kNegativeTestData[] = { "THREAD_STATE_NONE ", " THREAD_STATE_NONE", "NONE ", @@ -965,7 +965,7 @@ TEST(SymbolicConstantsMach, StringToThreadStateFlavor) { kNegativeTestData[index], options, false, 0); } - const struct { + static constexpr struct { const char* string; size_t length; } kNULTestData[] = { diff --git a/util/mach/task_memory_test.cc b/util/mach/task_memory_test.cc index 514f48f1..24adb409 100644 --- a/util/mach/task_memory_test.cc +++ b/util/mach/task_memory_test.cc @@ -194,6 +194,27 @@ TEST(TaskMemory, ReadCStringSelf) { EXPECT_FALSE(result.empty()); EXPECT_EQ(result, kStaticConstCharShort); + constexpr char kConstexprCharEmpty[] = ""; + ASSERT_TRUE(ReadCStringSelf(&memory, kConstexprCharEmpty, &result)); + EXPECT_TRUE(result.empty()); + EXPECT_EQ(result, kConstexprCharEmpty); + + constexpr char kConstexprCharShort[] = "A short constexpr char[]"; + ASSERT_TRUE(ReadCStringSelf(&memory, kConstexprCharShort, &result)); + EXPECT_FALSE(result.empty()); + EXPECT_EQ(result, kConstexprCharShort); + + static constexpr char kStaticConstexprCharEmpty[] = ""; + ASSERT_TRUE(ReadCStringSelf(&memory, kStaticConstexprCharEmpty, &result)); + EXPECT_TRUE(result.empty()); + EXPECT_EQ(result, kStaticConstexprCharEmpty); + + static constexpr char kStaticConstexprCharShort[] = + "A short static constexpr char[]"; + ASSERT_TRUE(ReadCStringSelf(&memory, kStaticConstexprCharShort, &result)); + EXPECT_FALSE(result.empty()); + EXPECT_EQ(result, kStaticConstexprCharShort); + std::string string_short("A short std::string in a function"); ASSERT_TRUE(ReadCStringSelf(&memory, &string_short[0], &result)); EXPECT_FALSE(result.empty()); @@ -280,7 +301,7 @@ TEST(TaskMemory, ReadCStringSizeLimited_ConstCharEmpty) { TaskMemory memory(mach_task_self()); std::string result; - const char kConstCharEmpty[] = ""; + static constexpr char kConstCharEmpty[] = ""; ASSERT_TRUE(ReadCStringSizeLimitedSelf( &memory, kConstCharEmpty, arraysize(kConstCharEmpty), &result)); EXPECT_TRUE(result.empty()); @@ -302,7 +323,7 @@ TEST(TaskMemory, ReadCStringSizeLimited_ConstCharShort) { TaskMemory memory(mach_task_self()); std::string result; - const char kConstCharShort[] = "A short const char[]"; + static constexpr char kConstCharShort[] = "A short const char[]"; ASSERT_TRUE(ReadCStringSizeLimitedSelf( &memory, kConstCharShort, arraysize(kConstCharShort), &result)); EXPECT_FALSE(result.empty()); @@ -322,7 +343,7 @@ TEST(TaskMemory, ReadCStringSizeLimited_StaticConstCharEmpty) { TaskMemory memory(mach_task_self()); std::string result; - static const char kStaticConstCharEmpty[] = ""; + static constexpr char kStaticConstCharEmpty[] = ""; ASSERT_TRUE(ReadCStringSizeLimitedSelf(&memory, kStaticConstCharEmpty, arraysize(kStaticConstCharEmpty), @@ -349,7 +370,8 @@ TEST(TaskMemory, ReadCStringSizeLimited_StaticConstCharShort) { TaskMemory memory(mach_task_self()); std::string result; - static const char kStaticConstCharShort[] = "A short static const char[]"; + static constexpr char kStaticConstCharShort[] = + "A short static constexpr char[]"; ASSERT_TRUE(ReadCStringSizeLimitedSelf(&memory, kStaticConstCharShort, arraysize(kStaticConstCharShort), @@ -461,7 +483,7 @@ TEST(TaskMemory, MappedMemoryDeallocates) { TaskMemory memory(mach_task_self()); std::unique_ptr mapped; - static const char kTestBuffer[] = "hello!"; + static constexpr char kTestBuffer[] = "hello!"; mach_vm_address_t test_address = FromPointerCast(&kTestBuffer); ASSERT_TRUE((mapped = memory.ReadMapped(test_address, sizeof(kTestBuffer)))); @@ -498,7 +520,7 @@ TEST(TaskMemory, MappedMemoryReadCString) { TaskMemory memory(mach_task_self()); std::unique_ptr mapped; - static const char kTestBuffer[] = "0\0" "2\0" "45\0" "789"; + static constexpr char kTestBuffer[] = "0\0" "2\0" "45\0" "789"; const mach_vm_address_t kTestAddress = FromPointerCast(&kTestBuffer); ASSERT_TRUE((mapped = memory.ReadMapped(kTestAddress, 10))); diff --git a/util/misc/clock_test.cc b/util/misc/clock_test.cc index d7f9cd71..95330eb2 100644 --- a/util/misc/clock_test.cc +++ b/util/misc/clock_test.cc @@ -71,7 +71,7 @@ void TestSleepNanoseconds(uint64_t nanoseconds) { } TEST(Clock, SleepNanoseconds) { - const uint64_t kTestData[] = { + static constexpr uint64_t kTestData[] = { 0, 1, static_cast(1E3), // 1 microsecond diff --git a/util/misc/implicit_cast.h b/util/misc/implicit_cast.h index 6f8a1a30..018800ab 100644 --- a/util/misc/implicit_cast.h +++ b/util/misc/implicit_cast.h @@ -34,8 +34,8 @@ namespace crashpad { // implicit_cast would have been part of the C++ standard library, // but the proposal was submitted too late. It will probably make // its way into the language in the future. -template -inline To implicit_cast(From const &f) { +template +constexpr To implicit_cast(From const& f) { return f; } diff --git a/util/misc/scoped_forbid_return_test.cc b/util/misc/scoped_forbid_return_test.cc index 78787d49..4f73ea58 100644 --- a/util/misc/scoped_forbid_return_test.cc +++ b/util/misc/scoped_forbid_return_test.cc @@ -43,7 +43,7 @@ void ScopedForbidReturnHelper(ForbidReturnType type) { } } -const char kForbiddenMessage[] = "attempt to exit scope forbidden"; +constexpr char kForbiddenMessage[] = "attempt to exit scope forbidden"; TEST(ScopedForbidReturnDeathTest, Default) { // kForbiddenMessage may appear to be unused if ASSERT_DEATH_CHECK() throws it diff --git a/util/misc/uuid.cc b/util/misc/uuid.cc index ac2468c6..12c7935a 100644 --- a/util/misc/uuid.cc +++ b/util/misc/uuid.cc @@ -66,7 +66,7 @@ bool UUID::InitializeFromString(const base::StringPiece& string) { return false; UUID temp; - const char kScanFormat[] = + static constexpr char kScanFormat[] = "%08" SCNx32 "-%04" SCNx16 "-%04" SCNx16 "-%02" SCNx8 "%02" SCNx8 "-%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8; diff --git a/util/misc/uuid_test.cc b/util/misc/uuid_test.cc index e550751b..72b8216b 100644 --- a/util/misc/uuid_test.cc +++ b/util/misc/uuid_test.cc @@ -45,22 +45,22 @@ TEST(UUID, UUID) { EXPECT_EQ(uuid_zero.data_5[5], 0u); EXPECT_EQ(uuid_zero.ToString(), "00000000-0000-0000-0000-000000000000"); - const uint8_t kBytes[16] = {0x00, - 0x01, - 0x02, - 0x03, - 0x04, - 0x05, - 0x06, - 0x07, - 0x08, - 0x09, - 0x0a, - 0x0b, - 0x0c, - 0x0d, - 0x0e, - 0x0f}; + static constexpr uint8_t kBytes[16] = {0x00, + 0x01, + 0x02, + 0x03, + 0x04, + 0x05, + 0x06, + 0x07, + 0x08, + 0x09, + 0x0a, + 0x0b, + 0x0c, + 0x0d, + 0x0e, + 0x0f}; UUID uuid; uuid.InitializeFromBytes(kBytes); EXPECT_EQ(uuid.data_1, 0x00010203u); @@ -110,22 +110,22 @@ TEST(UUID, UUID) { // have been valid. EXPECT_EQ(uuid_2, uuid); - const uint8_t kMoreBytes[16] = {0xff, - 0xee, - 0xdd, - 0xcc, - 0xbb, - 0xaa, - 0x99, - 0x88, - 0x77, - 0x66, - 0x55, - 0x44, - 0x33, - 0x22, - 0x11, - 0x00}; + static constexpr uint8_t kMoreBytes[16] = {0xff, + 0xee, + 0xdd, + 0xcc, + 0xbb, + 0xaa, + 0x99, + 0x88, + 0x77, + 0x66, + 0x55, + 0x44, + 0x33, + 0x22, + 0x11, + 0x00}; uuid.InitializeFromBytes(kMoreBytes); EXPECT_EQ(uuid.data_1, 0xffeeddccu); EXPECT_EQ(uuid.data_2, 0xbbaau); @@ -164,7 +164,7 @@ TEST(UUID, UUID) { } TEST(UUID, FromString) { - const struct TestCase { + static constexpr struct TestCase { const char* uuid_string; bool success; } kCases[] = { diff --git a/util/net/http_multipart_builder.cc b/util/net/http_multipart_builder.cc index 91105be9..cd88e430 100644 --- a/util/net/http_multipart_builder.cc +++ b/util/net/http_multipart_builder.cc @@ -29,9 +29,9 @@ namespace crashpad { namespace { -const char kCRLF[] = "\r\n"; +constexpr char kCRLF[] = "\r\n"; -const char kBoundaryCRLF[] = "\r\n\r\n"; +constexpr char kBoundaryCRLF[] = "\r\n\r\n"; // Generates a random string suitable for use as a multipart boundary. std::string GenerateBoundaryString() { @@ -47,7 +47,7 @@ std::string GenerateBoundaryString() { // randomness (62^32 > 2^190). std::string boundary_string = "---MultipartBoundary-"; for (int index = 0; index < 32; ++index) { - const char kCharacters[] = + static constexpr char kCharacters[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; int random_value = base::RandInt(0, static_cast(strlen(kCharacters)) - 1); diff --git a/util/net/http_multipart_builder_test.cc b/util/net/http_multipart_builder_test.cc index 79366bc2..71b2fa84 100644 --- a/util/net/http_multipart_builder_test.cc +++ b/util/net/http_multipart_builder_test.cc @@ -55,16 +55,16 @@ std::vector SplitCRLF(const std::string& string) { TEST(HTTPMultipartBuilder, ThreeStringFields) { HTTPMultipartBuilder builder; - const char kKey1[] = "key1"; - const char kValue1[] = "test"; + static constexpr char kKey1[] = "key1"; + static constexpr char kValue1[] = "test"; builder.SetFormData(kKey1, kValue1); - const char kKey2[] = "key2"; - const char kValue2[] = "This is another test."; + static constexpr char kKey2[] = "key2"; + static constexpr char kValue2[] = "This is another test."; builder.SetFormData(kKey2, kValue2); - const char kKey3[] = "key-three"; - const char kValue3[] = "More tests"; + static constexpr char kKey3[] = "key-three"; + static constexpr char kValue3[] = "More tests"; builder.SetFormData(kKey3, kValue3); std::unique_ptr body(builder.GetBodyStream()); @@ -115,7 +115,7 @@ TEST(HTTPMultipartBuilder, ThreeFileAttachments) { ascii_http_body_path, "text/plain"); - const char kFileContents[] = "This is a test.\n"; + static constexpr char kFileContents[] = "This is a test.\n"; std::unique_ptr body(builder.GetBodyStream()); ASSERT_TRUE(body.get()); @@ -158,7 +158,7 @@ TEST(HTTPMultipartBuilder, ThreeFileAttachments) { TEST(HTTPMultipartBuilder, OverwriteFormDataWithEscapedKey) { HTTPMultipartBuilder builder; - const char kKey[] = "a 100% \"silly\"\r\ntest"; + static constexpr char kKey[] = "a 100% \"silly\"\r\ntest"; builder.SetFormData(kKey, "some dummy value"); builder.SetFormData(kKey, "overwrite"); std::unique_ptr body(builder.GetBodyStream()); @@ -183,7 +183,7 @@ TEST(HTTPMultipartBuilder, OverwriteFormDataWithEscapedKey) { TEST(HTTPMultipartBuilder, OverwriteFileAttachment) { HTTPMultipartBuilder builder; - const char kValue[] = "1 2 3 test"; + static constexpr char kValue[] = "1 2 3 test"; builder.SetFormData("a key", kValue); base::FilePath testdata_path = TestPaths::TestDataRoot().Append(FILE_PATH_LITERAL("util/net/testdata")); @@ -240,7 +240,7 @@ TEST(HTTPMultipartBuilder, OverwriteFileAttachment) { TEST(HTTPMultipartBuilder, SharedFormDataAndAttachmentKeyNamespace) { HTTPMultipartBuilder builder; - const char kValue1[] = "11111"; + static constexpr char kValue1[] = "11111"; builder.SetFormData("one", kValue1); base::FilePath ascii_http_body_path = TestPaths::TestDataRoot().Append( FILE_PATH_LITERAL("util/net/testdata/ascii_http_body.txt")); @@ -248,7 +248,7 @@ TEST(HTTPMultipartBuilder, SharedFormDataAndAttachmentKeyNamespace) { "minidump.dmp", ascii_http_body_path, ""); - const char kValue2[] = "this is not a file"; + static constexpr char kValue2[] = "this is not a file"; builder.SetFormData("minidump", kValue2); std::unique_ptr body(builder.GetBodyStream()); diff --git a/util/net/http_transport_libcurl.cc b/util/net/http_transport_libcurl.cc index 1a20913a..70da696d 100644 --- a/util/net/http_transport_libcurl.cc +++ b/util/net/http_transport_libcurl.cc @@ -57,31 +57,31 @@ std::string UserAgent() { // linux-4.9.17/arch/x86/kernel/cpu/bugs.c check_bugs() sets the first digit // to 4, 5, or 6, but no higher. #if defined(__i686__) - const char arch[] = "i686"; + static constexpr char arch[] = "i686"; #elif defined(__i586__) - const char arch[] = "i586"; + static constexpr char arch[] = "i586"; #elif defined(__i486__) - const char arch[] = "i486"; + static constexpr char arch[] = "i486"; #else - const char arch[] = "i386"; + static constexpr char arch[] = "i386"; #endif #elif defined(ARCH_CPU_X86_64) - const char arch[] = "x86_64"; + static constexpr char arch[] = "x86_64"; #elif defined(ARCH_CPU_ARMEL) // linux-4.9.17/arch/arm/kernel/setup.c setup_processor() bases the string // on the ARM processor name and a character identifying little- or // big-endian. The processor name comes from a definition in // arch/arm/mm/proc-*.S. #if defined(__ARM_ARCH_4T__) - const char arch[] = "armv4t" + static constexpr char arch[] = "armv4t" #elif defined(__ARM_ARCH_5TEJ__) - const char arch[] = "armv5tej" + static constexpr char arch[] = "armv5tej" #elif defined(__ARM_ARCH_5TE__) - const char arch[] = "armv5te" + static constexpr char arch[] = "armv5te" #elif defined(__ARM_ARCH_5T__) - const char arch[] = "armv5t" + static constexpr char arch[] = "armv5t" #elif defined(__ARM_ARCH_7M__) - const char arch[] = "armv7m" + static constexpr char arch[] = "armv7m" #else // Most ARM architectures fall into here, including all profile variants of // armv6, armv7, armv8, with one exception, armv7m, handled above. @@ -89,7 +89,7 @@ std::string UserAgent() { // or 8. #define xstr(s) str(s) #define str(s) #s - const char arch[] = "armv" xstr(__ARM_ARCH) + static constexpr char arch[] = "armv" xstr(__ARM_ARCH) #undef str #undef xstr #endif @@ -102,14 +102,14 @@ std::string UserAgent() { // ARM64 uses aarch64 or aarch64_be as directed by ELF_PLATFORM. See // linux-4.9.17/arch/arm64/kernel/setup.c setup_arch(). #if defined(ARCH_CPU_LITTLE_ENDIAN) - const char arch[] = "aarch64"; + static constexpr char arch[] = "aarch64"; #elif defined(ARCH_CPU_BIG_ENDIAN) - const char arch[] = "aarch64_be"; + static constexpr char arch[] = "aarch64_be"; #endif #elif defined(ARCH_CPU_MIPSEL) - const char arch[] = "mips"; + static constexpr char arch[] = "mips"; #elif defined(ARCH_CPU_MIPS64EL) - const char arch[] = "mips64"; + static constexpr char arch[] = "mips64"; #else #error Port #endif diff --git a/util/net/http_transport_test.cc b/util/net/http_transport_test.cc index 70c3eee4..3b7e7ebd 100644 --- a/util/net/http_transport_test.cc +++ b/util/net/http_transport_test.cc @@ -136,7 +136,7 @@ class HTTPTransportTestFixture : public MultiprocessExec { RequestValidator request_validator_; }; -const char kMultipartFormData[] = "multipart/form-data"; +constexpr char kMultipartFormData[] = "multipart/form-data"; void GetHeaderField(const std::string& request, const std::string& header, @@ -179,7 +179,7 @@ void GetMultipartBoundary(const std::string& request, } } -const char kBoundaryEq[] = "boundary="; +constexpr char kBoundaryEq[] = "boundary="; void ValidFormData(HTTPTransportTestFixture* fixture, const std::string& request) { @@ -242,7 +242,7 @@ TEST(HTTPTransport, ValidFormData_Gzip) { test.Run(); } -const char kTextPlain[] = "text/plain"; +constexpr char kTextPlain[] = "text/plain"; void ErrorResponse(HTTPTransportTestFixture* fixture, const std::string& request) { @@ -260,7 +260,7 @@ TEST(HTTPTransport, ErrorResponse) { test.Run(); } -const char kTextBody[] = "hello world"; +constexpr char kTextBody[] = "hello world"; void UnchunkedPlainText(HTTPTransportTestFixture* fixture, const std::string& request) { diff --git a/util/net/http_transport_win.cc b/util/net/http_transport_win.cc index 56fdaad1..ecbe8ea2 100644 --- a/util/net/http_transport_win.cc +++ b/util/net/http_transport_win.cc @@ -242,7 +242,8 @@ bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) { DWORD content_length_dword; if (chunked) { - const wchar_t kTransferEncodingHeader[] = L"Transfer-Encoding: chunked\r\n"; + static constexpr wchar_t kTransferEncodingHeader[] = + L"Transfer-Encoding: chunked\r\n"; if (!WinHttpAddRequestHeaders( request.get(), kTransferEncodingHeader, diff --git a/util/numeric/checked_address_range_test.cc b/util/numeric/checked_address_range_test.cc index fa7ae87d..e6bd9ecd 100644 --- a/util/numeric/checked_address_range_test.cc +++ b/util/numeric/checked_address_range_test.cc @@ -46,7 +46,7 @@ bool ExpectationForValidity64(Validity validity) { } TEST(CheckedAddressRange, IsValid) { - const struct TestData { + static constexpr struct { uint64_t base; uint64_t size; Validity validity; @@ -120,7 +120,7 @@ TEST(CheckedAddressRange, IsValid) { }; for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& testcase = kTestData[index]; + const auto& testcase = kTestData[index]; SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%" PRIx64 ", size 0x%" PRIx64, index, @@ -136,7 +136,7 @@ TEST(CheckedAddressRange, IsValid) { } TEST(CheckedAddressRange, ContainsValue) { - const struct TestData { + static constexpr struct { uint64_t value; bool expectation; } kTestData[] = { @@ -171,7 +171,7 @@ TEST(CheckedAddressRange, ContainsValue) { ASSERT_TRUE(parent_range_32.IsValid()); for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& testcase = kTestData[index]; + const auto& testcase = kTestData[index]; SCOPED_TRACE(base::StringPrintf( "index %" PRIuS ", value 0x%" PRIx64, index, testcase.value)); @@ -189,7 +189,7 @@ TEST(CheckedAddressRange, ContainsValue) { } TEST(CheckedAddressRange, ContainsRange) { - const struct TestData { + static constexpr struct { uint64_t base; uint64_t size; bool expectation; @@ -228,7 +228,7 @@ TEST(CheckedAddressRange, ContainsRange) { ASSERT_TRUE(parent_range_32.IsValid()); for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& testcase = kTestData[index]; + const auto& testcase = kTestData[index]; SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%" PRIx64 ", size 0x%" PRIx64, index, diff --git a/util/numeric/checked_range_test.cc b/util/numeric/checked_range_test.cc index 404b9898..04f6bb1f 100644 --- a/util/numeric/checked_range_test.cc +++ b/util/numeric/checked_range_test.cc @@ -29,7 +29,7 @@ namespace test { namespace { TEST(CheckedRange, IsValid) { - const struct UnsignedTestData { + static constexpr struct { uint32_t base; uint32_t size; bool valid; @@ -79,7 +79,7 @@ TEST(CheckedRange, IsValid) { }; for (size_t index = 0; index < arraysize(kUnsignedTestData); ++index) { - const UnsignedTestData& testcase = kUnsignedTestData[index]; + const auto& testcase = kUnsignedTestData[index]; SCOPED_TRACE(base::StringPrintf("unsigned index %" PRIuS ", base 0x%x, size 0x%x", index, @@ -91,7 +91,7 @@ TEST(CheckedRange, IsValid) { } const int32_t kMinInt32 = std::numeric_limits::min(); - const struct SignedTestData { + static constexpr struct { int32_t base; uint32_t size; bool valid; @@ -141,7 +141,7 @@ TEST(CheckedRange, IsValid) { }; for (size_t index = 0; index < arraysize(kSignedTestData); ++index) { - const SignedTestData& testcase = kSignedTestData[index]; + const auto& testcase = kSignedTestData[index]; SCOPED_TRACE(base::StringPrintf("signed index %" PRIuS ", base 0x%x, size 0x%x", index, @@ -154,7 +154,7 @@ TEST(CheckedRange, IsValid) { } TEST(CheckedRange, ContainsValue) { - const struct TestData { + static constexpr struct { uint32_t value; bool contains; } kTestData[] = { @@ -187,7 +187,7 @@ TEST(CheckedRange, ContainsValue) { ASSERT_TRUE(parent_range.IsValid()); for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& testcase = kTestData[index]; + const auto& testcase = kTestData[index]; SCOPED_TRACE(base::StringPrintf( "index %" PRIuS ", value 0x%x", index, testcase.value)); @@ -196,7 +196,7 @@ TEST(CheckedRange, ContainsValue) { } TEST(CheckedRange, ContainsRange) { - const struct TestData { + static constexpr struct { uint32_t base; uint32_t size; bool contains; @@ -235,7 +235,7 @@ TEST(CheckedRange, ContainsRange) { ASSERT_TRUE(parent_range.IsValid()); for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& testcase = kTestData[index]; + const auto& testcase = kTestData[index]; SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x", index, testcase.base, @@ -248,7 +248,7 @@ TEST(CheckedRange, ContainsRange) { } TEST(CheckedRange, OverlapsRange) { - const struct TestData { + static constexpr struct { uint32_t base; uint32_t size; bool overlaps; @@ -288,7 +288,7 @@ TEST(CheckedRange, OverlapsRange) { ASSERT_TRUE(first_range.IsValid()); for (size_t index = 0; index < arraysize(kTestData); ++index) { - const TestData& testcase = kTestData[index]; + const auto& testcase = kTestData[index]; SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x", index, testcase.base, diff --git a/util/numeric/int128_test.cc b/util/numeric/int128_test.cc index e0b45999..83b4f6e8 100644 --- a/util/numeric/int128_test.cc +++ b/util/numeric/int128_test.cc @@ -23,10 +23,10 @@ namespace { TEST(Int128, UInt128) { #if defined(ARCH_CPU_LITTLE_ENDIAN) - const uint8_t kBytes[] = + static constexpr uint8_t kBytes[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; #else - const uint8_t kBytes[] = + static constexpr uint8_t kBytes[] = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; #endif diff --git a/util/posix/close_multiple.cc b/util/posix/close_multiple.cc index 908febf3..6e31eb9c 100644 --- a/util/posix/close_multiple.cc +++ b/util/posix/close_multiple.cc @@ -75,9 +75,9 @@ void CloseNowOrOnExec(int fd, bool ebadf_ok) { // no attempt needs to be made to close file descriptors that are not open. bool CloseMultipleNowOrOnExecUsingFDDir(int fd, int preserve_fd) { #if defined(OS_MACOSX) - const char kFDDir[] = "/dev/fd"; + static constexpr char kFDDir[] = "/dev/fd"; #elif defined(OS_LINUX) || defined(OS_ANDROID) - const char kFDDir[] = "/proc/self/fd"; + static constexpr char kFDDir[] = "/proc/self/fd"; #endif DIR* dir = opendir(kFDDir); @@ -99,10 +99,10 @@ bool CloseMultipleNowOrOnExecUsingFDDir(int fd, int preserve_fd) { // readdir_r() is deprecated as of glibc 2.24. See // https://sourceware.org/bugzilla/show_bug.cgi?id=19056 and // https://git.kernel.org/cgit/docs/man-pages/man-pages.git/commit?id=0c52f6d623636a61eacd0f7b7a3bb942793a2a05. - const char kReaddirName[] = "readdir"; + static constexpr char kReaddirName[] = "readdir"; while ((errno = 0, result = readdir(dir)) != nullptr) #else - const char kReaddirName[] = "readdir_r"; + static constexpr char kReaddirName[] = "readdir_r"; dirent entry; while ((errno = readdir_r(dir, &entry, &result)) == 0 && result != nullptr) #endif diff --git a/util/posix/symbolic_constants_posix.cc b/util/posix/symbolic_constants_posix.cc index 4ea2300b..51cc583b 100644 --- a/util/posix/symbolic_constants_posix.cc +++ b/util/posix/symbolic_constants_posix.cc @@ -26,7 +26,7 @@ namespace { -const char* kSignalNames[] = { +constexpr const char* kSignalNames[] = { nullptr, #if defined(OS_MACOSX) @@ -108,7 +108,7 @@ static_assert(arraysize(kSignalNames) == 32, "kSignalNames length"); static_assert(arraysize(kSignalNames) == NSIG, "kSignalNames length"); #endif -const char kSigPrefix[] = "SIG"; +constexpr char kSigPrefix[] = "SIG"; } // namespace diff --git a/util/posix/symbolic_constants_posix_test.cc b/util/posix/symbolic_constants_posix_test.cc index 9cb29b58..4084c2c3 100644 --- a/util/posix/symbolic_constants_posix_test.cc +++ b/util/posix/symbolic_constants_posix_test.cc @@ -29,7 +29,7 @@ namespace crashpad { namespace test { namespace { -const struct { +constexpr struct { int signal; const char* full_name; const char* short_name; @@ -157,7 +157,7 @@ void TestStringToSignal(const base::StringPiece& string, } TEST(SymbolicConstantsPOSIX, StringToSignal) { - const StringToSymbolicConstantOptions kOptions[] = { + static constexpr StringToSymbolicConstantOptions kOptions[] = { 0, kAllowFullName, kAllowShortName, @@ -198,7 +198,7 @@ TEST(SymbolicConstantsPOSIX, StringToSignal) { } } - const char* const kNegativeTestData[] = { + static constexpr const char* kNegativeTestData[] = { "SIGHUP ", " SIGINT", "QUIT ", @@ -216,7 +216,7 @@ TEST(SymbolicConstantsPOSIX, StringToSignal) { TestStringToSignal(kNegativeTestData[index], options, false, 0); } - const struct { + static constexpr struct { const char* string; size_t length; } kNULTestData[] = { diff --git a/util/stdlib/string_number_conversion_test.cc b/util/stdlib/string_number_conversion_test.cc index f6634d0f..dd17c00d 100644 --- a/util/stdlib/string_number_conversion_test.cc +++ b/util/stdlib/string_number_conversion_test.cc @@ -26,7 +26,7 @@ namespace test { namespace { TEST(StringNumberConversion, StringToInt) { - const struct { + static constexpr struct { const char* string; bool valid; int value; @@ -113,7 +113,7 @@ TEST(StringNumberConversion, StringToInt) { // Ensure that embedded NUL characters are treated as bad input. The string // is split to avoid MSVC warning: // "decimal digit terminates octal escape sequence". - const char input[] = "6\000" "6"; + static constexpr char input[] = "6\000" "6"; base::StringPiece input_string(input, arraysize(input) - 1); int output; EXPECT_FALSE(StringToNumber(input_string, &output)); @@ -124,7 +124,7 @@ TEST(StringNumberConversion, StringToInt) { } TEST(StringNumberConversion, StringToUnsignedInt) { - const struct { + static constexpr struct { const char* string; bool valid; unsigned int value; @@ -211,7 +211,7 @@ TEST(StringNumberConversion, StringToUnsignedInt) { // Ensure that embedded NUL characters are treated as bad input. The string // is split to avoid MSVC warning: // "decimal digit terminates octal escape sequence". - const char input[] = "6\000" "6"; + static constexpr char input[] = "6\000" "6"; base::StringPiece input_string(input, arraysize(input) - 1); unsigned int output; EXPECT_FALSE(StringToNumber(input_string, &output)); @@ -222,7 +222,7 @@ TEST(StringNumberConversion, StringToUnsignedInt) { } TEST(StringNumberConversion, StringToInt64) { - const struct { + static constexpr struct { const char* string; bool valid; int64_t value; @@ -271,7 +271,7 @@ TEST(StringNumberConversion, StringToInt64) { } TEST(StringNumberConversion, StringToUnsignedInt64) { - const struct { + static constexpr struct { const char* string; bool valid; uint64_t value; diff --git a/util/stdlib/strlcpy_test.cc b/util/stdlib/strlcpy_test.cc index 57315c3b..5185840f 100644 --- a/util/stdlib/strlcpy_test.cc +++ b/util/stdlib/strlcpy_test.cc @@ -41,7 +41,8 @@ TEST(strlcpy, c16lcpy) { // Test with M, é, Ā, ő, and Ḙ. This is a mix of characters that have zero and // nonzero low and high bytes. - const base::char16 test_characters[] = {0x4d, 0xe9, 0x100, 0x151, 0x1e18}; + static constexpr base::char16 test_characters[] = + {0x4d, 0xe9, 0x100, 0x151, 0x1e18}; for (size_t index = 0; index < arraysize(test_characters); ++index) { base::char16 test_character = test_characters[index]; diff --git a/util/stdlib/strnlen_test.cc b/util/stdlib/strnlen_test.cc index e030fdc8..1913e208 100644 --- a/util/stdlib/strnlen_test.cc +++ b/util/stdlib/strnlen_test.cc @@ -23,7 +23,7 @@ namespace test { namespace { TEST(strnlen, strnlen) { - const char kTestBuffer[] = "abc\0d"; + static constexpr char kTestBuffer[] = "abc\0d"; ASSERT_EQ(strlen(kTestBuffer), 3u); EXPECT_EQ(crashpad::strnlen(kTestBuffer, 0), 0u); EXPECT_EQ(crashpad::strnlen(kTestBuffer, 1), 1u); @@ -33,7 +33,7 @@ TEST(strnlen, strnlen) { EXPECT_EQ(crashpad::strnlen(kTestBuffer, 5), 3u); EXPECT_EQ(crashpad::strnlen(kTestBuffer, 6), 3u); - const char kEmptyBuffer[] = "\0"; + static constexpr char kEmptyBuffer[] = "\0"; ASSERT_EQ(strlen(kEmptyBuffer), 0u); EXPECT_EQ(crashpad::strnlen(kEmptyBuffer, 0), 0u); EXPECT_EQ(crashpad::strnlen(kEmptyBuffer, 1), 0u); diff --git a/util/thread/thread_log_messages_test.cc b/util/thread/thread_log_messages_test.cc index 65c0b854..f906ff15 100644 --- a/util/thread/thread_log_messages_test.cc +++ b/util/thread/thread_log_messages_test.cc @@ -50,7 +50,7 @@ std::string MessageString(const std::string& log_message) { return std::string(); } - const char kFindString[] = "] "; + static constexpr char kFindString[] = "] "; size_t pos = log_message.find(kFindString); if (pos == std::string::npos) { EXPECT_NE(pos, std::string::npos); @@ -78,7 +78,7 @@ TEST(ThreadLogMessages, Basic) { ASSERT_TRUE(LOG_IS_ON(INFO)); { - const char* const kMessages[] = { + static constexpr const char* kMessages[] = { "An info message", "A warning message", "An error message", @@ -101,7 +101,7 @@ TEST(ThreadLogMessages, Basic) { } { - const char kMessage[] = "Sample error message"; + static constexpr char kMessage[] = "Sample error message"; ThreadLogMessages thread_log_messages; diff --git a/util/win/command_line_test.cc b/util/win/command_line_test.cc index 95849b63..1eb15b88 100644 --- a/util/win/command_line_test.cc +++ b/util/win/command_line_test.cc @@ -60,10 +60,10 @@ TEST(CommandLine, AppendCommandLineArgument) { { SCOPED_TRACE("simple"); - const wchar_t* const kArguments[] = { - L"child.exe", - L"argument 1", - L"argument 2", + static constexpr wchar_t* const kArguments[] = { + L"child.exe", + L"argument 1", + L"argument 2", }; AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); } @@ -71,11 +71,11 @@ TEST(CommandLine, AppendCommandLineArgument) { { SCOPED_TRACE("path with spaces"); - const wchar_t* const kArguments[] = { - L"child.exe", - L"argument1", - L"argument 2", - L"\\some\\path with\\spaces", + static constexpr wchar_t* const kArguments[] = { + L"child.exe", + L"argument1", + L"argument 2", + L"\\some\\path with\\spaces", }; AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); } @@ -83,11 +83,11 @@ TEST(CommandLine, AppendCommandLineArgument) { { SCOPED_TRACE("argument with embedded quotation marks"); - const wchar_t* const kArguments[] = { - L"child.exe", - L"argument1", - L"she said, \"you had me at hello\"", - L"\\some\\path with\\spaces", + static constexpr wchar_t* const kArguments[] = { + L"child.exe", + L"argument1", + L"she said, \"you had me at hello\"", + L"\\some\\path with\\spaces", }; AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); } @@ -95,12 +95,12 @@ TEST(CommandLine, AppendCommandLineArgument) { { SCOPED_TRACE("argument with unbalanced quotation marks"); - const wchar_t* const kArguments[] = { - L"child.exe", - L"argument1", - L"argument\"2", - L"argument3", - L"argument4", + static constexpr wchar_t* const kArguments[] = { + L"child.exe", + L"argument1", + L"argument\"2", + L"argument3", + L"argument4", }; AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); } @@ -108,10 +108,10 @@ TEST(CommandLine, AppendCommandLineArgument) { { SCOPED_TRACE("argument ending with backslash"); - const wchar_t* const kArguments[] = { - L"child.exe", - L"\\some\\directory with\\spaces\\", - L"argument2", + static constexpr wchar_t* const kArguments[] = { + L"child.exe", + L"\\some\\directory with\\spaces\\", + L"argument2", }; AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); } @@ -119,10 +119,10 @@ TEST(CommandLine, AppendCommandLineArgument) { { SCOPED_TRACE("empty argument"); - const wchar_t* const kArguments[] = { - L"child.exe", - L"", - L"argument2", + static constexpr wchar_t* const kArguments[] = { + L"child.exe", + L"", + L"argument2", }; AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); } @@ -130,34 +130,34 @@ TEST(CommandLine, AppendCommandLineArgument) { { SCOPED_TRACE("funny nonprintable characters"); - const wchar_t* const kArguments[] = { - L"child.exe", - L"argument 1", - L"argument\t2", - L"argument\n3", - L"argument\v4", - L"argument\"5", - L" ", - L"\t", - L"\n", - L"\v", - L"\"", - L" x", - L"\tx", - L"\nx", - L"\vx", - L"\"x", - L"x ", - L"x\t", - L"x\n", - L"x\v", - L"x\"", - L" ", - L"\t\t", - L"\n\n", - L"\v\v", - L"\"\"", - L" \t\n\v\"", + static constexpr wchar_t* const kArguments[] = { + L"child.exe", + L"argument 1", + L"argument\t2", + L"argument\n3", + L"argument\v4", + L"argument\"5", + L" ", + L"\t", + L"\n", + L"\v", + L"\"", + L" x", + L"\tx", + L"\nx", + L"\vx", + L"\"x", + L"x ", + L"x\t", + L"x\n", + L"x\v", + L"x\"", + L" ", + L"\t\t", + L"\n\n", + L"\v\v", + L"\"\"", + L" \t\n\v\"", }; AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); } diff --git a/util/win/process_info_test.cc b/util/win/process_info_test.cc index 50f932c8..d715350f 100644 --- a/util/win/process_info_test.cc +++ b/util/win/process_info_test.cc @@ -42,7 +42,7 @@ namespace crashpad { namespace test { namespace { -const wchar_t kNtdllName[] = L"\\ntdll.dll"; +constexpr wchar_t kNtdllName[] = L"\\ntdll.dll"; bool IsProcessWow64(HANDLE process_handle) { static const auto is_wow64_process = @@ -101,7 +101,7 @@ TEST(ProcessInfo, Self) { std::vector modules; EXPECT_TRUE(process_info.Modules(&modules)); ASSERT_GE(modules.size(), 2u); - const wchar_t kSelfName[] = L"\\crashpad_util_test.exe"; + static constexpr wchar_t kSelfName[] = L"\\crashpad_util_test.exe"; ASSERT_GE(modules[0].name.size(), wcslen(kSelfName)); EXPECT_EQ(modules[0].name.substr(modules[0].name.size() - wcslen(kSelfName)), kSelfName); @@ -178,7 +178,7 @@ void TestOtherProcess(const base::string16& directory_modification) { kNtdllName); // lz32.dll is an uncommonly-used-but-always-available module that the test // binary manually loads. - const wchar_t kLz32dllName[] = L"\\lz32.dll"; + static constexpr wchar_t kLz32dllName[] = L"\\lz32.dll"; ASSERT_GE(modules.back().name.size(), wcslen(kLz32dllName)); EXPECT_EQ(modules.back().name.substr(modules.back().name.size() - wcslen(kLz32dllName)), diff --git a/util/win/registration_protocol_win.cc b/util/win/registration_protocol_win.cc index 87c45748..dc31e7d4 100644 --- a/util/win/registration_protocol_win.cc +++ b/util/win/registration_protocol_win.cc @@ -136,7 +136,7 @@ const void* GetSecurityDescriptorForNamedPipeInstance(size_t* size) { // would in turn cause deadlock. #pragma pack(push, 1) - static const struct SecurityDescriptorBlob { + static constexpr struct SecurityDescriptorBlob { // See https://msdn.microsoft.com/en-us/library/cc230366.aspx. SECURITY_DESCRIPTOR_RELATIVE sd_rel; struct { diff --git a/util/win/registration_protocol_win_test.cc b/util/win/registration_protocol_win_test.cc index 10a5bb63..6601b4e7 100644 --- a/util/win/registration_protocol_win_test.cc +++ b/util/win/registration_protocol_win_test.cc @@ -33,7 +33,7 @@ TEST(SecurityDescriptor, MatchesAdvapi32) { // Mandatory Label, no ACE flags, no ObjectType, integrity level // untrusted. - const wchar_t kSddl[] = L"S:(ML;;;;;S-1-16-0)"; + static constexpr wchar_t kSddl[] = L"S:(ML;;;;;S-1-16-0)"; PSECURITY_DESCRIPTOR sec_desc; ULONG sec_desc_len; ASSERT_TRUE(ConvertStringSecurityDescriptorToSecurityDescriptor( diff --git a/util/win/safe_terminate_process_test.cc b/util/win/safe_terminate_process_test.cc index 2fbc8483..d176002e 100644 --- a/util/win/safe_terminate_process_test.cc +++ b/util/win/safe_terminate_process_test.cc @@ -134,7 +134,7 @@ TEST(SafeTerminateProcess, PatchBadly) { // https://crashpad.chromium.org/bug/179. In reality, this only affects // 32-bit x86, as there’s no calling convention confusion on x86_64. It // doesn’t hurt to run this test in the 64-bit environment, though. - const uint8_t patch[] = { + static constexpr uint8_t patch[] = { #if defined(ARCH_CPU_X86) 0x31, 0xc0, // xor eax, eax #elif defined(ARCH_CPU_X86_64)