perfetto: switch to C++17 with temporary C++11 opt-out

* make all targets build with C++17
* make it an error to compile with C++11 without defining an opt-out
  flag. The error makes it clear that any objections need to be
  discussed very soon
* Keep the debug CI bot compiling with C++11 to prevent accidental
  use of C++14/17 features in the transition period

Bug: b/257064316
Change-Id: I32c227944f9d65a110d4f613b1ea17a823567822
diff --git a/bazel/rules.bzl b/bazel/rules.bzl
index c2a649b..b699471 100644
--- a/bazel/rules.bzl
+++ b/bazel/rules.bzl
@@ -22,7 +22,7 @@
 def default_cc_args():
     return {
         "deps": PERFETTO_CONFIG.deps.build_config,
-        "copts": [
+        "copts": PERFETTO_CONFIG.default_copts + [
             "-Wno-pragma-system-header-outside-header",
         ],
         "includes": ["include"],
diff --git a/bazel/standalone/perfetto_cfg.bzl b/bazel/standalone/perfetto_cfg.bzl
index d1b77e4..ce2764e 100644
--- a/bazel/standalone/perfetto_cfg.bzl
+++ b/bazel/standalone/perfetto_cfg.bzl
@@ -125,4 +125,9 @@
 
         go_proto_library = None,
     ),
+
+    # The default copts which we use to compile C++ code.
+    default_copts = [
+        "-std=c++17",
+    ]
 )
diff --git a/buildtools/BUILD.gn b/buildtools/BUILD.gn
index 99627a2..023fa7d 100644
--- a/buildtools/BUILD.gn
+++ b/buildtools/BUILD.gn
@@ -705,11 +705,15 @@
     ]
 
     configs -= [
-      "//gn/standalone:c++11",
       "//gn/standalone:extra_warnings",
       "//gn/standalone:no_exceptions",
       "//gn/standalone:no_rtti",
     ]
+    if (perfetto_cpp11_until_q1_2023) {
+      configs -= [ "//gn/standalone:c++11" ]
+    } else {
+      configs -= [ "//gn/standalone:c++17" ]
+    }
     configs += [
       ":libc++config",
       "//gn/standalone/sanitizers:sanitizer_options_link_helper",
@@ -804,11 +808,15 @@
       configs += [ ":libc++winver" ]
     }
     configs -= [
-      "//gn/standalone:c++11",
       "//gn/standalone:extra_warnings",
       "//gn/standalone:no_exceptions",
       "//gn/standalone:no_rtti",
     ]
+    if (perfetto_cpp11_until_q1_2023) {
+      configs -= [ "//gn/standalone:c++11" ]
+    } else {
+      configs -= [ "//gn/standalone:c++17" ]
+    }
     if ((is_android || is_mac) && !custom_libcxx_is_static) {
       # Use libc++_perfetto to avoid conflicting with system libc++
       output_name = "libc++_perfettto"
@@ -1190,17 +1198,18 @@
   }
   configs -= [
     "//gn/standalone:extra_warnings",
-    "//gn/standalone:c++11",
     "//gn/standalone:visibility_hidden",
   ]
   cflags = [ "-DFAKE_LOG_DEVICE=1" ]
   if (!is_win) {
     cflags += [ "-Wno-deprecated-declarations" ]
   }
-  public_configs = [
-    ":libunwindstack_config",
-    "//gn/standalone:c++17",
-  ]
+  public_configs = [ ":libunwindstack_config" ]
+
+  if (perfetto_cpp11_until_q1_2023) {
+    configs -= [ "//gn/standalone:c++11" ]
+    public_configs += [ "//gn/standalone:c++17" ]
+  }
 }
 
 config("bionic_kernel_uapi_headers") {
@@ -1306,18 +1315,19 @@
   include_dirs = [ "llvm-project/llvm/include" ]
 }
 
