aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Mauro <dmauro@google.com>2024-01-02 13:26:37 -0800
committerCopybara-Service <copybara-worker@google.com>2024-01-02 13:27:33 -0800
commit4038192a57cb75f7ee671f81a3378ff4c74c4f8e (patch)
tree84e6f749939160da3038c9811fd36c3daa030834
parent9028b8126dde250ddc193a7088ceebbbb20bac92 (diff)
downloadabseil-cpp-4038192a57cb75f7ee671f81a3378ff4c74c4f8e.tar.gz
Remove workaround for older versions MSVC that did not support
constexpr Flag construction. These versions of MSVC are no longer supported. PiperOrigin-RevId: 595195773 Change-Id: Iaf2f01a2255fb24f3aadc26f09600543fffa9da5
-rw-r--r--absl/flags/BUILD.bazel4
-rw-r--r--absl/flags/CMakeLists.txt3
-rw-r--r--absl/flags/declare.h5
-rw-r--r--absl/flags/flag.cc38
-rw-r--r--absl/flags/flag.h11
-rw-r--r--absl/flags/flag_test.cc11
-rw-r--r--absl/flags/internal/flag.h5
-rw-r--r--absl/flags/internal/flag_msvc.inc116
8 files changed, 1 insertions, 192 deletions
diff --git a/absl/flags/BUILD.bazel b/absl/flags/BUILD.bazel
index 170d1ba8..ce0c00a2 100644
--- a/absl/flags/BUILD.bazel
+++ b/absl/flags/BUILD.bazel
@@ -229,10 +229,6 @@ cc_library(
cc_library(
name = "flag",
- srcs = [
- "flag.cc",
- "internal/flag_msvc.inc",
- ],
hdrs = [
"declare.h",
"flag.h",
diff --git a/absl/flags/CMakeLists.txt b/absl/flags/CMakeLists.txt
index ddf2d4e7..44953124 100644
--- a/absl/flags/CMakeLists.txt
+++ b/absl/flags/CMakeLists.txt
@@ -201,12 +201,9 @@ absl_cc_library(
absl_cc_library(
NAME
flags
- SRCS
- "flag.cc"
HDRS
"declare.h"
"flag.h"
- "internal/flag_msvc.inc"
COPTS
${ABSL_DEFAULT_COPTS}
LINKOPTS
diff --git a/absl/flags/declare.h b/absl/flags/declare.h
index d1437bb9..8d2a856e 100644
--- a/absl/flags/declare.h
+++ b/absl/flags/declare.h
@@ -40,13 +40,8 @@ class Flag;
// Flag
//
// Forward declaration of the `absl::Flag` type for use in defining the macro.
-#if defined(_MSC_VER) && !defined(__clang__)
-template <typename T>
-class Flag;
-#else
template <typename T>
using Flag = flags_internal::Flag<T>;
-#endif
ABSL_NAMESPACE_END
} // namespace absl
diff --git a/absl/flags/flag.cc b/absl/flags/flag.cc
deleted file mode 100644
index 531df128..00000000
--- a/absl/flags/flag.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-//
-// Copyright 2019 The Abseil Authors.
-//
-// 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
-//
-// https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "absl/flags/flag.h"
-
-#include "absl/base/config.h"
-
-namespace absl {
-ABSL_NAMESPACE_BEGIN
-
-// This global mutex protects on-demand construction of flag objects in MSVC
-// builds.
-#if defined(_MSC_VER) && !defined(__clang__)
-
-namespace flags_internal {
-
-ABSL_CONST_INIT static absl::Mutex construction_guard(absl::kConstInit);
-
-absl::Mutex* GetGlobalConstructionGuard() { return &construction_guard; }
-
-} // namespace flags_internal
-
-#endif
-
-ABSL_NAMESPACE_END
-} // namespace absl
diff --git a/absl/flags/flag.h b/absl/flags/flag.h
index b7f94be7..06ea6932 100644
--- a/absl/flags/flag.h
+++ b/absl/flags/flag.h
@@ -71,12 +71,9 @@ ABSL_NAMESPACE_BEGIN
// For type support of Abseil Flags, see the marshalling.h header file, which
// discusses supported standard types, optional flags, and additional Abseil
// type support.
-#if !defined(_MSC_VER) || defined(__clang__)
+
template <typename T>
using Flag = flags_internal::Flag<T>;
-#else
-#include "absl/flags/internal/flag_msvc.inc"
-#endif
// GetFlag()
//
@@ -196,18 +193,12 @@ ABSL_NAMESPACE_END
// -----------------------------------------------------------------------------
// ABSL_FLAG_IMPL macro definition conditional on ABSL_FLAGS_STRIP_NAMES
-#if !defined(_MSC_VER) || defined(__clang__)
#define ABSL_FLAG_IMPL_FLAG_PTR(flag) flag
#define ABSL_FLAG_IMPL_HELP_ARG(name) \
absl::flags_internal::HelpArg<AbslFlagHelpGenFor##name>( \
FLAGS_help_storage_##name)
#define ABSL_FLAG_IMPL_DEFAULT_ARG(Type, name) \
absl::flags_internal::DefaultArg<Type, AbslFlagDefaultGenFor##name>(0)
-#else
-#define ABSL_FLAG_IMPL_FLAG_PTR(flag) flag.GetImpl()
-#define ABSL_FLAG_IMPL_HELP_ARG(name) &AbslFlagHelpGenFor##name::NonConst
-#define ABSL_FLAG_IMPL_DEFAULT_ARG(Type, name) &AbslFlagDefaultGenFor##name::Gen
-#endif
#if ABSL_FLAGS_STRIP_NAMES
#define ABSL_FLAG_IMPL_FLAGNAME(txt) ""
diff --git a/absl/flags/flag_test.cc b/absl/flags/flag_test.cc
index f9cda02e..8d14ba8d 100644
--- a/absl/flags/flag_test.cc
+++ b/absl/flags/flag_test.cc
@@ -144,7 +144,6 @@ using String = std::string;
using int128 = absl::int128;
using uint128 = absl::uint128;
-#if !defined(_MSC_VER) || defined(__clang__)
#define DEFINE_CONSTRUCTED_FLAG(T, dflt, dflt_kind) \
constexpr flags::FlagDefaultArg f1default##T{ \
flags::FlagDefaultSrc{dflt}, flags::FlagDefaultKind::dflt_kind}; \
@@ -157,16 +156,6 @@ using uint128 = absl::uint128;
flags::FlagDefaultKind::kGenFunc \
} \
}
-#else
-#define DEFINE_CONSTRUCTED_FLAG(T, dflt, dflt_kind) \
- constexpr flags::FlagDefaultArg f1default##T{ \
- flags::FlagDefaultSrc{dflt}, flags::FlagDefaultKind::dflt_kind}; \
- constexpr absl::Flag<T> f1##T{"f1", "file", &TestLiteralHelpMsg, \
- &TestMakeDflt<T>}; \
- ABSL_CONST_INIT absl::Flag<T> f2##T { \
- "f2", "file", &TestHelpMsg, &TestMakeDflt<T> \
- }
-#endif
DEFINE_CONSTRUCTED_FLAG(bool, true, kOneWord);
DEFINE_CONSTRUCTED_FLAG(int16_t, 1, kOneWord);
diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h
index b41f9a69..2e6e6b87 100644
--- a/absl/flags/internal/flag.h
+++ b/absl/flags/internal/flag.h
@@ -54,13 +54,8 @@ template <typename T>
class Flag;
} // namespace flags_internal
-#if defined(_MSC_VER) && !defined(__clang__)
-template <typename T>
-class Flag;
-#else
template <typename T>
using Flag = flags_internal::Flag<T>;
-#endif
template <typename T>
ABSL_MUST_USE_RESULT T GetFlag(const absl::Flag<T>& flag);
diff --git a/absl/flags/internal/flag_msvc.inc b/absl/flags/internal/flag_msvc.inc
deleted file mode 100644
index 614d09fd..00000000
--- a/absl/flags/internal/flag_msvc.inc
+++ /dev/null
@@ -1,116 +0,0 @@
-//
-// Copyright 2021 The Abseil Authors.
-//
-// 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
-//
-// https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// Do not include this file directly.
-// Include absl/flags/flag.h instead.
-
-// MSVC debug builds do not implement initialization with constexpr constructors
-// correctly. To work around this we add a level of indirection, so that the
-// class `absl::Flag` contains an `internal::Flag*` (instead of being an alias
-// to that class) and dynamically allocates an instance when necessary. We also
-// forward all calls to internal::Flag methods via trampoline methods. In this
-// setup the `absl::Flag` class does not have constructor and virtual methods,
-// all the data members are public and thus MSVC is able to initialize it at
-// link time. To deal with multiple threads accessing the flag for the first
-// time concurrently we use an atomic boolean indicating if flag object is
-// initialized. We also employ the double-checked locking pattern where the
-// second level of protection is a global Mutex, so if two threads attempt to
-// construct the flag concurrently only one wins.
-//
-// This solution is based on a recommendation here:
-// https://developercommunity.visualstudio.com/content/problem/336946/class-with-constexpr-constructor-not-using-static.html?childToView=648454#comment-648454
-
-namespace flags_internal {
-absl::Mutex* GetGlobalConstructionGuard();
-} // namespace flags_internal
-
-// Public methods of `absl::Flag<T>` are NOT part of the Abseil Flags API.
-// See https://abseil.io/docs/cpp/guides/flags
-template <typename T>
-class Flag {
- public:
- // No constructor and destructor to ensure this is an aggregate type.
- // Visual Studio 2015 still requires the constructor for class to be
- // constexpr initializable.
-#if _MSC_VER <= 1900
- constexpr Flag(const char* name, const char* filename,
- const flags_internal::HelpGenFunc help_gen,
- const flags_internal::FlagDfltGenFunc default_value_gen)
- : name_(name),
- filename_(filename),
- help_gen_(help_gen),
- default_value_gen_(default_value_gen),
- inited_(false),
- impl_(nullptr) {}
-#endif
-
- flags_internal::Flag<T>& GetImpl() const {
- if (!inited_.load(std::memory_order_acquire)) {
- absl::MutexLock l(flags_internal::GetGlobalConstructionGuard());
-
- if (inited_.load(std::memory_order_acquire)) {
- return *impl_;
- }
-
- impl_ = new flags_internal::Flag<T>(
- name_, filename_,
- {flags_internal::FlagHelpMsg(help_gen_),
- flags_internal::FlagHelpKind::kGenFunc},
- {flags_internal::FlagDefaultSrc(default_value_gen_),
- flags_internal::FlagDefaultKind::kGenFunc});
- inited_.store(true, std::memory_order_release);
- }
-
- return *impl_;
- }
-
- // Public methods of `absl::Flag<T>` are NOT part of the Abseil Flags API.
- // See https://abseil.io/docs/cpp/guides/flags
- bool IsRetired() const { return GetImpl().IsRetired(); }
- absl::string_view Name() const { return GetImpl().Name(); }
- std::string Help() const { return GetImpl().Help(); }
- bool IsModified() const { return GetImpl().IsModified(); }
- bool IsSpecifiedOnCommandLine() const {
- return GetImpl().IsSpecifiedOnCommandLine();
- }
- std::string Filename() const { return GetImpl().Filename(); }
- std::string DefaultValue() const { return GetImpl().DefaultValue(); }
- std::string CurrentValue() const { return GetImpl().CurrentValue(); }
- template <typename U>
- inline bool IsOfType() const {
- return GetImpl().template IsOfType<U>();
- }
- T Get() const {
- return flags_internal::FlagImplPeer::InvokeGet<T>(GetImpl());
- }
- void Set(const T& v) {
- flags_internal::FlagImplPeer::InvokeSet(GetImpl(), v);
- }
- void InvokeCallback() { GetImpl().InvokeCallback(); }
-
- const CommandLineFlag& Reflect() const {
- return flags_internal::FlagImplPeer::InvokeReflect(GetImpl());
- }
-
- // The data members are logically private, but they need to be public for
- // this to be an aggregate type.
- const char* name_;
- const char* filename_;
- const flags_internal::HelpGenFunc help_gen_;
- const flags_internal::FlagDfltGenFunc default_value_gen_;
-
- mutable std::atomic<bool> inited_;
- mutable flags_internal::Flag<T>* impl_;
-};