diff --git a/starboard/build/config/base_configuration.gni b/starboard/build/config/base_configuration.gni index 713606314c28..73a222113d61 100644 --- a/starboard/build/config/base_configuration.gni +++ b/starboard/build/config/base_configuration.gni @@ -162,6 +162,9 @@ declare_args() { # Enables an NPLB audit of C++17 support. sb_enable_cpp17_audit = true + # Enables an NPLB audit of C++20 support. + sb_enable_cpp20_audit = true + # Flag to use a future version of Skia, currently not available. use_skia_next = false diff --git a/starboard/build/config/modular/BUILD.gn b/starboard/build/config/modular/BUILD.gn index 1bbbd5f6dc4a..cef39191a51d 100644 --- a/starboard/build/config/modular/BUILD.gn +++ b/starboard/build/config/modular/BUILD.gn @@ -33,10 +33,13 @@ config("modular") { cflags += [ "-fPIC" ] } - cflags_cc = [ - "-nostdinc++", - "-std=c++17", - ] + cflags_cc = [ "-nostdinc++" ] + + if (sb_enable_cpp20_audit) { + cflags_cc += [ "-std=c++17" ] + } else { + cflags_cc += [ "-std=c++17" ] + } defines = [ # Ensure that the Starboardized __external_threading file is included. diff --git a/starboard/nplb/BUILD.gn b/starboard/nplb/BUILD.gn index 1d2005be8eab..952005c40d6c 100644 --- a/starboard/nplb/BUILD.gn +++ b/starboard/nplb/BUILD.gn @@ -267,6 +267,10 @@ target(gtest_target_type, "nplb") { deps += [ "//starboard/nplb/compiler_compliance:cpp17_supported" ] } + if (sb_enable_cpp20_audit) { + deps += [ "//starboard/nplb/compiler_compliance:cpp20_supported" ] + } + data_deps = [ "//cobalt/network:copy_ssl_certificates", "//starboard/nplb/testdata/file_tests:nplb_file_tests_data", diff --git a/starboard/nplb/compiler_compliance/BUILD.gn b/starboard/nplb/compiler_compliance/BUILD.gn index e3638c1436b9..74a33898fb51 100644 --- a/starboard/nplb/compiler_compliance/BUILD.gn +++ b/starboard/nplb/compiler_compliance/BUILD.gn @@ -40,3 +40,23 @@ if (sb_enable_cpp17_audit) { cflags_cc = [ "-std=c++17" ] } } + +if (sb_enable_cpp20_audit) { + static_library("cpp20_supported") { + sources = [ "cpp20_support.cc" ] + deps = [ + ":cpp20_supported_config_shim", + "//starboard:starboard_group", + ] + } + + # We do this to ensure the -std=c++20 flag is added after any other -std flag + # so it overrides any other one. + group("cpp20_supported_config_shim") { + public_configs = [ ":cpp20_supported_config" ] + } + + config("cpp20_supported_config") { + cflags_cc = [ "-std=c++20" ] + } +} diff --git a/starboard/nplb/compiler_compliance/cpp20_support.cc b/starboard/nplb/compiler_compliance/cpp20_support.cc new file mode 100644 index 000000000000..3ca7c32dea98 --- /dev/null +++ b/starboard/nplb/compiler_compliance/cpp20_support.cc @@ -0,0 +1,31 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the aLicense is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +namespace starboard { +namespace nplb { +namespace compiler_compliance { +namespace { + +// Test string ends with support + +void test_string_ends_with() { + bool result = std::string("foobar").ends_with("bar"); +} + +} // namespace +} // namespace compiler_compliance +} // namespace nplb +} // namespace starboard