-# NB: this is built under c++14 and linked into code that is c++11 by default.
-# We rely on the ABIs being compatible for this to be sane. At the time of
-# writing, the only c++14 specific code is behind an #ifndef NDEBUG, so we
-# could keep building as c++11 in non-debug builds, but we always use c++14 for
-# consistency.
 source_set("llvm_demangle") {
   visibility = _buildtools_visibility
-  configs -= [
-    "//gn/standalone:extra_warnings",
-    "//gn/standalone:c++11",
-  ]
-  configs += [ "//gn/standalone:c++14" ]
+  configs -= [ "//gn/standalone:extra_warnings" ]
+
+  # NB: this is built under c++14 and linked into code that is c++11 by default.
+  # We rely on the ABIs being compatible for this to be sane. At the time of
+  # writing, the only c++14 specific code is behind an #ifndef NDEBUG, so we
+  # could keep building as c++11 in non-debug builds, but we always use c++14 for
+  # consistency.
+  if (perfetto_cpp11_until_q1_2023) {
+    configs -= [ "//gn/standalone:c++11" ]
+    configs += [ "//gn/standalone:c++14" ]
+  }
   public_configs = [ ":llvm_demangle_config" ]
   sources = [
     "llvm-project/llvm/include/llvm/Demangle/Demangle.h",
diff --git a/docs/README.md b/docs/README.md
index 9152c0a..1ce43f8 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -82,7 +82,7 @@
 to the Linux/Android tracing daemon through a UNIX socket, allowing to combine
 app-specific instrumentation points with system-wide tracing events.
 
-The SDK is based on portable C++11 code [tested](/docs/contributing/testing.md)
+The SDK is based on portable C++17 code [tested](/docs/contributing/testing.md)
 with the major C++ sanitizers (ASan, TSan, MSan, LSan). It doesn't rely on
 run-time code modifications or compiler plugins.
 
@@ -109,7 +109,7 @@
 dedicated project for importing, parsing and querying new and legacy trace
 formats, [Trace Processor](/docs/analysis/trace-processor.md).
 
-Trace Processor is a portable C++11 library that provides column-oriented
+Trace Processor is a portable C++17 library that provides column-oriented
 table storage, designed ad-hoc for efficiently holding hours of trace data
 into memory and exposes a SQL query interface based on the popular SQLite query
 engine.
diff --git a/docs/instrumentation/tracing-sdk.md b/docs/instrumentation/tracing-sdk.md
index 6bba47b..43261fb 100644
--- a/docs/instrumentation/tracing-sdk.md
+++ b/docs/instrumentation/tracing-sdk.md
@@ -1,6 +1,6 @@
 # Tracing SDK
 
-The Perfetto Tracing SDK is a C++11 library that allows userspace applications
+The Perfetto Tracing SDK is a C++17 library that allows userspace applications
 to emit trace events and add more app-specific context to a Perfetto trace.
 
 When using the Tracing SDK there are two main aspects to consider:
@@ -35,7 +35,7 @@
 
 The SDK consists of two files, `sdk/perfetto.h` and `sdk/perfetto.cc`. These are
 an amalgamation of the Client API designed to easy to integrate to existing
-build systems. The sources are self-contained and require only a C++11 compliant
+build systems. The sources are self-contained and require only a C++17 compliant
 standard library.
 
 For example, to add the SDK to a CMake project, edit your CMakeLists.txt:
diff --git a/examples/sdk/README.md b/examples/sdk/README.md
index 31e7145..e25c308 100644
--- a/examples/sdk/README.md
+++ b/examples/sdk/README.md
@@ -8,7 +8,7 @@
 Dependencies:
 
 - [CMake](https://cmake.org/)
-- C++11
+- C++17
 
 ## Building
 
diff --git a/gn/standalone/BUILD.gn b/gn/standalone/BUILD.gn
index 0d17328..192bee8 100644
--- a/gn/standalone/BUILD.gn
+++ b/gn/standalone/BUILD.gn
@@ -111,6 +111,10 @@
 }
 
 config("c++11") {
+  if (!perfetto_cpp11_until_q1_2023) {
+    visibility = []
+  }
+
   # C++11 is the default on Windows.
   if (!is_win) {
     cflags_cc = [ "-std=c++11" ]
@@ -118,11 +122,16 @@
     # Enable standards-conforming compiler behavior.
     cflags_cc = [ "/permissive-" ]
   }
+  defines = [ "PERFETTO_ALLOW_SUB_CPP17" ]
 }
 
 # Used in buildtools dependencies for standalone builds.
 config("c++14") {
-  visibility = [ "//buildtools:llvm_demangle" ]
+  if (perfetto_cpp11_until_q1_2023) {
+    visibility = [ "//buildtools:llvm_demangle" ]
+  } else {
+    visibility = []
+  }
   if (is_win) {
     cflags_cc = [ "/std:c++14" ]
   } else {
@@ -132,7 +141,9 @@
 
 # Used in buildtools dependencies for standalone builds.
 config("c++17") {
-  visibility = [ "//buildtools:libunwindstack" ]
+  if (perfetto_cpp11_until_q1_2023) {
+    visibility = [ "//buildtools:libunwindstack" ]
+  }
   if (is_win) {
     cflags_cc = [ "/std:c++17" ]
   } else {
@@ -196,6 +207,7 @@
       "/Gy",  # Enable function-level linking.
       "/FS",  # Preserve previous PDB behavior.
       "/utf-8",  # Assume UTF-8 by default to avoid code page dependencies.
+      "/Zc:__cplusplus",  # Allow use of __cplusplus macro.
     ]
     defines += [
       "_CRT_NONSTDC_NO_WARNINGS",
diff --git a/gn/standalone/BUILDCONFIG.gn b/gn/standalone/BUILDCONFIG.gn
index 6f32686..772161b 100644
--- a/gn/standalone/BUILDCONFIG.gn
+++ b/gn/standalone/BUILDCONFIG.gn
@@ -17,6 +17,7 @@
   is_clang = true
   is_system_compiler = false
   is_lto = false
+  perfetto_cpp11_until_q1_2023 = false
 
   # This is defined here because it's needed below for determining the value of
   # |is_cross_compiling|.
@@ -65,7 +66,6 @@
 default_configs = [
   "//gn/standalone:debug_symbols",
   "//gn/standalone:default",
-  "//gn/standalone:c++11",
   "//gn/standalone:extra_warnings",
   "//gn/standalone:no_exceptions",
   "//gn/standalone:no_rtti",
@@ -74,6 +74,12 @@
   "//gn/standalone/sanitizers:sanitizers_cflags",
 ]
 
+if (perfetto_cpp11_until_q1_2023) {
+  default_configs += [ "//gn/standalone:c++11" ]
+} else {
+  default_configs += [ "//gn/standalone:c++17" ]
+}
+
 if (is_win) {
   default_configs += [ "//gn/standalone:win32_lean_and_mean" ]
 }
diff --git a/include/perfetto/base/compiler.h b/include/perfetto/base/compiler.h
index e95b676..c67e315 100644
--- a/include/perfetto/base/compiler.h
+++ b/include/perfetto/base/compiler.h
@@ -23,6 +23,22 @@
 #include "perfetto/base/build_config.h"
 #include "perfetto/public/compiler.h"
 
+#if __cplusplus >= 201703
+#define PERFETTO_IS_AT_LEAST_CPP17() 1
+#else
+#define PERFETTO_IS_AT_LEAST_CPP17() 0
+#endif
+
+#if !PERFETTO_IS_AT_LEAST_CPP17() && !defined(PERFETTO_ALLOW_SUB_CPP17)
+#error Perfetto is exploring a switch to C++17 in v34 (Feb 2023). During this \
+transitionary period, we are throwing an error when compiling Perfetto \
+with a standard less than C++17. Please reach out to \
+perfetto-dev@googlegroups.com if you have objections or thoughts on \
+this move. To continue compiling this release of Perfetto with \
+C++11/14, specify the define PERFETTO_ALLOW_SUB_CPP17. \
+*Note*: this define *will* stop working in v34 (Feb 2023).
+#endif
+
 // __has_attribute is supported only by clang and recent versions of GCC.
 // Add a layer to wrap the __has_attribute macro.
 #if defined(__has_attribute)
diff --git a/include/perfetto/tracing/internal/track_event_macros.h b/include/perfetto/tracing/internal/track_event_macros.h
index d4e1017..3e91f96 100644
--- a/include/perfetto/tracing/internal/track_event_macros.h
+++ b/include/perfetto/tracing/internal/track_event_macros.h
@@ -144,6 +144,14 @@
     }                                                                          \
   } while (false)
 
+// C++17 doesn't like a move constructor being defined for the EventFinalizer
+// class but C++11 doesn't compile without it being defined so support both.
+#if PERFETTO_IS_AT_LEAST_CPP17()
+#define PERFETTO_INTERNAL_EVENT_FINALIZER_KEYWORD delete
+#else
+#define PERFETTO_INTERNAL_EVENT_FINALIZER_KEYWORD default
+#endif
+
 #define PERFETTO_INTERNAL_SCOPED_TRACK_EVENT(category, name, ...)             \
   struct PERFETTO_UID(ScopedEvent) {                                          \
     struct EventFinalizer {                                                   \
@@ -160,7 +168,8 @@
       EventFinalizer(const EventFinalizer&) = delete;                         \
       inline EventFinalizer& operator=(const EventFinalizer&) = delete;       \
                                                                               \
-      EventFinalizer(EventFinalizer&&) = default;                             \
+      EventFinalizer(EventFinalizer&&) =                                      \
+          PERFETTO_INTERNAL_EVENT_FINALIZER_KEYWORD;                          \
       EventFinalizer& operator=(EventFinalizer&&) = delete;                   \
     } finalizer;                                                              \
   } PERFETTO_UID(scoped_event) {                                              \
diff --git a/infra/ci/config.py b/infra/ci/config.py
index ba8bf93..7a10502 100755
--- a/infra/ci/config.py
+++ b/infra/ci/config.py
@@ -66,10 +66,10 @@
 # Only variables starting with PERFETTO_ are propagated into the sandbox.
 JOB_CONFIGS = {
     'linux-clang-x86_64-debug': {
-        'PERFETTO_TEST_GN_ARGS':
-            'is_debug=true is_hermetic_clang=false non_hermetic_clang_stdlib="libc++"',
-        'PERFETTO_TEST_SCRIPT':
-            'test/ci/linux_tests.sh',
+        'PERFETTO_TEST_GN_ARGS': 'is_debug=true is_hermetic_clang=false '
+                                 'non_hermetic_clang_stdlib="libc++" '
+                                 'perfetto_cpp11_until_q1_2023=true',
+        'PERFETTO_TEST_SCRIPT': 'test/ci/linux_tests.sh',
     },
     'linux-clang-x86_64-tsan': {
         'PERFETTO_TEST_GN_ARGS': 'is_debug=false is_tsan=true',
diff --git a/meson.build b/meson.build
index 5295c52..5ef6fce 100644
--- a/meson.build
+++ b/meson.build
@@ -19,7 +19,7 @@
 project(
     'perfetto',
     ['cpp'],
-    default_options: ['cpp_std=c++11']
+    default_options: ['cpp_std=c++17']
 )
 
 fs = import('fs')
diff --git a/src/base/metatrace.cc b/src/base/metatrace.cc
index c676d80..1464ed3 100644
--- a/src/base/metatrace.cc
+++ b/src/base/metatrace.cc
@@ -29,7 +29,6 @@
 std::atomic<uint64_t> g_enabled_timestamp{0};
 
 // static members
-constexpr size_t RingBuffer::kCapacity;
 std::array<Record, RingBuffer::kCapacity> RingBuffer::records_;
 std::atomic<bool> RingBuffer::read_task_queued_;
 std::atomic<uint64_t> RingBuffer::wr_index_;
@@ -37,9 +36,12 @@
 std::atomic<bool> RingBuffer::has_overruns_;
 Record RingBuffer::bankruptcy_record_;
 
+#if !PERFETTO_IS_AT_LEAST_CPP17()
+constexpr size_t RingBuffer::kCapacity;
 constexpr uint16_t Record::kTypeMask;
 constexpr uint16_t Record::kTypeCounter;
 constexpr uint16_t Record::kTypeEvent;
+#endif
 
 namespace {
 
diff --git a/src/protozero/packed_repeated_fields.cc b/src/protozero/packed_repeated_fields.cc
index b0e23c5..16d4539 100644
--- a/src/protozero/packed_repeated_fields.cc
+++ b/src/protozero/packed_repeated_fields.cc
@@ -20,8 +20,10 @@
 
 namespace protozero {
 
+#if !PERFETTO_IS_AT_LEAST_CPP17()
 // static
 constexpr size_t PackedBufferBase::kOnStackStorageSize;
+#endif
 
 void PackedBufferBase::GrowSlowpath() {
   size_t write_off = static_cast<size_t>(write_ptr_ - storage_begin_);
diff --git a/src/trace_processor/containers/string_pool.cc b/src/trace_processor/containers/string_pool.cc
index 0189054..0ca5d0b 100644
--- a/src/trace_processor/containers/string_pool.cc
+++ b/src/trace_processor/containers/string_pool.cc
@@ -24,6 +24,7 @@
 namespace perfetto {
 namespace trace_processor {
 
+#if !PERFETTO_IS_AT_LEAST_CPP17()
 // static
 constexpr size_t StringPool::kNumBlockIndexBits;
 // static
@@ -38,6 +39,7 @@
 constexpr size_t StringPool::kBlockSizeBytes;
 // static
 constexpr size_t StringPool::kMinLargeStringSizeBytes;
+#endif
 
 StringPool::StringPool() {
   static_assert(
diff --git a/src/trace_processor/importers/common/args_translation_table.cc b/src/trace_processor/importers/common/args_translation_table.cc
index 1e4e22f..b35f427 100644
--- a/src/trace_processor/importers/common/args_translation_table.cc
+++ b/src/trace_processor/importers/common/args_translation_table.cc
@@ -49,6 +49,7 @@
 
 }  // namespace
 
+#if !PERFETTO_IS_AT_LEAST_CPP17()
 constexpr char ArgsTranslationTable::kChromeHistogramHashKey[];
 constexpr char ArgsTranslationTable::kChromeHistogramNameKey[];
 
@@ -65,6 +66,7 @@
 constexpr char ArgsTranslationTable::kMojoMethodRelPcKey[];
 constexpr char ArgsTranslationTable::kMojoMethodNameKey[];
 constexpr char ArgsTranslationTable::kMojoIntefaceTagKey[];
+#endif
 
 ArgsTranslationTable::ArgsTranslationTable(TraceStorage* storage)
     : storage_(storage),
diff --git a/src/trace_processor/importers/proto/track_event_tracker.cc b/src/trace_processor/importers/proto/track_event_tracker.cc
index 6497df1..c37eccd 100644
--- a/src/trace_processor/importers/proto/track_event_tracker.cc
+++ b/src/trace_processor/importers/proto/track_event_tracker.cc
@@ -24,8 +24,10 @@
 namespace perfetto {
 namespace trace_processor {
 
+#if !PERFETTO_IS_AT_LEAST_CPP17()
 // static
 constexpr uint64_t TrackEventTracker::kDefaultDescriptorTrackUuid;
+#endif
 
 TrackEventTracker::TrackEventTracker(TraceProcessorContext* context)
     : source_key_(context->storage->InternString("source")),
diff --git a/src/trace_processor/sqlite/sqlite_utils_unittest.cc b/src/trace_processor/sqlite/sqlite_utils_unittest.cc
index 5d85383..1d1de13 100644
--- a/src/trace_processor/sqlite/sqlite_utils_unittest.cc
+++ b/src/trace_processor/sqlite/sqlite_utils_unittest.cc
@@ -16,7 +16,6 @@
 
 #include "src/trace_processor/sqlite/sqlite_utils.h"
 
-#include "gtest/gtest.h"
 #include "test/gtest_and_gmock.h"
 
 namespace perfetto {
diff --git a/src/trace_processor/trace_sorter_queue_unittest.cc b/src/trace_processor/trace_sorter_queue_unittest.cc
index b233fe7..d013c91 100644
--- a/src/trace_processor/trace_sorter_queue_unittest.cc
+++ b/src/trace_processor/trace_sorter_queue_unittest.cc
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 #include "src/trace_processor/trace_sorter_queue.h"
-#include "gtest/gtest.h"
+
 #include "src/trace_processor/types/variadic.h"
 #include "test/gtest_and_gmock.h"
 
diff --git a/src/trace_processor/types/variadic.cc b/src/trace_processor/types/variadic.cc
index 837bfeb..9a26bd5 100644
--- a/src/trace_processor/types/variadic.cc
+++ b/src/trace_processor/types/variadic.cc
@@ -19,7 +19,9 @@
 namespace perfetto {
 namespace trace_processor {
 
+#if !PERFETTO_IS_AT_LEAST_CPP17()
 constexpr const char* Variadic::kTypeNames[];
+#endif
 
 }  // namespace trace_processor
 }  // namespace perfetto
diff --git a/src/tracing/core/metatrace_writer.cc b/src/tracing/core/metatrace_writer.cc
index f6acfa0..c270632 100644
--- a/src/tracing/core/metatrace_writer.cc
+++ b/src/tracing/core/metatrace_writer.cc
@@ -26,8 +26,10 @@
 
 namespace perfetto {
 
+#if !PERFETTO_IS_AT_LEAST_CPP17()
 // static
 constexpr char MetatraceWriter::kDataSourceName[];
+#endif
 
 MetatraceWriter::MetatraceWriter() : weak_ptr_factory_(this) {}
 
diff --git a/src/tracing/core/shared_memory_abi.cc b/src/tracing/core/shared_memory_abi.cc
index 9461848..0c4694b 100644
--- a/src/tracing/core/shared_memory_abi.cc
+++ b/src/tracing/core/shared_memory_abi.cc
@@ -69,6 +69,7 @@
 
 }  // namespace
 
+#if !PERFETTO_IS_AT_LEAST_CPP17()
 // static
 constexpr uint32_t SharedMemoryABI::kNumChunksForLayout[];
 constexpr const char* SharedMemoryABI::kChunkStateStr[];
@@ -76,6 +77,7 @@
 constexpr const size_t SharedMemoryABI::kMinPageSize;
 constexpr const size_t SharedMemoryABI::kMaxPageSize;
 constexpr const size_t SharedMemoryABI::kPacketSizeDropPacket;
+#endif
 
 SharedMemoryABI::SharedMemoryABI() = default;
 
diff --git a/src/tracing/core/shared_memory_arbiter_impl.cc b/src/tracing/core/shared_memory_arbiter_impl.cc
index 7928676..f1b830a 100644
--- a/src/tracing/core/shared_memory_arbiter_impl.cc
+++ b/src/tracing/core/shared_memory_arbiter_impl.cc
@@ -52,8 +52,10 @@
 SharedMemoryABI::PageLayout SharedMemoryArbiterImpl::default_page_layout =
     SharedMemoryABI::PageLayout::kPageDiv1;
 
+#if !PERFETTO_IS_AT_LEAST_CPP17()
 // static
 constexpr BufferID SharedMemoryArbiterImpl::kInvalidBufferId;
+#endif
 
 // static
 std::unique_ptr<SharedMemoryArbiter> SharedMemoryArbiter::CreateInstance(
diff --git a/src/tracing/core/trace_buffer.cc b/src/tracing/core/trace_buffer.cc
index 41633aa..c0527ad 100644
--- a/src/tracing/core/trace_buffer.cc
+++ b/src/tracing/core/trace_buffer.cc
@@ -42,8 +42,10 @@
     SharedMemoryABI::ChunkHeader::kChunkNeedsPatching;
 }  // namespace.
 
+#if !PERFETTO_IS_AT_LEAST_CPP17()
 constexpr size_t TraceBuffer::ChunkRecord::kMaxSize;
-constexpr size_t TraceBuffer::InlineChunkHeaderSize = sizeof(ChunkRecord);
+#endif
+const size_t TraceBuffer::InlineChunkHeaderSize = sizeof(ChunkRecord);
 
 // static
 std::unique_ptr<TraceBuffer> TraceBuffer::Create(size_t size_in_bytes,
diff --git a/src/tracing/core/tracing_service_impl.cc b/src/tracing/core/tracing_service_impl.cc
index f910a90..da4e34c 100644
--- a/src/tracing/core/tracing_service_impl.cc
+++ b/src/tracing/core/tracing_service_impl.cc
@@ -312,10 +312,12 @@
 
 }  // namespace
 
+#if !PERFETTO_IS_AT_LEAST_CPP17()
 // These constants instead are defined in the header because are used by tests.
 constexpr size_t TracingServiceImpl::kMaxShmSize;
 constexpr uint32_t TracingServiceImpl::kDataSourceStopTimeoutMs;
 constexpr uint8_t TracingServiceImpl::kSyncMarker[];
+#endif
 
 std::string GetBugreportPath() {
 #if PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) && \
diff --git a/src/tracing/core/virtual_destructors.cc b/src/tracing/core/virtual_destructors.cc
index 3bcedce..ad9522e 100644
--- a/src/tracing/core/virtual_destructors.cc
+++ b/src/tracing/core/virtual_destructors.cc
@@ -36,7 +36,9 @@
 SharedMemory::Factory::~Factory() = default;
 SharedMemoryArbiter::~SharedMemoryArbiter() = default;
 
+#if !PERFETTO_IS_AT_LEAST_CPP17()
 constexpr size_t TracingService::kDefaultShmSize;
 constexpr size_t TracingService::kDefaultShmPageSize;
+#endif
 
 }  // namespace perfetto
diff --git a/src/tracing/test/api_integrationtest_main.cc b/src/tracing/test/api_integrationtest_main.cc
index 49fb0d4..5073244 100644
--- a/src/tracing/test/api_integrationtest_main.cc
+++ b/src/tracing/test/api_integrationtest_main.cc
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include <gtest/gtest.h>
+#include "test/gtest_and_gmock.h"
 
 #include "perfetto/tracing.h"
 
diff --git a/tools/test_gen_amalgamated.py b/tools/test_gen_amalgamated.py
index aa99bc4..9eb17ad 100755
--- a/tools/test_gen_amalgamated.py
+++ b/tools/test_gen_amalgamated.py
@@ -52,7 +52,7 @@
 
 def check_amalgamated_build():
   args = [
-      '-std=c++11', '-Werror', '-Wall', '-Wextra',
+      '-std=c++17', '-Werror', '-Wall', '-Wextra',
       '-DPERFETTO_AMALGAMATED_SDK_TEST', '-I' + OUT_DIR,
       OUT_DIR + '/perfetto.cc', 'test/client_api_example.cc', '-o',
       OUT_DIR + '/test'