From 284378a71b32dfb3af4e3661f585e671d1b603a3 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 5 Dec 2018 12:37:41 -0800 Subject: Export of internal Abseil changes. -- 22fa219d17b2281c0695642830c4300711bd65ea by CJ Johnson : Rearrange the private method declarations in InlinedVector PiperOrigin-RevId: 224202447 -- eed3c9f488f23b521bee41d3683eb6cc22517ded by Derek Mauro : Fix leak_check target (it was always a no-op when LSAN isn't available). Fixes https://github.com/abseil/abseil-cpp/issues/232 PiperOrigin-RevId: 224201634 -- fc08039e175204b14a9561f618fcfc0234586801 by Greg Falcon : Add parens around more invocations of min() and max() missed in my prior CL. PiperOrigin-RevId: 224162430 -- 0ec5476a8293c7796cd84928a1a558b14f14f222 by Abseil Team : Update absl/numeric/CMakeLists.txt to use new functions i.e. absl_cc_(library|test) PiperOrigin-RevId: 224139165 -- 2b46aa6fabb20c589661f8bbc84030ecf39ce394 by Abseil Team : Update absl/meta/CMakeLists.txt to use new functions i.e. absl_cc_(library|test) PiperOrigin-RevId: 224117258 -- 6c951c798f8c6903bd8793a8a4b5f69244be8aa9 by Abseil Team : Fix 2 Unused C++ BUILD Dependencies PiperOrigin-RevId: 224070093 -- 0ee7bd191708708f91fc5209c197fd93f6e4a8b3 by Greg Falcon : Inside Abseil headers, wrap most invocations of methods and functions named `min` and `max` in parentheses, for better interoperability with Windows toolchains. CCTZ fixes will appear in a follow-up CL. PiperOrigin-RevId: 224051960 -- f562f56577b84a8bc07e5873775c01d068531bca by Jon Cohen : Generate Abseil compile options. The single source of truth is now absl/copts/copts.py The way this works goes something like this: copts.py acts as the configuration file. We use python because unlike JSON it allows comments. It has two maps in it: one from names to external flags, and one from names to internal flags. generate_copts.py imports the maps and loops through them to write GENERATED_copts.bzl and GENERATED_AbseilCopts.cmake AbseilConfigureCopts.cmake and configure_copts.bzl import their respective copts args and set the platform-appropriate copts into ABSL_DEFAULT_COPTS, ABSL_TEST_COPTS, ABSL_EXCEPTIONS_FLAG, and ABSL_EXCEPTIONS_LINKOPTS For Bazel, each BUILD file load()s configure_copts.bzl For CMake, AbseilHelpers.cmake include()s AbseilConfigureCopts.cmake to get the final copts and both inserts them as needed into legacy target rules and also makes them available to the rest of our CMakeLists.txt file. We may instead want to include() AbseilConfigureCopts.cmake directly into each CMakeLists.txt file for consistency, but I'm not sure what the deal is with cmake and include guards, or if they are even needed. That's also not as idiomatic -- CMake tends to use directory scope where globals set at a higher level CMakeLists.txt file are used in the subdirectory CMakeLists.txt files. PiperOrigin-RevId: 224039419 -- f7402f6bb65037e668a7355f0a003f5c05a3b6a7 by Abseil Team : Import of CCTZ from GitHub. PiperOrigin-RevId: 224036622 GitOrigin-RevId: 22fa219d17b2281c0695642830c4300711bd65ea Change-Id: I6b505360539ff2aef8aa30c51a5f7d55db1c75cf --- absl/copts/configure_copts.bzl | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 absl/copts/configure_copts.bzl (limited to 'absl/copts/configure_copts.bzl') diff --git a/absl/copts/configure_copts.bzl b/absl/copts/configure_copts.bzl new file mode 100644 index 00000000..57cd3f62 --- /dev/null +++ b/absl/copts/configure_copts.bzl @@ -0,0 +1,42 @@ +"""absl specific copts. + +This file simply selects the correct options from the generated files. To +change Abseil copts, edit absl/copts/copts.py +""" + +load( + "//absl:copts/GENERATED_copts.bzl", + "GCC_EXCEPTIONS_FLAGS", + "GCC_FLAGS", + "GCC_TEST_FLAGS", + "LLVM_EXCEPTIONS_FLAGS", + "LLVM_FLAGS", + "LLVM_TEST_FLAGS", + "MSVC_EXCEPTIONS_FLAGS", + "MSVC_FLAGS", + "MSVC_TEST_FLAGS", +) + +ABSL_DEFAULT_COPTS = select({ + "//absl:windows": MSVC_FLAGS, + "//absl:llvm_compiler": LLVM_FLAGS, + "//conditions:default": GCC_FLAGS, +}) + +# in absence of modules (--compiler=gcc or -c opt), cc_tests leak their copts +# to their (included header) dependencies and fail to build outside absl +ABSL_TEST_COPTS = ABSL_DEFAULT_COPTS + select({ + "//absl:windows": MSVC_TEST_FLAGS, + "//absl:llvm_compiler": LLVM_TEST_FLAGS, + "//conditions:default": GCC_TEST_FLAGS, +}) + +ABSL_EXCEPTIONS_FLAG = select({ + "//absl:windows": MSVC_EXCEPTIONS_FLAGS, + "//absl:llvm_compiler": LLVM_EXCEPTIONS_FLAGS, + "//conditions:default": GCC_EXCEPTIONS_FLAGS, +}) + +ABSL_EXCEPTIONS_FLAG_LINKOPTS = select({ + "//conditions:default": [], +}) -- cgit v1.2.3 From 253eb7416421661873afbaa33828a850db978541 Mon Sep 17 00:00:00 2001 From: Loo Rong Jie Date: Sat, 23 Mar 2019 03:23:01 +0800 Subject: [CMake] Set correct flags for clang-cl (#278) clang-cl produce binaries with MSVC ABI and wants to be as flag-compatible with pure MSVC as possible, so this leads to all sorts of weird cases. clang-cl alias /Wall as clang's -Weverything which is way too verbose, so it needs /W3 like pure MSVC. clang-cl only understand GCC style warning flags (-W[no]blah) and just silent drop MSVC style warning flags (/wd[num]). clang-cl needs MSVC define flags since it is consuming the same header files as pure MSVC. CMake set CMAKE_CXX_COMPILER_ID as Clang when clang-cl is detected, so need extra if (MSVC) to differentiate it. We are not doing clang-cl specialization in Bazel as currently there is no reliable way to detect clang-cl in Bazel.. This PR should be NFC for LLVM/GCC users on Unix platforms. Other changes: Add ABSL_ prefix to variable names to avoid name collision in CMake. --- .gitignore | 2 +- absl/copts/AbseilConfigureCopts.cmake | 39 +++--- absl/copts/GENERATED_AbseilCopts.cmake | 104 +++++++++++++-- absl/copts/GENERATED_copts.bzl | 104 +++++++++++++-- absl/copts/configure_copts.bzl | 36 +++--- absl/copts/copts.py | 230 ++++++++++++++++++--------------- 6 files changed, 346 insertions(+), 169 deletions(-) (limited to 'absl/copts/configure_copts.bzl') diff --git a/.gitignore b/.gitignore index 31f33741..d54fa5a9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,5 @@ CMakeLists.txt.user # Ignore VS Code files .vscode/* # Ignore generated python artifacts -copts/copts.pyc +*.pyc copts/__pycache__/ diff --git a/absl/copts/AbseilConfigureCopts.cmake b/absl/copts/AbseilConfigureCopts.cmake index f68895d9..5084958c 100644 --- a/absl/copts/AbseilConfigureCopts.cmake +++ b/absl/copts/AbseilConfigureCopts.cmake @@ -5,26 +5,33 @@ set(ABSL_LSAN_LINKOPTS "") set(ABSL_HAVE_LSAN OFF) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(ABSL_DEFAULT_COPTS "${GCC_FLAGS}") - set(ABSL_TEST_COPTS "${GCC_FLAGS};${GCC_TEST_FLAGS}") - set(ABSL_EXCEPTIONS_FLAG "${GCC_EXCEPTIONS_FLAGS}") + set(ABSL_DEFAULT_COPTS "${ABSL_GCC_FLAGS}") + set(ABSL_TEST_COPTS "${ABSL_GCC_FLAGS};${ABSL_GCC_TEST_FLAGS}") + set(ABSL_EXCEPTIONS_FLAG "${ABSL_GCC_EXCEPTIONS_FLAGS}") elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # MATCHES so we get both Clang and AppleClang - set(ABSL_DEFAULT_COPTS "${LLVM_FLAGS}") - set(ABSL_TEST_COPTS "${LLVM_FLAGS};${LLVM_TEST_FLAGS}") - set(ABSL_EXCEPTIONS_FLAG "${LLVM_EXCEPTIONS_FLAGS}") - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - # AppleClang doesn't have lsan - # https://developer.apple.com/documentation/code_diagnostics - if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5) - set(ABSL_LSAN_LINKOPTS "-fsanitize=leak") - set(ABSL_HAVE_LSAN ON) + if (MSVC) + # clang-cl is half MSVC, half LLVM + set(ABSL_DEFAULT_COPTS "${ABSL_CLANG_CL_FLAGS}") + set(ABSL_TEST_COPTS "${ABSL_CLANG_CL_FLAGS};${ABSL_CLANG_CL_TEST_FLAGS}") + set(ABSL_EXCEPTIONS_FLAG "${ABSL_CLANG_CL_EXCEPTIONS_FLAGS}") + else() + set(ABSL_DEFAULT_COPTS "${ABSL_LLVM_FLAGS}") + set(ABSL_TEST_COPTS "${ABSL_LLVM_FLAGS};${ABSL_LLVM_TEST_FLAGS}") + set(ABSL_EXCEPTIONS_FLAG "${ABSL_LLVM_EXCEPTIONS_FLAGS}") + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # AppleClang doesn't have lsan + # https://developer.apple.com/documentation/code_diagnostics + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5) + set(ABSL_LSAN_LINKOPTS "-fsanitize=leak") + set(ABSL_HAVE_LSAN ON) + endif() endif() endif() elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - set(ABSL_DEFAULT_COPTS "${MSVC_FLAGS}") - set(ABSL_TEST_COPTS "${MSVC_FLAGS};${MSVC_TEST_FLAGS}") - set(ABSL_EXCEPTIONS_FLAG "${MSVC_EXCEPTIONS_FLAGS}") + set(ABSL_DEFAULT_COPTS "${ABSL_MSVC_FLAGS}") + set(ABSL_TEST_COPTS "${ABSL_MSVC_FLAGS};${ABSL_MSVC_TEST_FLAGS}") + set(ABSL_EXCEPTIONS_FLAG "${ABSL_MSVC_EXCEPTIONS_FLAGS}") else() message(WARNING "Unknown compiler: ${CMAKE_CXX_COMPILER}. Building with no default flags") set(ABSL_DEFAULT_COPTS "") @@ -42,4 +49,4 @@ elseif(NOT "${CMAKE_CXX_STANDARD}") set(ABSL_CXX_STANDARD 11) else() set(ABSL_CXX_STANDARD "${CMAKE_CXX_STANDARD}") -endif() \ No newline at end of file +endif() diff --git a/absl/copts/GENERATED_AbseilCopts.cmake b/absl/copts/GENERATED_AbseilCopts.cmake index d02ea193..9031bfa5 100644 --- a/absl/copts/GENERATED_AbseilCopts.cmake +++ b/absl/copts/GENERATED_AbseilCopts.cmake @@ -3,11 +3,87 @@ # (1) Edit absl/copts/copts.py. # (2) Run `python /copts/generate_copts.py`. -list(APPEND GCC_EXCEPTIONS_FLAGS +list(APPEND ABSL_CLANG_CL_EXCEPTIONS_FLAGS + "/U_HAS_EXCEPTIONS" + "/D_HAS_EXCEPTIONS=1" + "/EHsc" +) + +list(APPEND ABSL_CLANG_CL_FLAGS + "/W3" + "-Wno-c++98-compat-pedantic" + "-Wno-conversion" + "-Wno-covered-switch-default" + "-Wno-deprecated" + "-Wno-disabled-macro-expansion" + "-Wno-double-promotion" + "-Wno-comma" + "-Wno-extra-semi" + "-Wno-extra-semi-stmt" + "-Wno-packed" + "-Wno-padded" + "-Wno-sign-compare" + "-Wno-float-conversion" + "-Wno-float-equal" + "-Wno-format-nonliteral" + "-Wno-gcc-compat" + "-Wno-global-constructors" + "-Wno-exit-time-destructors" + "-Wno-nested-anon-types" + "-Wno-non-modular-include-in-module" + "-Wno-old-style-cast" + "-Wno-range-loop-analysis" + "-Wno-reserved-id-macro" + "-Wno-shorten-64-to-32" + "-Wno-switch-enum" + "-Wno-thread-safety-negative" + "-Wno-undef" + "-Wno-unknown-warning-option" + "-Wno-unreachable-code" + "-Wno-unused-macros" + "-Wno-weak-vtables" + "-Wbitfield-enum-conversion" + "-Wbool-conversion" + "-Wconstant-conversion" + "-Wenum-conversion" + "-Wint-conversion" + "-Wliteral-conversion" + "-Wnon-literal-null-conversion" + "-Wnull-conversion" + "-Wobjc-literal-conversion" + "-Wno-sign-conversion" + "-Wstring-conversion" + "/DNOMINMAX" + "/DWIN32_LEAN_AND_MEAN" + "/D_CRT_SECURE_NO_WARNINGS" + "/D_SCL_SECURE_NO_WARNINGS" + "/D_ENABLE_EXTENDED_ALIGNED_STORAGE" +) + +list(APPEND ABSL_CLANG_CL_TEST_FLAGS + "-Wno-c99-extensions" + "-Wno-missing-noreturn" + "-Wno-missing-prototypes" + "-Wno-missing-variable-declarations" + "-Wno-null-conversion" + "-Wno-shadow" + "-Wno-shift-sign-overflow" + "-Wno-sign-compare" + "-Wno-unused-function" + "-Wno-unused-member-function" + "-Wno-unused-parameter" + "-Wno-unused-private-field" + "-Wno-unused-template" + "-Wno-used-but-marked-unused" + "-Wno-zero-as-null-pointer-constant" + "-Wno-gnu-zero-variadic-macro-arguments" +) + +list(APPEND ABSL_GCC_EXCEPTIONS_FLAGS "-fexceptions" ) -list(APPEND GCC_FLAGS +list(APPEND ABSL_GCC_FLAGS "-Wall" "-Wextra" "-Wcast-qual" @@ -24,7 +100,7 @@ list(APPEND GCC_FLAGS "-Wno-sign-compare" ) -list(APPEND GCC_TEST_FLAGS +list(APPEND ABSL_GCC_TEST_FLAGS "-Wno-conversion-null" "-Wno-missing-declarations" "-Wno-sign-compare" @@ -33,11 +109,11 @@ list(APPEND GCC_TEST_FLAGS "-Wno-unused-private-field" ) -list(APPEND LLVM_EXCEPTIONS_FLAGS +list(APPEND ABSL_LLVM_EXCEPTIONS_FLAGS "-fexceptions" ) -list(APPEND LLVM_FLAGS +list(APPEND ABSL_LLVM_FLAGS "-Wall" "-Wextra" "-Weverything" @@ -85,7 +161,7 @@ list(APPEND LLVM_FLAGS "-Wstring-conversion" ) -list(APPEND LLVM_TEST_FLAGS +list(APPEND ABSL_LLVM_TEST_FLAGS "-Wno-c99-extensions" "-Wno-missing-noreturn" "-Wno-missing-prototypes" @@ -104,28 +180,28 @@ list(APPEND LLVM_TEST_FLAGS "-Wno-gnu-zero-variadic-macro-arguments" ) -list(APPEND MSVC_EXCEPTIONS_FLAGS +list(APPEND ABSL_MSVC_EXCEPTIONS_FLAGS "/U_HAS_EXCEPTIONS" "/D_HAS_EXCEPTIONS=1" "/EHsc" ) -list(APPEND MSVC_FLAGS +list(APPEND ABSL_MSVC_FLAGS "/W3" + "/DNOMINMAX" + "/DWIN32_LEAN_AND_MEAN" + "/D_CRT_SECURE_NO_WARNINGS" + "/D_SCL_SECURE_NO_WARNINGS" + "/D_ENABLE_EXTENDED_ALIGNED_STORAGE" "/wd4005" "/wd4068" "/wd4180" "/wd4244" "/wd4267" "/wd4800" - "/DNOMINMAX" - "/DWIN32_LEAN_AND_MEAN" - "/D_CRT_SECURE_NO_WARNINGS" - "/D_SCL_SECURE_NO_WARNINGS" - "/D_ENABLE_EXTENDED_ALIGNED_STORAGE" ) -list(APPEND MSVC_TEST_FLAGS +list(APPEND ABSL_MSVC_TEST_FLAGS "/wd4018" "/wd4101" "/wd4503" diff --git a/absl/copts/GENERATED_copts.bzl b/absl/copts/GENERATED_copts.bzl index d23f4069..e05a58e3 100644 --- a/absl/copts/GENERATED_copts.bzl +++ b/absl/copts/GENERATED_copts.bzl @@ -4,11 +4,87 @@ (2) Run `python /copts/generate_copts.py`. """ -GCC_EXCEPTIONS_FLAGS = [ +ABSL_CLANG_CL_EXCEPTIONS_FLAGS = [ + "/U_HAS_EXCEPTIONS", + "/D_HAS_EXCEPTIONS=1", + "/EHsc", +] + +ABSL_CLANG_CL_FLAGS = [ + "/W3", + "-Wno-c++98-compat-pedantic", + "-Wno-conversion", + "-Wno-covered-switch-default", + "-Wno-deprecated", + "-Wno-disabled-macro-expansion", + "-Wno-double-promotion", + "-Wno-comma", + "-Wno-extra-semi", + "-Wno-extra-semi-stmt", + "-Wno-packed", + "-Wno-padded", + "-Wno-sign-compare", + "-Wno-float-conversion", + "-Wno-float-equal", + "-Wno-format-nonliteral", + "-Wno-gcc-compat", + "-Wno-global-constructors", + "-Wno-exit-time-destructors", + "-Wno-nested-anon-types", + "-Wno-non-modular-include-in-module", + "-Wno-old-style-cast", + "-Wno-range-loop-analysis", + "-Wno-reserved-id-macro", + "-Wno-shorten-64-to-32", + "-Wno-switch-enum", + "-Wno-thread-safety-negative", + "-Wno-undef", + "-Wno-unknown-warning-option", + "-Wno-unreachable-code", + "-Wno-unused-macros", + "-Wno-weak-vtables", + "-Wbitfield-enum-conversion", + "-Wbool-conversion", + "-Wconstant-conversion", + "-Wenum-conversion", + "-Wint-conversion", + "-Wliteral-conversion", + "-Wnon-literal-null-conversion", + "-Wnull-conversion", + "-Wobjc-literal-conversion", + "-Wno-sign-conversion", + "-Wstring-conversion", + "/DNOMINMAX", + "/DWIN32_LEAN_AND_MEAN", + "/D_CRT_SECURE_NO_WARNINGS", + "/D_SCL_SECURE_NO_WARNINGS", + "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", +] + +ABSL_CLANG_CL_TEST_FLAGS = [ + "-Wno-c99-extensions", + "-Wno-missing-noreturn", + "-Wno-missing-prototypes", + "-Wno-missing-variable-declarations", + "-Wno-null-conversion", + "-Wno-shadow", + "-Wno-shift-sign-overflow", + "-Wno-sign-compare", + "-Wno-unused-function", + "-Wno-unused-member-function", + "-Wno-unused-parameter", + "-Wno-unused-private-field", + "-Wno-unused-template", + "-Wno-used-but-marked-unused", + "-Wno-zero-as-null-pointer-constant", + "-Wno-gnu-zero-variadic-macro-arguments", +] + +ABSL_GCC_EXCEPTIONS_FLAGS = [ "-fexceptions", ] -GCC_FLAGS = [ +ABSL_GCC_FLAGS = [ "-Wall", "-Wextra", "-Wcast-qual", @@ -25,7 +101,7 @@ GCC_FLAGS = [ "-Wno-sign-compare", ] -GCC_TEST_FLAGS = [ +ABSL_GCC_TEST_FLAGS = [ "-Wno-conversion-null", "-Wno-missing-declarations", "-Wno-sign-compare", @@ -34,11 +110,11 @@ GCC_TEST_FLAGS = [ "-Wno-unused-private-field", ] -LLVM_EXCEPTIONS_FLAGS = [ +ABSL_LLVM_EXCEPTIONS_FLAGS = [ "-fexceptions", ] -LLVM_FLAGS = [ +ABSL_LLVM_FLAGS = [ "-Wall", "-Wextra", "-Weverything", @@ -86,7 +162,7 @@ LLVM_FLAGS = [ "-Wstring-conversion", ] -LLVM_TEST_FLAGS = [ +ABSL_LLVM_TEST_FLAGS = [ "-Wno-c99-extensions", "-Wno-missing-noreturn", "-Wno-missing-prototypes", @@ -105,28 +181,28 @@ LLVM_TEST_FLAGS = [ "-Wno-gnu-zero-variadic-macro-arguments", ] -MSVC_EXCEPTIONS_FLAGS = [ +ABSL_MSVC_EXCEPTIONS_FLAGS = [ "/U_HAS_EXCEPTIONS", "/D_HAS_EXCEPTIONS=1", "/EHsc", ] -MSVC_FLAGS = [ +ABSL_MSVC_FLAGS = [ "/W3", + "/DNOMINMAX", + "/DWIN32_LEAN_AND_MEAN", + "/D_CRT_SECURE_NO_WARNINGS", + "/D_SCL_SECURE_NO_WARNINGS", + "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", "/wd4005", "/wd4068", "/wd4180", "/wd4244", "/wd4267", "/wd4800", - "/DNOMINMAX", - "/DWIN32_LEAN_AND_MEAN", - "/D_CRT_SECURE_NO_WARNINGS", - "/D_SCL_SECURE_NO_WARNINGS", - "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", ] -MSVC_TEST_FLAGS = [ +ABSL_MSVC_TEST_FLAGS = [ "/wd4018", "/wd4101", "/wd4503", diff --git a/absl/copts/configure_copts.bzl b/absl/copts/configure_copts.bzl index 57cd3f62..1655addd 100644 --- a/absl/copts/configure_copts.bzl +++ b/absl/copts/configure_copts.bzl @@ -6,35 +6,35 @@ change Abseil copts, edit absl/copts/copts.py load( "//absl:copts/GENERATED_copts.bzl", - "GCC_EXCEPTIONS_FLAGS", - "GCC_FLAGS", - "GCC_TEST_FLAGS", - "LLVM_EXCEPTIONS_FLAGS", - "LLVM_FLAGS", - "LLVM_TEST_FLAGS", - "MSVC_EXCEPTIONS_FLAGS", - "MSVC_FLAGS", - "MSVC_TEST_FLAGS", + "ABSL_GCC_EXCEPTIONS_FLAGS", + "ABSL_GCC_FLAGS", + "ABSL_GCC_TEST_FLAGS", + "ABSL_LLVM_EXCEPTIONS_FLAGS", + "ABSL_LLVM_FLAGS", + "ABSL_LLVM_TEST_FLAGS", + "ABSL_MSVC_EXCEPTIONS_FLAGS", + "ABSL_MSVC_FLAGS", + "ABSL_MSVC_TEST_FLAGS", ) ABSL_DEFAULT_COPTS = select({ - "//absl:windows": MSVC_FLAGS, - "//absl:llvm_compiler": LLVM_FLAGS, - "//conditions:default": GCC_FLAGS, + "//absl:windows": ABSL_MSVC_FLAGS, + "//absl:llvm_compiler": ABSL_LLVM_FLAGS, + "//conditions:default": ABSL_GCC_FLAGS, }) # in absence of modules (--compiler=gcc or -c opt), cc_tests leak their copts # to their (included header) dependencies and fail to build outside absl ABSL_TEST_COPTS = ABSL_DEFAULT_COPTS + select({ - "//absl:windows": MSVC_TEST_FLAGS, - "//absl:llvm_compiler": LLVM_TEST_FLAGS, - "//conditions:default": GCC_TEST_FLAGS, + "//absl:windows": ABSL_MSVC_TEST_FLAGS, + "//absl:llvm_compiler": ABSL_LLVM_TEST_FLAGS, + "//conditions:default": ABSL_GCC_TEST_FLAGS, }) ABSL_EXCEPTIONS_FLAG = select({ - "//absl:windows": MSVC_EXCEPTIONS_FLAGS, - "//absl:llvm_compiler": LLVM_EXCEPTIONS_FLAGS, - "//conditions:default": GCC_EXCEPTIONS_FLAGS, + "//absl:windows": ABSL_MSVC_EXCEPTIONS_FLAGS, + "//absl:llvm_compiler": ABSL_LLVM_EXCEPTIONS_FLAGS, + "//conditions:default": ABSL_GCC_EXCEPTIONS_FLAGS, }) ABSL_EXCEPTIONS_FLAG_LINKOPTS = select({ diff --git a/absl/copts/copts.py b/absl/copts/copts.py index 5a2d91a3..3c9d4294 100644 --- a/absl/copts/copts.py +++ b/absl/copts/copts.py @@ -11,8 +11,119 @@ The generated copts are consumed by configure_copts.bzl and AbseilConfigureCopts.cmake. """ +# /Wall with msvc includes unhelpful warnings such as C4711, C4710, ... +MSVC_BIG_WARNING_FLAGS = [ + "/W3", +] + +LLVM_BIG_WARNING_FLAGS = [ + "-Wall", + "-Wextra", + "-Weverything", +] + +# Docs on single flags is preceded by a comment. +# Docs on groups of flags is preceded by ###. +LLVM_DISABLE_WARNINGS_FLAGS = [ + # Abseil does not support C++98 + "-Wno-c++98-compat-pedantic", + # Turns off all implicit conversion warnings. Most are re-enabled below. + "-Wno-conversion", + "-Wno-covered-switch-default", + "-Wno-deprecated", + "-Wno-disabled-macro-expansion", + "-Wno-double-promotion", + ### + # Turned off as they include valid C++ code. + "-Wno-comma", + "-Wno-extra-semi", + "-Wno-extra-semi-stmt", + "-Wno-packed", + "-Wno-padded", + ### + # Google style does not use unsigned integers, though STL containers + # have unsigned types. + "-Wno-sign-compare", + ### + "-Wno-float-conversion", + "-Wno-float-equal", + "-Wno-format-nonliteral", + # Too aggressive: warns on Clang extensions enclosed in Clang-only + # compilation paths. + "-Wno-gcc-compat", + ### + # Some internal globals are necessary. Don't do this at home. + "-Wno-global-constructors", + "-Wno-exit-time-destructors", + ### + "-Wno-nested-anon-types", + "-Wno-non-modular-include-in-module", + "-Wno-old-style-cast", + # Warns on preferred usage of non-POD types such as string_view + "-Wno-range-loop-analysis", + "-Wno-reserved-id-macro", + "-Wno-shorten-64-to-32", + "-Wno-switch-enum", + "-Wno-thread-safety-negative", + "-Wno-undef", + "-Wno-unknown-warning-option", + "-Wno-unreachable-code", + # Causes warnings on include guards + "-Wno-unused-macros", + "-Wno-weak-vtables", + ### + # Implicit conversion warnings turned off by -Wno-conversion + # which are re-enabled below. + "-Wbitfield-enum-conversion", + "-Wbool-conversion", + "-Wconstant-conversion", + "-Wenum-conversion", + "-Wint-conversion", + "-Wliteral-conversion", + "-Wnon-literal-null-conversion", + "-Wnull-conversion", + "-Wobjc-literal-conversion", + "-Wno-sign-conversion", + "-Wstring-conversion", +] + +LLVM_TEST_DISABLE_WARNINGS_FLAGS = [ + "-Wno-c99-extensions", + "-Wno-missing-noreturn", + "-Wno-missing-prototypes", + "-Wno-missing-variable-declarations", + "-Wno-null-conversion", + "-Wno-shadow", + "-Wno-shift-sign-overflow", + "-Wno-sign-compare", + "-Wno-unused-function", + "-Wno-unused-member-function", + "-Wno-unused-parameter", + "-Wno-unused-private-field", + "-Wno-unused-template", + "-Wno-used-but-marked-unused", + "-Wno-zero-as-null-pointer-constant", + # gtest depends on this GNU extension being offered. + "-Wno-gnu-zero-variadic-macro-arguments", +] + +MSVC_STYLE_EXCEPTIONS_FLAGS = [ + "/U_HAS_EXCEPTIONS", "/D_HAS_EXCEPTIONS=1", "/EHsc" +] + +MSVC_DEFINES = [ + "/DNOMINMAX", # Don't define min and max macros (windows.h) + # Don't bloat namespace with incompatible winsock versions. + "/DWIN32_LEAN_AND_MEAN", + # Don't warn about usage of insecure C functions. + "/D_CRT_SECURE_NO_WARNINGS", + "/D_SCL_SECURE_NO_WARNINGS", + # Introduced in VS 2017 15.8, allow overaligned types in aligned_storage + "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", +] + COPT_VARS = { - "GCC_FLAGS": [ + "ABSL_GCC_FLAGS": [ "-Wall", "-Wextra", "-Wcast-qual", @@ -33,7 +144,7 @@ COPT_VARS = { # have unsigned types. "-Wno-sign-compare", ], - "GCC_TEST_FLAGS": [ + "ABSL_GCC_TEST_FLAGS": [ "-Wno-conversion-null", "-Wno-missing-declarations", "-Wno-sign-compare", @@ -41,98 +152,15 @@ COPT_VARS = { "-Wno-unused-parameter", "-Wno-unused-private-field", ], - "GCC_EXCEPTIONS_FLAGS": ["-fexceptions"], - - # Docs on single flags is preceded by a comment. - # Docs on groups of flags is preceded by ###. - "LLVM_FLAGS": [ - "-Wall", - "-Wextra", - "-Weverything", - # Abseil does not support C++98 - "-Wno-c++98-compat-pedantic", - # Turns off all implicit conversion warnings. Most are re-enabled below. - "-Wno-conversion", - "-Wno-covered-switch-default", - "-Wno-deprecated", - "-Wno-disabled-macro-expansion", - "-Wno-double-promotion", - ### - # Turned off as they include valid C++ code. - "-Wno-comma", - "-Wno-extra-semi", - "-Wno-extra-semi-stmt", - "-Wno-packed", - "-Wno-padded", - ### - # Google style does not use unsigned integers, though STL containers - # have unsigned types. - "-Wno-sign-compare", - ### - "-Wno-float-conversion", - "-Wno-float-equal", - "-Wno-format-nonliteral", - # Too aggressive: warns on Clang extensions enclosed in Clang-only - # compilation paths. - "-Wno-gcc-compat", - ### - # Some internal globals are necessary. Don't do this at home. - "-Wno-global-constructors", - "-Wno-exit-time-destructors", - ### - "-Wno-nested-anon-types", - "-Wno-non-modular-include-in-module", - "-Wno-old-style-cast", - # Warns on preferred usage of non-POD types such as string_view - "-Wno-range-loop-analysis", - "-Wno-reserved-id-macro", - "-Wno-shorten-64-to-32", - "-Wno-switch-enum", - "-Wno-thread-safety-negative", - "-Wno-undef", - "-Wno-unknown-warning-option", - "-Wno-unreachable-code", - # Causes warnings on include guards - "-Wno-unused-macros", - "-Wno-weak-vtables", - ### - # Implicit conversion warnings turned off by -Wno-conversion - # which are re-enabled below. - "-Wbitfield-enum-conversion", - "-Wbool-conversion", - "-Wconstant-conversion", - "-Wenum-conversion", - "-Wint-conversion", - "-Wliteral-conversion", - "-Wnon-literal-null-conversion", - "-Wnull-conversion", - "-Wobjc-literal-conversion", - "-Wno-sign-conversion", - "-Wstring-conversion", - ], - "LLVM_TEST_FLAGS": [ - "-Wno-c99-extensions", - "-Wno-missing-noreturn", - "-Wno-missing-prototypes", - "-Wno-missing-variable-declarations", - "-Wno-null-conversion", - "-Wno-shadow", - "-Wno-shift-sign-overflow", - "-Wno-sign-compare", - "-Wno-unused-function", - "-Wno-unused-member-function", - "-Wno-unused-parameter", - "-Wno-unused-private-field", - "-Wno-unused-template", - "-Wno-used-but-marked-unused", - "-Wno-zero-as-null-pointer-constant", - # gtest depends on this GNU extension being offered. - "-Wno-gnu-zero-variadic-macro-arguments", - ], - "LLVM_EXCEPTIONS_FLAGS": ["-fexceptions"], - # /Wall with msvc includes unhelpful warnings such as C4711, C4710, ... - "MSVC_FLAGS": [ - "/W3", + "ABSL_GCC_EXCEPTIONS_FLAGS": ["-fexceptions"], + "ABSL_LLVM_FLAGS": LLVM_BIG_WARNING_FLAGS + LLVM_DISABLE_WARNINGS_FLAGS, + "ABSL_LLVM_TEST_FLAGS": LLVM_TEST_DISABLE_WARNINGS_FLAGS, + "ABSL_LLVM_EXCEPTIONS_FLAGS": ["-fexceptions"], + "ABSL_CLANG_CL_FLAGS": (MSVC_BIG_WARNING_FLAGS + + LLVM_DISABLE_WARNINGS_FLAGS + MSVC_DEFINES), + "ABSL_CLANG_CL_TEST_FLAGS": LLVM_TEST_DISABLE_WARNINGS_FLAGS, + "ABSL_CLANG_CL_EXCEPTIONS_FLAGS": MSVC_STYLE_EXCEPTIONS_FLAGS, + "ABSL_MSVC_FLAGS": MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + [ "/wd4005", # macro-redefinition "/wd4068", # unknown pragma "/wd4180", # qualifier applied to function type has no meaning; ignored @@ -140,21 +168,11 @@ COPT_VARS = { "/wd4267", # conversion from 'size_t' to 'type', possible loss of data # forcing value to bool 'true' or 'false' (performance warning) "/wd4800", - "/DNOMINMAX", # Don't define min and max macros (windows.h) - # Don't bloat namespace with incompatible winsock versions. - "/DWIN32_LEAN_AND_MEAN", - # Don't warn about usage of insecure C functions. - "/D_CRT_SECURE_NO_WARNINGS", - "/D_SCL_SECURE_NO_WARNINGS", - # Introduced in VS 2017 15.8, allow overaligned types in aligned_storage - "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", ], - "MSVC_TEST_FLAGS": [ + "ABSL_MSVC_TEST_FLAGS": [ "/wd4018", # signed/unsigned mismatch "/wd4101", # unreferenced local variable "/wd4503", # decorated name length exceeded, name was truncated ], - "MSVC_EXCEPTIONS_FLAGS": [ - "/U_HAS_EXCEPTIONS", "/D_HAS_EXCEPTIONS=1", "/EHsc" - ] + "ABSL_MSVC_EXCEPTIONS_FLAGS": MSVC_STYLE_EXCEPTIONS_FLAGS, } -- cgit v1.2.3 From 5b65c4af5107176555b23a638e5947686410ac1f Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 27 Mar 2019 08:05:41 -0700 Subject: Export of internal Abseil changes. -- f6c627ce4470a814adc377947b58346eef69a4c9 by Jon Cohen : Don't create install rules when Abseil is used as a subdirectory. Fix #287 PiperOrigin-RevId: 240559825 -- a5d9b06fe736143068997988b654b5f66ec3266a by Matt Calabrese : Make absl::nullopt an inline constexpr variable, as specified in the standard (with a workaround for pre-c++17 compilers). PiperOrigin-RevId: 240552286 -- d7bee50cff745fbb8d1cdf56a200d9073d311c80 by Abseil Team : Internal Change PiperOrigin-RevId: 240425622 -- 828dd49d392d83dbeecd9d3e9cb14551ab265905 by Jon Cohen : Add default link options to absl builds. Currently all this does is add -ignore:4221 to Abseil msvc builds, but the structure is all in place to add more link options when necessary Fix #277 Note: This CL changes tact for us in that it puts the default options in the helper function as opposed to the invocations of absl_cc_blah. The original intent of keeping these out of the helper functions was to make generating the CMakeLists.txt files have a smaller diff, but looking now that is a problem for the future, and small compared to making maintenance and use of our CMake buildsystem easier PiperOrigin-RevId: 240409463 -- 4aa120e9dcf76d29e9ca0008d0f6d4d9fa8abe8c by Matt Kulukundis : Reduce flake rate for non-determistic test to < 1/10,000 PiperOrigin-RevId: 240370938 -- bc30e219531827bfbf90915b2067c7fb8160bb6d by Derek Mauro : Add Bazel caching on Kokoro for new linux targets. PiperOrigin-RevId: 240356556 -- c4e06d79a50d7bb211312b7845c4bd92c0761747 by Jon Cohen : include AbseilInstallDirs instead of GNUInstallDirs. It worked before because global_CMakeLists.txt also included AbseilInstallDirs PiperOrigin-RevId: 240206409 -- c254dc6cade8a263f3f97fb1417d92fe5235ff32 by Jon Cohen : Fix logic for when we create the variant_exception_safety_test in CMake. Currently we are only running in on gcc > 4.9, when we want it run on every compiler except gcc <= 4.8 PiperOrigin-RevId: 240194174 -- 01518006b351d3670ba1d349cfbcb7dd6f3a8b84 by CJ Johnson : Removes old implementation warning comment now that InlinedVector has an implementation detail file PiperOrigin-RevId: 240167265 -- eb05355ae8c7397752ab7a65afc9e0a99472ba9d by Jon Cohen : Remove the forward declaration of Span PiperOrigin-RevId: 240156660 -- b7e75aa3933d6e79dd086821cf58d15e72f476f4 by Jon Cohen : Prepare CMake install rule for LTS releases: * Remove the warning against installing in system install locations * Insert versioning to keep different LTS installs from colliding. Headers are installed in /absl_$version/include, .a files in /absl_$version/lib, and config files in /absl_$version/lib/cmake PiperOrigin-RevId: 240153986 -- de63488ab6236e041f08260794b0b634a2b8ed16 by CJ Johnson : Reduce reader confusion by using std::addressof(...) even when the type is known to not overload operator&(...) PiperOrigin-RevId: 240131902 GitOrigin-RevId: f6c627ce4470a814adc377947b58346eef69a4c9 Change-Id: I95dbbacaaf65aceeeca9e9bee5fd9ea456225f62 --- CMake/AbseilHelpers.cmake | 21 +++--- CMake/AbseilInstallDirs.cmake | 20 ++++++ CMake/install_test_project/test.sh | 92 +++++++++++++++++--------- CMakeLists.txt | 66 ++++++++++++------- absl/algorithm/BUILD.bazel | 6 ++ absl/base/BUILD.bazel | 50 +++++++++----- absl/container/BUILD.bazel | 60 ++++++++++++++++- absl/container/inlined_vector.h | 19 ++---- absl/container/internal/raw_hash_set_test.cc | 4 +- absl/copts/AbseilConfigureCopts.cmake | 3 + absl/copts/GENERATED_AbseilCopts.cmake | 4 ++ absl/copts/GENERATED_copts.bzl | 4 ++ absl/copts/configure_copts.bzl | 6 ++ absl/copts/copts.py | 45 ++++++++----- absl/debugging/BUILD.bazel | 21 +++++- absl/hash/BUILD.bazel | 7 ++ absl/memory/BUILD.bazel | 5 +- absl/meta/BUILD.bazel | 3 + absl/numeric/BUILD.bazel | 4 ++ absl/synchronization/BUILD.bazel | 23 ++++--- absl/time/BUILD.bazel | 5 ++ absl/time/internal/cctz/BUILD.bazel | 2 - absl/types/BUILD.bazel | 31 +++++---- absl/types/CMakeLists.txt | 6 +- absl/types/optional.cc | 24 ------- absl/types/optional.h | 27 ++++---- absl/types/optional_test.cc | 8 --- absl/types/span.h | 97 ++++++++++++++++------------ absl/utility/BUILD.bazel | 3 + ci/cmake_install_test.sh | 2 +- ci/linux_clang-latest_libcxx_bazel.sh | 20 +++++- ci/linux_clang-latest_libstdcxx_bazel.sh | 20 +++++- ci/linux_gcc-latest_libstdcxx_bazel.sh | 20 +++++- 33 files changed, 494 insertions(+), 234 deletions(-) create mode 100644 CMake/AbseilInstallDirs.cmake delete mode 100644 absl/types/optional.cc (limited to 'absl/copts/configure_copts.bzl') diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake index 6d26169d..be9a0e9c 100644 --- a/CMake/AbseilHelpers.cmake +++ b/CMake/AbseilHelpers.cmake @@ -16,7 +16,7 @@ include(CMakeParseArguments) include(AbseilConfigureCopts) -include(GNUInstallDirs) +include(AbseilInstallDirs) # The IDE folder for Abseil that will be used if Abseil is included in a CMake # project that sets @@ -105,13 +105,15 @@ function(absl_cc_library) target_include_directories(${_NAME} PUBLIC $ - $ + $ ) target_compile_options(${_NAME} PRIVATE ${ABSL_CC_LIB_COPTS}) target_link_libraries(${_NAME} PUBLIC ${ABSL_CC_LIB_DEPS} - PRIVATE ${ABSL_CC_LIB_LINKOPTS} + PRIVATE + ${ABSL_CC_LIB_LINKOPTS} + ${ABSL_DEFAULT_LINKOPTS} ) target_compile_definitions(${_NAME} PUBLIC ${ABSL_CC_LIB_DEFINES}) @@ -140,10 +142,13 @@ function(absl_cc_library) target_include_directories(${_NAME} INTERFACE $ - $ + $ ) target_link_libraries(${_NAME} - INTERFACE ${ABSL_CC_LIB_DEPS} ${ABSL_CC_LIB_LINKOPTS} + INTERFACE + ${ABSL_CC_LIB_DEPS} + ${ABSL_CC_LIB_LINKOPTS} + ${ABSL_DEFAULT_LINKOPTS} ) target_compile_definitions(${_NAME} INTERFACE ${ABSL_CC_LIB_DEFINES}) endif() @@ -152,9 +157,9 @@ function(absl_cc_library) # installed abseil can't be tested. if (NOT ABSL_CC_LIB_TESTONLY) install(TARGETS ${_NAME} EXPORT ${PROJECT_NAME}Targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${ABSL_INSTALL_BINDIR} + LIBRARY DESTINATION ${ABSL_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${ABSL_INSTALL_LIBDIR} ) endif() diff --git a/CMake/AbseilInstallDirs.cmake b/CMake/AbseilInstallDirs.cmake new file mode 100644 index 00000000..5b67008b --- /dev/null +++ b/CMake/AbseilInstallDirs.cmake @@ -0,0 +1,20 @@ +include(GNUInstallDirs) + +# absl_VERSION is only set if we are an LTS release being installed, in which +# case it may be into a system directory and so we need to make subdirectories +# for each installed version of Abseil. This mechanism is implemented in +# Abseil's internal Copybara (https://github.com/google/copybara) workflows and +# isn't visible in the CMake buildsystem itself. + +if (absl_VERSION) + set(ABSL_SUBDIR "${PROJECT_NAME}_${PROJECT_VERSION}") + set(ABSL_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}/${ABSL_SUBDIR}") + set(ABSL_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${ABSL_SUBDIR}") + set(ABSL_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/{ABSL_SUBDIR}") + set(ABSL_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${ABSL_SUBDIR}") +else() + set(ABSL_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}") + set(ABSL_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + set(ABSL_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}") + set(ABSL_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}") +endif() \ No newline at end of file diff --git a/CMake/install_test_project/test.sh b/CMake/install_test_project/test.sh index 3e77e79a..99989b03 100755 --- a/CMake/install_test_project/test.sh +++ b/CMake/install_test_project/test.sh @@ -24,15 +24,6 @@ # Fail on any error. Treat unset variables an error. Print commands as executed. set -euox pipefail -absl_dir=/abseil-cpp -absl_build_dir=/buildfs/absl-build -project_dir="${absl_dir}"/CMake/install_test_project -project_build_dir=/buildfs/project-build -install_dir="${project_build_dir}"/install - -mkdir -p "${absl_build_dir}" -mkdir -p "${project_build_dir}" -mkdir -p "${install_dir}" install_absl() { pushd "${absl_build_dir}" @@ -51,10 +42,41 @@ uninstall_absl() { mkdir -p "${absl_build_dir}" } +lts_install="" + +while getopts ":l" lts; do + case "${lts}" in + l ) + lts_install="true" + ;; + esac +done + +absl_dir=/abseil-cpp +absl_build_dir=/buildfs/absl-build +project_dir="${absl_dir}"/CMake/install_test_project +project_build_dir=/buildfs/project-build + +mkdir -p "${absl_build_dir}" +mkdir -p "${project_build_dir}" + +if [[ "${lts_install}" ]]; then + install_dir="/usr/local" +else + install_dir="${project_build_dir}"/install +fi +mkdir -p "${install_dir}" + # Test build, install, and link against installed abseil -install_absl "${install_dir}" pushd "${project_build_dir}" -cmake "${project_dir}" -DCMAKE_PREFIX_PATH="${install_dir}" +if [[ "${lts_install}" ]]; then + install_absl + cmake "${project_dir}" +else + install_absl "${install_dir}" + cmake "${project_dir}" -DCMAKE_PREFIX_PATH="${install_dir}" +fi + cmake --build . --target simple output="$(${project_build_dir}/simple "printme" 2>&1)" @@ -64,14 +86,16 @@ if [[ "${output}" != *"Arg 1: printme"* ]]; then exit 1 fi +popd + # Test that we haven't accidentally made absl::abslblah pushd "${install_dir}" # Starting in CMake 3.12 the default install dir is lib$bit_width -if [[ -d lib ]]; then - libdir="lib" -elif [[ -d lib64 ]]; then +if [[ -d lib64 ]]; then libdir="lib64" +elif [[ -d lib ]]; then + libdir="lib" else echo "ls *, */*, */*/*:" ls * @@ -80,7 +104,15 @@ else echo "unknown lib dir" fi -if ! grep absl::strings "${libdir}"/cmake/absl/abslTargets.cmake; then +if [[ "${lts_install}" ]]; then + # LTS versions append the date of the release to the subdir. + # 9999/99/99 is the dummy date used in the local_lts workflow. + absl_subdir="absl_99999999" +else + absl_subdir="absl" +fi + +if ! grep absl::strings "${libdir}/cmake/${absl_subdir}/abslTargets.cmake"; then cat "${libdir}"/cmake/absl/abslTargets.cmake echo "CMake targets named incorrectly" exit 1 @@ -89,22 +121,24 @@ fi uninstall_absl popd -# Test that we warn if installed without a prefix or a system prefix -output="$(install_absl 2>&1)" -if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then - echo "Install without prefix didn't warn as expected. Output:" - echo "${output}" - exit 1 -fi -uninstall_absl +if [[ ! "${lts_install}" ]]; then + # Test that we warn if installed without a prefix or a system prefix + output="$(install_absl 2>&1)" + if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then + echo "Install without prefix didn't warn as expected. Output:" + echo "${output}" + exit 1 + fi + uninstall_absl -output="$(install_absl /usr 2>&1)" -if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then - echo "Install with /usr didn't warn as expected. Output:" - echo "${output}" - exit 1 + output="$(install_absl /usr 2>&1)" + if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then + echo "Install with /usr didn't warn as expected. Output:" + echo "${output}" + exit 1 + fi + uninstall_absl fi -uninstall_absl echo "Install test complete!" exit 0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f4fbdcf..ad55fa47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,13 +22,14 @@ cmake_minimum_required(VERSION 3.5) # Compiler id for Apple Clang is now AppleClang. -if (POLICY CMP0025) - cmake_policy(SET CMP0025 NEW) -endif() +cmake_policy(SET CMP0025 NEW) # if command can use IN_LIST cmake_policy(SET CMP0057 NEW) +# Project version variables are the empty std::string if version is unspecified +cmake_policy(SET CMP0048 NEW) + project(absl) # when absl is included as subproject (i.e. using add_subdirectory(abseil-cpp)) @@ -44,7 +45,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/absl/copts ) -include(GNUInstallDirs) +include(AbseilInstallDirs) include(CMakePackageConfigHelpers) include(AbseilHelpers) @@ -85,6 +86,7 @@ if(${ABSL_RUN_TESTS}) enable_testing() endif() +# absl:lts-remove-begin(system installation is supported for LTS releases) # We don't support system-wide installation list(APPEND SYSTEM_INSTALL_DIRS "/usr/local" "/usr" "/opt/" "/opt/local" "c:/Program Files/${PROJECT_NAME}") if(NOT DEFINED CMAKE_INSTALL_PREFIX OR CMAKE_INSTALL_PREFIX IN_LIST SYSTEM_INSTALL_DIRS) @@ -94,6 +96,7 @@ releases of Abseil. Please set CMAKE_INSTALL_PREFIX to install Abseil in your \ source or build tree directly.\ ") endif() +# absl:lts-remove-end ## check targets if(BUILD_TESTING) @@ -118,25 +121,40 @@ endif() add_subdirectory(absl) -# install as a subdirectory only -install(EXPORT ${PROJECT_NAME}Targets - NAMESPACE absl:: - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" -) - -configure_package_config_file( - CMake/abslConfig.cmake.in - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" -) +if (ABSL_ENABLE_INSTALL) + # install as a subdirectory only + install(EXPORT ${PROJECT_NAME}Targets + NAMESPACE absl:: + DESTINATION "${ABSL_INSTALL_CONFIGDIR}" + ) -install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" -) + configure_package_config_file( + CMake/abslConfig.cmake.in + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION "${ABSL_INSTALL_CONFIGDIR}" + ) + install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + DESTINATION "${ABSL_INSTALL_CONFIGDIR}" + ) -install(DIRECTORY absl - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - FILES_MATCHING - PATTERN "*.inc" - PATTERN "*.h" -) + # Abseil only has a version in LTS releases. This mechanism is accomplished + # Abseil's internal Copybara (https://github.com/google/copybara) workflows and + # isn't visible in the CMake buildsystem itself. + if (absl_VERSION) + write_basic_package_version_file( + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + COMPATIBILITY ExactVersion + ) + + install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION ${ABSL_INSTALL_CONFIGDIR} + ) + endif() # absl_VERSION + + install(DIRECTORY absl + DESTINATION ${ABSL_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.inc" + PATTERN "*.h" + ) +endif() # ABSL_ENABLE_INSTALL diff --git a/absl/algorithm/BUILD.bazel b/absl/algorithm/BUILD.bazel index 8d266db5..c506f3b9 100644 --- a/absl/algorithm/BUILD.bazel +++ b/absl/algorithm/BUILD.bazel @@ -17,6 +17,7 @@ load( "//absl:copts/configure_copts.bzl", "ABSL_DEFAULT_COPTS", + "ABSL_DEFAULT_LINKOPTS", "ABSL_TEST_COPTS", ) @@ -28,6 +29,7 @@ cc_library( name = "algorithm", hdrs = ["algorithm.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, ) cc_test( @@ -35,6 +37,7 @@ cc_test( size = "small", srcs = ["algorithm_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":algorithm", "@com_google_googletest//:gtest_main", @@ -45,6 +48,7 @@ cc_test( name = "algorithm_benchmark", srcs = ["equal_benchmark.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = ["benchmark"], deps = [ ":algorithm", @@ -59,6 +63,7 @@ cc_library( "container.h", ], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":algorithm", "//absl/base:core_headers", @@ -70,6 +75,7 @@ cc_test( name = "container_test", srcs = ["container_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":container", "//absl/base", diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel index 804f62a0..8133a462 100644 --- a/absl/base/BUILD.bazel +++ b/absl/base/BUILD.bazel @@ -17,6 +17,7 @@ load( "//absl:copts/configure_copts.bzl", "ABSL_DEFAULT_COPTS", + "ABSL_DEFAULT_LINKOPTS", "ABSL_TEST_COPTS", "ABSL_EXCEPTIONS_FLAG", "ABSL_EXCEPTIONS_FLAG_LINKOPTS", @@ -40,6 +41,7 @@ cc_library( "internal/spinlock_wait.h", ], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl/base:__pkg__", ], @@ -53,6 +55,7 @@ cc_library( "policy_checks.h", ], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, ) cc_library( @@ -61,6 +64,7 @@ cc_library( hdrs = ["dynamic_annotations.h"], copts = ABSL_DEFAULT_COPTS, defines = ["__CLANG_SUPPORT_DYN_ANNOTATION__"], + linkopts = ABSL_DEFAULT_LINKOPTS, ) cc_library( @@ -74,6 +78,7 @@ cc_library( "thread_annotations.h", ], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":config", ], @@ -92,7 +97,7 @@ cc_library( linkopts = select({ "//absl:windows": [], "//conditions:default": ["-pthread"], - }), + }) + ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl:__subpackages__", ], @@ -115,6 +120,7 @@ cc_library( "internal/scheduling_mode.h", ], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl:__subpackages__", ], @@ -149,7 +155,7 @@ cc_library( linkopts = select({ "//absl:windows": [], "//conditions:default": ["-pthread"], - }), + }) + ABSL_DEFAULT_LINKOPTS, deps = [ ":base_internal", ":config", @@ -164,6 +170,7 @@ cc_test( size = "small", srcs = ["internal/atomic_hook_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":base", ":core_headers", @@ -178,6 +185,7 @@ cc_test( "bit_cast_test.cc", ], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":base", ":core_headers", @@ -190,7 +198,7 @@ cc_library( srcs = ["internal/throw_delegate.cc"], hdrs = ["internal/throw_delegate.h"], copts = ABSL_DEFAULT_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl:__subpackages__", ], @@ -204,7 +212,7 @@ cc_test( name = "throw_delegate_test", srcs = ["throw_delegate_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":throw_delegate", "@com_google_googletest//:gtest_main", @@ -216,6 +224,7 @@ cc_library( testonly = 1, hdrs = ["internal/exception_testing.h"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl:__subpackages__", ], @@ -228,6 +237,7 @@ cc_library( cc_library( name = "pretty_function", hdrs = ["internal/pretty_function.h"], + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = ["//absl:__subpackages__"], ) @@ -237,7 +247,7 @@ cc_library( srcs = ["internal/exception_safety_testing.cc"], hdrs = ["internal/exception_safety_testing.h"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":config", ":pretty_function", @@ -253,7 +263,7 @@ cc_test( name = "exception_safety_testing_test", srcs = ["exception_safety_testing_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":exception_safety_testing", "//absl/memory", @@ -271,6 +281,7 @@ cc_test( "internal/inline_variable_testing.h", ], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":base_internal", "@com_google_googletest//:gtest_main", @@ -282,6 +293,7 @@ cc_test( size = "small", srcs = ["invoke_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":base_internal", "//absl/memory", @@ -297,6 +309,7 @@ cc_library( testonly = 1, srcs = ["spinlock_test_common.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":base", ":core_headers", @@ -312,7 +325,7 @@ cc_test( size = "medium", srcs = ["spinlock_test_common.cc"], copts = ABSL_TEST_COPTS, - tags = ["no_test_wasm"], + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":base", ":core_headers", @@ -327,6 +340,7 @@ cc_library( testonly = 1, srcs = ["internal/spinlock_benchmark.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl/base:__pkg__", ], @@ -343,6 +357,7 @@ cc_binary( name = "spinlock_benchmark", testonly = 1, copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = ["//visibility:private"], deps = [ ":spinlock_benchmark_common", @@ -356,6 +371,7 @@ cc_library( "internal/unaligned_access.h", ], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":config", ":core_headers", @@ -378,9 +394,7 @@ cc_test( name = "config_test", srcs = ["config_test.cc"], copts = ABSL_TEST_COPTS, - tags = [ - "no_test_wasm", - ], + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":config", "//absl/synchronization:thread_pool", @@ -392,9 +406,7 @@ cc_test( name = "call_once_test", srcs = ["call_once_test.cc"], copts = ABSL_TEST_COPTS, - tags = [ - "no_test_wasm", - ], + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":base", ":core_headers", @@ -407,6 +419,7 @@ cc_test( name = "raw_logging_test", srcs = ["raw_logging_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":base", "//absl/strings", @@ -419,6 +432,7 @@ cc_test( size = "small", srcs = ["internal/sysinfo_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":base", "//absl/synchronization", @@ -431,6 +445,7 @@ cc_test( size = "small", srcs = ["internal/low_level_alloc_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = ["no_test_ios_x86_64"], deps = [":malloc_internal"], ) @@ -440,9 +455,7 @@ cc_test( size = "small", srcs = ["internal/thread_identity_test.cc"], copts = ABSL_TEST_COPTS, - tags = [ - "no_test_wasm", - ], + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":base", ":core_headers", @@ -455,6 +468,7 @@ cc_test( name = "thread_identity_benchmark", srcs = ["internal/thread_identity_benchmark.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = ["benchmark"], visibility = ["//visibility:private"], deps = [ @@ -467,6 +481,7 @@ cc_test( cc_library( name = "bits", hdrs = ["internal/bits.h"], + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl:__subpackages__", ], @@ -478,6 +493,7 @@ cc_test( size = "small", srcs = ["internal/bits_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":bits", "@com_google_googletest//:gtest_main", @@ -489,6 +505,7 @@ cc_library( testonly = 1, srcs = ["internal/scoped_set_env.cc"], hdrs = ["internal/scoped_set_env.h"], + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl:__subpackages__", ], @@ -500,6 +517,7 @@ cc_test( size = "small", srcs = ["internal/scoped_set_env_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":scoped_set_env", "@com_google_googletest//:gtest_main", diff --git a/absl/container/BUILD.bazel b/absl/container/BUILD.bazel index cd914baf..066a9886 100644 --- a/absl/container/BUILD.bazel +++ b/absl/container/BUILD.bazel @@ -17,6 +17,7 @@ load( "//absl:copts/configure_copts.bzl", "ABSL_DEFAULT_COPTS", + "ABSL_DEFAULT_LINKOPTS", "ABSL_EXCEPTIONS_FLAG", "ABSL_EXCEPTIONS_FLAG_LINKOPTS", "ABSL_TEST_COPTS", @@ -30,6 +31,7 @@ cc_library( name = "compressed_tuple", hdrs = ["internal/compressed_tuple.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/utility", ], @@ -39,6 +41,7 @@ cc_test( name = "compressed_tuple_test", srcs = ["internal/compressed_tuple_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":compressed_tuple", "//absl/memory", @@ -51,6 +54,7 @@ cc_library( name = "fixed_array", hdrs = ["fixed_array.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":compressed_tuple", "//absl/algorithm", @@ -65,7 +69,7 @@ cc_test( name = "fixed_array_test", srcs = ["fixed_array_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":fixed_array", "//absl/base:exception_testing", @@ -79,6 +83,7 @@ cc_test( name = "fixed_array_test_noexceptions", srcs = ["fixed_array_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":fixed_array", "//absl/base:exception_testing", @@ -92,7 +97,7 @@ cc_test( name = "fixed_array_exception_safety_test", srcs = ["fixed_array_exception_safety_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":fixed_array", "//absl/base:exception_safety_testing", @@ -104,6 +109,7 @@ cc_test( name = "fixed_array_benchmark", srcs = ["fixed_array_benchmark.cc"], copts = ABSL_TEST_COPTS + ["$(STACK_FRAME_UNLIMITED)"], + linkopts = ABSL_DEFAULT_LINKOPTS, tags = ["benchmark"], deps = [ ":fixed_array", @@ -115,6 +121,7 @@ cc_library( name = "inlined_vector_internal", hdrs = ["internal/inlined_vector.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/meta:type_traits", ], @@ -124,6 +131,7 @@ cc_library( name = "inlined_vector", hdrs = ["inlined_vector.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":inlined_vector_internal", "//absl/algorithm", @@ -138,6 +146,7 @@ cc_library( testonly = 1, hdrs = ["internal/counting_allocator.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = ["//visibility:private"], ) @@ -145,7 +154,7 @@ cc_test( name = "inlined_vector_test", srcs = ["inlined_vector_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":counting_allocator", ":inlined_vector", @@ -164,6 +173,7 @@ cc_test( name = "inlined_vector_test_noexceptions", srcs = ["inlined_vector_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":counting_allocator", ":inlined_vector", @@ -182,6 +192,7 @@ cc_test( name = "inlined_vector_benchmark", srcs = ["inlined_vector_benchmark.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = ["benchmark"], deps = [ ":inlined_vector", @@ -197,6 +208,7 @@ cc_library( srcs = ["internal/test_instance_tracker.cc"], hdrs = ["internal/test_instance_tracker.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl:__subpackages__", ], @@ -206,6 +218,7 @@ cc_test( name = "test_instance_tracker_test", srcs = ["internal/test_instance_tracker_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":test_instance_tracker", "@com_google_googletest//:gtest_main", @@ -230,6 +243,7 @@ cc_library( name = "flat_hash_map", hdrs = ["flat_hash_map.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":container_memory", ":hash_function_defaults", @@ -243,6 +257,7 @@ cc_test( name = "flat_hash_map_test", srcs = ["flat_hash_map_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = NOTEST_TAGS_NONMOBILE, deps = [ ":flat_hash_map", @@ -260,6 +275,7 @@ cc_library( name = "flat_hash_set", hdrs = ["flat_hash_set.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":container_memory", ":hash_function_defaults", @@ -274,6 +290,7 @@ cc_test( name = "flat_hash_set_test", srcs = ["flat_hash_set_test.cc"], copts = ABSL_TEST_COPTS + ["-DUNORDERED_SET_CXX17"], + linkopts = ABSL_DEFAULT_LINKOPTS, tags = NOTEST_TAGS_NONMOBILE, deps = [ ":flat_hash_set", @@ -292,6 +309,7 @@ cc_library( name = "node_hash_map", hdrs = ["node_hash_map.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":container_memory", ":hash_function_defaults", @@ -306,6 +324,7 @@ cc_test( name = "node_hash_map_test", srcs = ["node_hash_map_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = NOTEST_TAGS_NONMOBILE, deps = [ ":hash_generator_testing", @@ -323,6 +342,7 @@ cc_library( name = "node_hash_set", hdrs = ["node_hash_set.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash_function_defaults", ":node_hash_policy", @@ -336,6 +356,7 @@ cc_test( name = "node_hash_set_test", srcs = ["node_hash_set_test.cc"], copts = ABSL_TEST_COPTS + ["-DUNORDERED_SET_CXX17"], + linkopts = ABSL_DEFAULT_LINKOPTS, tags = NOTEST_TAGS_NONMOBILE, deps = [ ":node_hash_set", @@ -351,6 +372,7 @@ cc_library( name = "container_memory", hdrs = ["internal/container_memory.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/memory", "//absl/utility", @@ -361,6 +383,7 @@ cc_test( name = "container_memory_test", srcs = ["internal/container_memory_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = NOTEST_TAGS_NONMOBILE, deps = [ ":container_memory", @@ -373,6 +396,7 @@ cc_library( name = "hash_function_defaults", hdrs = ["internal/hash_function_defaults.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base:config", "//absl/hash", @@ -384,6 +408,7 @@ cc_test( name = "hash_function_defaults_test", srcs = ["internal/hash_function_defaults_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = NOTEST_TAGS, deps = [ ":hash_function_defaults", @@ -399,6 +424,7 @@ cc_library( srcs = ["internal/hash_generator_testing.cc"], hdrs = ["internal/hash_generator_testing.h"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash_policy_testing", "//absl/meta:type_traits", @@ -411,6 +437,7 @@ cc_library( testonly = 1, hdrs = ["internal/hash_policy_testing.h"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/hash", "//absl/strings", @@ -421,6 +448,7 @@ cc_test( name = "hash_policy_testing_test", srcs = ["internal/hash_policy_testing_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash_policy_testing", "@com_google_googletest//:gtest_main", @@ -431,6 +459,7 @@ cc_library( name = "hash_policy_traits", hdrs = ["internal/hash_policy_traits.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = ["//absl/meta:type_traits"], ) @@ -438,6 +467,7 @@ cc_test( name = "hash_policy_traits_test", srcs = ["internal/hash_policy_traits_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash_policy_traits", "@com_google_googletest//:gtest_main", @@ -448,6 +478,7 @@ cc_library( name = "hashtable_debug", hdrs = ["internal/hashtable_debug.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hashtable_debug_hooks", ], @@ -457,6 +488,7 @@ cc_library( name = "hashtable_debug_hooks", hdrs = ["internal/hashtable_debug_hooks.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, ) cc_library( @@ -467,6 +499,7 @@ cc_library( ], hdrs = ["internal/hashtablez_sampler.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":have_sse", "//absl/base", @@ -481,6 +514,7 @@ cc_library( cc_test( name = "hashtablez_sampler_test", srcs = ["internal/hashtablez_sampler_test.cc"], + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hashtablez_sampler", ":have_sse", @@ -496,12 +530,14 @@ cc_library( name = "node_hash_policy", hdrs = ["internal/node_hash_policy.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, ) cc_test( name = "node_hash_policy_test", srcs = ["internal/node_hash_policy_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash_policy_traits", ":node_hash_policy", @@ -513,6 +549,7 @@ cc_library( name = "raw_hash_map", hdrs = ["internal/raw_hash_map.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":container_memory", ":raw_hash_set", @@ -523,6 +560,7 @@ cc_library( name = "have_sse", hdrs = ["internal/have_sse.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = ["//visibility:private"], ) @@ -530,6 +568,7 @@ cc_library( name = "common", hdrs = ["internal/common.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/meta:type_traits", "//absl/types:optional", @@ -541,6 +580,7 @@ cc_library( srcs = ["internal/raw_hash_set.cc"], hdrs = ["internal/raw_hash_set.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":common", ":compressed_tuple", @@ -584,6 +624,7 @@ cc_test( size = "small", srcs = ["internal/raw_hash_set_allocator_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":raw_hash_set", ":tracked", @@ -596,6 +637,7 @@ cc_library( name = "layout", hdrs = ["internal/layout.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base:core_headers", "//absl/meta:type_traits", @@ -610,6 +652,7 @@ cc_test( size = "small", srcs = ["internal/layout_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = NOTEST_TAGS, visibility = ["//visibility:private"], deps = [ @@ -626,6 +669,7 @@ cc_library( testonly = 1, hdrs = ["internal/tracked.h"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, ) cc_library( @@ -633,6 +677,7 @@ cc_library( testonly = 1, hdrs = ["internal/unordered_map_constructor_test.h"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash_generator_testing", ":hash_policy_testing", @@ -645,6 +690,7 @@ cc_library( testonly = 1, hdrs = ["internal/unordered_map_lookup_test.h"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash_generator_testing", ":hash_policy_testing", @@ -657,6 +703,7 @@ cc_library( testonly = 1, hdrs = ["internal/unordered_map_modifiers_test.h"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash_generator_testing", ":hash_policy_testing", @@ -669,6 +716,7 @@ cc_library( testonly = 1, hdrs = ["internal/unordered_set_constructor_test.h"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash_generator_testing", ":hash_policy_testing", @@ -682,6 +730,7 @@ cc_library( testonly = 1, hdrs = ["internal/unordered_set_members_test.h"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/meta:type_traits", "@com_google_googletest//:gtest", @@ -693,6 +742,7 @@ cc_library( testonly = 1, hdrs = ["internal/unordered_map_members_test.h"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/meta:type_traits", "@com_google_googletest//:gtest", @@ -704,6 +754,7 @@ cc_library( testonly = 1, hdrs = ["internal/unordered_set_lookup_test.h"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash_generator_testing", ":hash_policy_testing", @@ -716,6 +767,7 @@ cc_library( testonly = 1, hdrs = ["internal/unordered_set_modifiers_test.h"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash_generator_testing", ":hash_policy_testing", @@ -727,6 +779,7 @@ cc_test( name = "unordered_set_test", srcs = ["internal/unordered_set_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = NOTEST_TAGS_NONMOBILE, deps = [ ":unordered_set_constructor_test", @@ -741,6 +794,7 @@ cc_test( name = "unordered_map_test", srcs = ["internal/unordered_map_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = NOTEST_TAGS_NONMOBILE, deps = [ ":unordered_map_constructor_test", diff --git a/absl/container/inlined_vector.h b/absl/container/inlined_vector.h index 77988058..bd4ed666 100644 --- a/absl/container/inlined_vector.h +++ b/absl/container/inlined_vector.h @@ -454,7 +454,7 @@ class InlinedVector { // Overload of `InlinedVector::operator=()` to replace the contents of the // inlined vector with the contents of `other`. InlinedVector& operator=(const InlinedVector& other) { - if (ABSL_PREDICT_FALSE(this == &other)) return *this; + if (ABSL_PREDICT_FALSE(this == std::addressof(other))) return *this; // Optimized to avoid reallocation. // Prefer reassignment to copy construction for elements. @@ -475,7 +475,7 @@ class InlinedVector { // NOTE: As a result of calling this overload, `other` may be empty or it's // contents may be left in a moved-from state. InlinedVector& operator=(InlinedVector&& other) { - if (ABSL_PREDICT_FALSE(this == &other)) return *this; + if (ABSL_PREDICT_FALSE(this == std::addressof(other))) return *this; if (other.allocated()) { clear(); @@ -840,7 +840,7 @@ class InlinedVector { // // Swaps the contents of this inlined vector with the contents of `other`. void swap(InlinedVector& other) { - if (ABSL_PREDICT_FALSE(this == &other)) return; + if (ABSL_PREDICT_FALSE(this == std::addressof(other))) return; SwapImpl(other); } @@ -864,7 +864,8 @@ class InlinedVector { } void init_allocation(const Allocation& allocation) { - new (&storage_.rep_.allocation_storage.allocation) Allocation(allocation); + new (static_cast(std::addressof( + storage_.rep_.allocation_storage.allocation))) Allocation(allocation); } // TODO(absl-team): investigate whether the reinterpret_cast is appropriate. @@ -1154,7 +1155,7 @@ class InlinedVector { if (!allocated() && !other.allocated()) { // Both inlined: swap up to smaller size, then move remaining elements. InlinedVector* a = this; - InlinedVector* b = &other; + InlinedVector* b = std::addressof(other); if (size() < other.size()) { swap(a, b); } @@ -1186,7 +1187,7 @@ class InlinedVector { // pointer/capacity into the originally inlined vector and swap // the tags. InlinedVector* a = this; - InlinedVector* b = &other; + InlinedVector* b = std::addressof(other); if (a->allocated()) { swap(a, b); } @@ -1305,10 +1306,4 @@ auto AbslHashValue(H h, const InlinedVector& v) -> H { } } // namespace absl -// ----------------------------------------------------------------------------- -// Implementation of InlinedVector -// -// Do not depend on any below implementation details! -// ----------------------------------------------------------------------------- - #endif // ABSL_CONTAINER_INLINED_VECTOR_H_ diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 02fd0bfa..4d94f785 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc @@ -1785,7 +1785,7 @@ TEST(Table, IterationOrderChangesByInstance) { std::vector tables; bool found_difference = false; - for (int i = 0; !found_difference && i < 500; ++i) { + for (int i = 0; !found_difference && i < 5000; ++i) { tables.push_back(MakeSimpleTable(size)); found_difference = OrderOfIteration(tables.back()) != reference; } @@ -1799,7 +1799,7 @@ TEST(Table, IterationOrderChangesByInstance) { TEST(Table, IterationOrderChangesOnRehash) { std::vector garbage; - for (int i = 0; i < 500; ++i) { + for (int i = 0; i < 5000; ++i) { auto t = MakeSimpleTable(20); const auto reference = OrderOfIteration(t); // Force rehash to the same size. diff --git a/absl/copts/AbseilConfigureCopts.cmake b/absl/copts/AbseilConfigureCopts.cmake index 5084958c..b2b3f88d 100644 --- a/absl/copts/AbseilConfigureCopts.cmake +++ b/absl/copts/AbseilConfigureCopts.cmake @@ -3,6 +3,7 @@ include(GENERATED_AbseilCopts) set(ABSL_LSAN_LINKOPTS "") set(ABSL_HAVE_LSAN OFF) +set(ABSL_DEFAULT_LINKOPTS "") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(ABSL_DEFAULT_COPTS "${ABSL_GCC_FLAGS}") @@ -19,6 +20,7 @@ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(ABSL_DEFAULT_COPTS "${ABSL_LLVM_FLAGS}") set(ABSL_TEST_COPTS "${ABSL_LLVM_FLAGS};${ABSL_LLVM_TEST_FLAGS}") set(ABSL_EXCEPTIONS_FLAG "${ABSL_LLVM_EXCEPTIONS_FLAGS}") + set(ABSL_DEFAULT_LINKOPTS "${ABSL_MSVC_LINKOPTS}") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # AppleClang doesn't have lsan # https://developer.apple.com/documentation/code_diagnostics @@ -32,6 +34,7 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") set(ABSL_DEFAULT_COPTS "${ABSL_MSVC_FLAGS}") set(ABSL_TEST_COPTS "${ABSL_MSVC_FLAGS};${ABSL_MSVC_TEST_FLAGS}") set(ABSL_EXCEPTIONS_FLAG "${ABSL_MSVC_EXCEPTIONS_FLAGS}") + set(ABSL_DEFAULT_LINKOPTS "${ABSL_MSVC_LINKOPTS}") else() message(WARNING "Unknown compiler: ${CMAKE_CXX_COMPILER}. Building with no default flags") set(ABSL_DEFAULT_COPTS "") diff --git a/absl/copts/GENERATED_AbseilCopts.cmake b/absl/copts/GENERATED_AbseilCopts.cmake index 9031bfa5..043c88a2 100644 --- a/absl/copts/GENERATED_AbseilCopts.cmake +++ b/absl/copts/GENERATED_AbseilCopts.cmake @@ -201,6 +201,10 @@ list(APPEND ABSL_MSVC_FLAGS "/wd4800" ) +list(APPEND ABSL_MSVC_LINKOPTS + "-ignore:4221" +) + list(APPEND ABSL_MSVC_TEST_FLAGS "/wd4018" "/wd4101" diff --git a/absl/copts/GENERATED_copts.bzl b/absl/copts/GENERATED_copts.bzl index e05a58e3..d40380b8 100644 --- a/absl/copts/GENERATED_copts.bzl +++ b/absl/copts/GENERATED_copts.bzl @@ -202,6 +202,10 @@ ABSL_MSVC_FLAGS = [ "/wd4800", ] +ABSL_MSVC_LINKOPTS = [ + "-ignore:4221", +] + ABSL_MSVC_TEST_FLAGS = [ "/wd4018", "/wd4101", diff --git a/absl/copts/configure_copts.bzl b/absl/copts/configure_copts.bzl index 1655addd..00159317 100644 --- a/absl/copts/configure_copts.bzl +++ b/absl/copts/configure_copts.bzl @@ -14,6 +14,7 @@ load( "ABSL_LLVM_TEST_FLAGS", "ABSL_MSVC_EXCEPTIONS_FLAGS", "ABSL_MSVC_FLAGS", + "ABSL_MSVC_LINKOPTS", "ABSL_MSVC_TEST_FLAGS", ) @@ -40,3 +41,8 @@ ABSL_EXCEPTIONS_FLAG = select({ ABSL_EXCEPTIONS_FLAG_LINKOPTS = select({ "//conditions:default": [], }) + +ABSL_DEFAULT_LINKOPTS = select({ + "//absl:windows": ABSL_MSVC_LINKOPTS, + "//conditions:default": [], +}) diff --git a/absl/copts/copts.py b/absl/copts/copts.py index 3c9d4294..608d7c0e 100644 --- a/absl/copts/copts.py +++ b/absl/copts/copts.py @@ -153,26 +153,39 @@ COPT_VARS = { "-Wno-unused-private-field", ], "ABSL_GCC_EXCEPTIONS_FLAGS": ["-fexceptions"], - "ABSL_LLVM_FLAGS": LLVM_BIG_WARNING_FLAGS + LLVM_DISABLE_WARNINGS_FLAGS, - "ABSL_LLVM_TEST_FLAGS": LLVM_TEST_DISABLE_WARNINGS_FLAGS, + "ABSL_LLVM_FLAGS": + LLVM_BIG_WARNING_FLAGS + LLVM_DISABLE_WARNINGS_FLAGS, + "ABSL_LLVM_TEST_FLAGS": + LLVM_TEST_DISABLE_WARNINGS_FLAGS, "ABSL_LLVM_EXCEPTIONS_FLAGS": ["-fexceptions"], - "ABSL_CLANG_CL_FLAGS": (MSVC_BIG_WARNING_FLAGS + - LLVM_DISABLE_WARNINGS_FLAGS + MSVC_DEFINES), - "ABSL_CLANG_CL_TEST_FLAGS": LLVM_TEST_DISABLE_WARNINGS_FLAGS, - "ABSL_CLANG_CL_EXCEPTIONS_FLAGS": MSVC_STYLE_EXCEPTIONS_FLAGS, - "ABSL_MSVC_FLAGS": MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + [ - "/wd4005", # macro-redefinition - "/wd4068", # unknown pragma - "/wd4180", # qualifier applied to function type has no meaning; ignored - "/wd4244", # conversion from 'type1' to 'type2', possible loss of data - "/wd4267", # conversion from 'size_t' to 'type', possible loss of data - # forcing value to bool 'true' or 'false' (performance warning) - "/wd4800", - ], + "ABSL_CLANG_CL_FLAGS": ( + MSVC_BIG_WARNING_FLAGS + LLVM_DISABLE_WARNINGS_FLAGS + MSVC_DEFINES), + "ABSL_CLANG_CL_TEST_FLAGS": + LLVM_TEST_DISABLE_WARNINGS_FLAGS, + "ABSL_CLANG_CL_EXCEPTIONS_FLAGS": + MSVC_STYLE_EXCEPTIONS_FLAGS, + "ABSL_MSVC_FLAGS": + MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + [ + "/wd4005", # macro-redefinition + "/wd4068", # unknown pragma + # qualifier applied to function type has no meaning; ignored + "/wd4180", + # conversion from 'type1' to 'type2', possible loss of data + "/wd4244", + # conversion from 'size_t' to 'type', possible loss of data + "/wd4267", + # forcing value to bool 'true' or 'false' (performance warning) + "/wd4800", + ], "ABSL_MSVC_TEST_FLAGS": [ "/wd4018", # signed/unsigned mismatch "/wd4101", # unreferenced local variable "/wd4503", # decorated name length exceeded, name was truncated ], - "ABSL_MSVC_EXCEPTIONS_FLAGS": MSVC_STYLE_EXCEPTIONS_FLAGS, + "ABSL_MSVC_EXCEPTIONS_FLAGS": + MSVC_STYLE_EXCEPTIONS_FLAGS, + "ABSL_MSVC_LINKOPTS": [ + # Object file doesn't export any previously undefined symbols + "/ignore:4221", + ], } diff --git a/absl/debugging/BUILD.bazel b/absl/debugging/BUILD.bazel index c9184f92..0854314e 100644 --- a/absl/debugging/BUILD.bazel +++ b/absl/debugging/BUILD.bazel @@ -17,6 +17,7 @@ load( "//absl:copts/configure_copts.bzl", "ABSL_DEFAULT_COPTS", + "ABSL_DEFAULT_LINKOPTS", "ABSL_TEST_COPTS", ) @@ -33,6 +34,7 @@ cc_library( ], hdrs = ["stacktrace.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":debugging_internal", "//absl/base", @@ -53,6 +55,7 @@ cc_library( "symbolize.h", ], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":debugging_internal", ":demangle_internal", @@ -66,6 +69,7 @@ cc_test( name = "symbolize_test", srcs = ["symbolize_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":stack_consumption", ":symbolize", @@ -85,6 +89,7 @@ cc_library( "internal/examine_stack.h", ], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = ["//visibility:private"], deps = [ ":stacktrace", @@ -99,6 +104,7 @@ cc_library( srcs = ["failure_signal_handler.cc"], hdrs = ["failure_signal_handler.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":examine_stack", ":stacktrace", @@ -115,7 +121,7 @@ cc_test( linkopts = select({ "//absl:windows": [], "//conditions:default": ["-pthread"], - }), + }) + ABSL_DEFAULT_LINKOPTS, deps = [ ":failure_signal_handler", ":stacktrace", @@ -147,6 +153,7 @@ cc_library( "internal/vdso_support.h", ], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base", "//absl/base:core_headers", @@ -169,6 +176,7 @@ cc_test( name = "demangle_test", srcs = ["internal/demangle_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":demangle_internal", ":stack_consumption", @@ -183,6 +191,7 @@ cc_library( name = "leak_check", srcs = ["leak_check.cc"], hdrs = ["leak_check.h"], + linkopts = ABSL_DEFAULT_LINKOPTS, deps = ["//absl/base:core_headers"], ) @@ -192,6 +201,7 @@ cc_library( cc_library( name = "leak_check_disable", srcs = ["leak_check_disable.cc"], + linkopts = ABSL_DEFAULT_LINKOPTS, linkstatic = 1, alwayslink = 1, ) @@ -212,6 +222,7 @@ cc_library( "//absl:llvm_compiler": ["-DLEAK_SANITIZER"], "//conditions:default": [], }), + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = ["//visibility:private"], ) @@ -221,6 +232,7 @@ cc_library( srcs = ["leak_check.cc"], hdrs = ["leak_check.h"], copts = ["-ULEAK_SANITIZER"], + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = ["//visibility:private"], ) @@ -231,7 +243,7 @@ cc_test( "//absl:llvm_compiler": ["-DABSL_EXPECT_LEAK_SANITIZER"], "//conditions:default": [], }), - linkopts = ABSL_LSAN_LINKOPTS, + linkopts = ABSL_LSAN_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":leak_check_api_enabled_for_testing", "//absl/base", @@ -243,6 +255,7 @@ cc_test( name = "leak_check_no_lsan_test", srcs = ["leak_check_test.cc"], copts = ["-UABSL_EXPECT_LEAK_SANITIZER"], + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":leak_check_api_disabled_for_testing", "//absl/base", # for raw_logging @@ -257,7 +270,7 @@ cc_test( cc_test( name = "disabled_leak_check_test", srcs = ["leak_check_fail_test.cc"], - linkopts = ABSL_LSAN_LINKOPTS, + linkopts = ABSL_LSAN_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":leak_check_api_enabled_for_testing", ":leak_check_disable", @@ -272,6 +285,7 @@ cc_library( srcs = ["internal/stack_consumption.cc"], hdrs = ["internal/stack_consumption.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = ["//visibility:private"], deps = [ "//absl/base", @@ -283,6 +297,7 @@ cc_test( name = "stack_consumption_test", srcs = ["internal/stack_consumption_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":stack_consumption", "//absl/base", diff --git a/absl/hash/BUILD.bazel b/absl/hash/BUILD.bazel index 69860d98..8c2daf70 100644 --- a/absl/hash/BUILD.bazel +++ b/absl/hash/BUILD.bazel @@ -17,6 +17,7 @@ load( "//absl:copts/configure_copts.bzl", "ABSL_DEFAULT_COPTS", + "ABSL_DEFAULT_LINKOPTS", "ABSL_TEST_COPTS", ) @@ -32,6 +33,7 @@ cc_library( ], hdrs = ["hash.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":city", "//absl/base:core_headers", @@ -50,6 +52,7 @@ cc_library( name = "hash_testing", testonly = 1, hdrs = ["hash_testing.h"], + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":spy_hash_state", "//absl/meta:type_traits", @@ -63,6 +66,7 @@ cc_test( name = "hash_test", srcs = ["hash_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash", ":hash_testing", @@ -80,6 +84,7 @@ cc_library( testonly = 1, hdrs = ["internal/spy_hash_state.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = ["//visibility:private"], deps = [ ":hash", @@ -95,6 +100,7 @@ cc_library( "internal/city.h", ], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base:config", "//absl/base:core_headers", @@ -106,6 +112,7 @@ cc_test( name = "city_test", srcs = ["internal/city_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":city", "@com_google_googletest//:gtest_main", diff --git a/absl/memory/BUILD.bazel b/absl/memory/BUILD.bazel index 7c6366fe..f815ef94 100644 --- a/absl/memory/BUILD.bazel +++ b/absl/memory/BUILD.bazel @@ -17,6 +17,7 @@ load( "//absl:copts/configure_copts.bzl", "ABSL_DEFAULT_COPTS", + "ABSL_DEFAULT_LINKOPTS", "ABSL_TEST_COPTS", "ABSL_EXCEPTIONS_FLAG", "ABSL_EXCEPTIONS_FLAG_LINKOPTS", @@ -30,6 +31,7 @@ cc_library( name = "memory", hdrs = ["memory.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base:core_headers", "//absl/meta:type_traits", @@ -40,6 +42,7 @@ cc_test( name = "memory_test", srcs = ["memory_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":memory", "//absl/base", @@ -54,7 +57,7 @@ cc_test( "memory_exception_safety_test.cc", ], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":memory", "//absl/base:exception_safety_testing", diff --git a/absl/meta/BUILD.bazel b/absl/meta/BUILD.bazel index 1c39fa98..c2435f4f 100644 --- a/absl/meta/BUILD.bazel +++ b/absl/meta/BUILD.bazel @@ -1,6 +1,7 @@ load( "//absl:copts/configure_copts.bzl", "ABSL_DEFAULT_COPTS", + "ABSL_DEFAULT_LINKOPTS", "ABSL_TEST_COPTS", ) @@ -12,6 +13,7 @@ cc_library( name = "type_traits", hdrs = ["type_traits.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base:config", ], @@ -21,6 +23,7 @@ cc_test( name = "type_traits_test", srcs = ["type_traits_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":type_traits", "//absl/base:core_headers", diff --git a/absl/numeric/BUILD.bazel b/absl/numeric/BUILD.bazel index 7cd7ee19..d9b561df 100644 --- a/absl/numeric/BUILD.bazel +++ b/absl/numeric/BUILD.bazel @@ -15,6 +15,7 @@ load( "//absl:copts/configure_copts.bzl", "ABSL_DEFAULT_COPTS", + "ABSL_DEFAULT_LINKOPTS", "ABSL_TEST_COPTS", ) @@ -31,6 +32,7 @@ cc_library( ], hdrs = ["int128.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base:config", "//absl/base:core_headers", @@ -45,6 +47,7 @@ cc_test( "int128_test.cc", ], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":int128", "//absl/base", @@ -59,6 +62,7 @@ cc_test( name = "int128_benchmark", srcs = ["int128_benchmark.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = ["benchmark"], deps = [ ":int128", diff --git a/absl/synchronization/BUILD.bazel b/absl/synchronization/BUILD.bazel index 5e69847e..67da9d46 100644 --- a/absl/synchronization/BUILD.bazel +++ b/absl/synchronization/BUILD.bazel @@ -17,6 +17,7 @@ load( "//absl:copts/configure_copts.bzl", "ABSL_DEFAULT_COPTS", + "ABSL_DEFAULT_LINKOPTS", "ABSL_TEST_COPTS", ) @@ -34,6 +35,7 @@ cc_library( "internal/graphcycles.h", ], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl:__subpackages__", ], @@ -72,7 +74,7 @@ cc_library( linkopts = select({ "//absl:windows": [], "//conditions:default": ["-pthread"], - }), + }) + ABSL_DEFAULT_LINKOPTS, deps = [ ":graphcycles_internal", "//absl/base", @@ -92,9 +94,7 @@ cc_test( size = "small", srcs = ["barrier_test.cc"], copts = ABSL_TEST_COPTS, - tags = [ - "no_test_wasm", - ], + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":synchronization", "//absl/time", @@ -107,9 +107,7 @@ cc_test( size = "small", srcs = ["blocking_counter_test.cc"], copts = ABSL_TEST_COPTS, - tags = [ - "no_test_wasm", - ], + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":synchronization", "//absl/time", @@ -122,6 +120,7 @@ cc_test( size = "medium", srcs = ["internal/graphcycles_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":graphcycles_internal", "//absl/base", @@ -134,6 +133,7 @@ cc_test( name = "graphcycles_benchmark", srcs = ["internal/graphcycles_benchmark.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = [ "benchmark", ], @@ -148,6 +148,7 @@ cc_library( name = "thread_pool", testonly = 1, hdrs = ["internal/thread_pool.h"], + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl:__subpackages__", ], @@ -162,6 +163,7 @@ cc_test( size = "large", srcs = ["mutex_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, shard_count = 25, deps = [ ":synchronization", @@ -179,6 +181,7 @@ cc_library( testonly = 1, srcs = ["mutex_benchmark.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl/synchronization:__pkg__", ], @@ -195,6 +198,7 @@ cc_binary( name = "mutex_benchmark", testonly = 1, copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = ["//visibility:private"], deps = [ ":mutex_benchmark_common", @@ -206,6 +210,7 @@ cc_test( size = "small", srcs = ["notification_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":synchronization", "//absl/time", @@ -218,6 +223,7 @@ cc_library( testonly = 1, srcs = ["internal/per_thread_sem_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":synchronization", "//absl/base", @@ -232,7 +238,7 @@ cc_test( name = "per_thread_sem_test", size = "medium", copts = ABSL_TEST_COPTS, - tags = ["no_test_wasm"], + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":per_thread_sem_test_common", ":synchronization", @@ -249,6 +255,7 @@ cc_test( "lifetime_test.cc", ], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = ["no_test_ios_x86_64"], deps = [ ":synchronization", diff --git a/absl/time/BUILD.bazel b/absl/time/BUILD.bazel index a94be655..55e83a8c 100644 --- a/absl/time/BUILD.bazel +++ b/absl/time/BUILD.bazel @@ -17,6 +17,7 @@ load( "//absl:copts/configure_copts.bzl", "ABSL_DEFAULT_COPTS", + "ABSL_DEFAULT_LINKOPTS", "ABSL_TEST_COPTS", ) @@ -41,6 +42,7 @@ cc_library( "time.h", ], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base", "//absl/base:core_headers", @@ -60,6 +62,7 @@ cc_library( ], hdrs = ["internal/test_util.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl/time:__pkg__", ], @@ -82,6 +85,7 @@ cc_test( "time_zone_test.cc", ], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":test_util", ":time", @@ -103,6 +107,7 @@ cc_test( "time_benchmark.cc", ], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = [ "benchmark", ], diff --git a/absl/time/internal/cctz/BUILD.bazel b/absl/time/internal/cctz/BUILD.bazel index 903499be..05f56bca 100644 --- a/absl/time/internal/cctz/BUILD.bazel +++ b/absl/time/internal/cctz/BUILD.bazel @@ -87,7 +87,6 @@ cc_test( "no_test_android_arm", "no_test_android_arm64", "no_test_android_x86", - "no_test_wasm", ], deps = [ ":civil_time", @@ -106,7 +105,6 @@ cc_test( "no_test_android_arm", "no_test_android_arm64", "no_test_android_x86", - "no_test_wasm", ], deps = [ ":civil_time", diff --git a/absl/types/BUILD.bazel b/absl/types/BUILD.bazel index 7da00030..a62522e4 100644 --- a/absl/types/BUILD.bazel +++ b/absl/types/BUILD.bazel @@ -17,6 +17,7 @@ load( "//absl:copts/configure_copts.bzl", "ABSL_DEFAULT_COPTS", + "ABSL_DEFAULT_LINKOPTS", "ABSL_TEST_COPTS", "ABSL_EXCEPTIONS_FLAG", "ABSL_EXCEPTIONS_FLAG_LINKOPTS", @@ -30,6 +31,7 @@ cc_library( name = "any", hdrs = ["any.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":bad_any_cast", "//absl/base:config", @@ -43,6 +45,7 @@ cc_library( name = "bad_any_cast", hdrs = ["bad_any_cast.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":bad_any_cast_impl", "//absl/base:config", @@ -56,7 +59,7 @@ cc_library( "bad_any_cast.h", ], copts = ABSL_EXCEPTIONS_FLAG + ABSL_DEFAULT_COPTS, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, visibility = ["//visibility:private"], deps = [ "//absl/base", @@ -71,7 +74,7 @@ cc_test( "any_test.cc", ], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":any", "//absl/base", @@ -89,6 +92,7 @@ cc_test( "any_test.cc", ], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":any", "//absl/base", @@ -103,7 +107,7 @@ cc_test( name = "any_exception_safety_test", srcs = ["any_exception_safety_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":any", "//absl/base:exception_safety_testing", @@ -115,6 +119,7 @@ cc_library( name = "span", hdrs = ["span.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/algorithm", "//absl/base:core_headers", @@ -128,7 +133,7 @@ cc_test( size = "small", srcs = ["span_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":span", "//absl/base:config", @@ -147,6 +152,7 @@ cc_test( size = "small", srcs = ["span_test.cc"], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":span", "//absl/base:config", @@ -162,11 +168,12 @@ cc_test( cc_library( name = "optional", - srcs = ["optional.cc"], hdrs = ["optional.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":bad_optional_access", + "//absl/base:base_internal", "//absl/base:config", "//absl/base:core_headers", "//absl/memory", @@ -180,7 +187,7 @@ cc_library( srcs = ["bad_optional_access.cc"], hdrs = ["bad_optional_access.h"], copts = ABSL_DEFAULT_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base", "//absl/base:config", @@ -192,7 +199,7 @@ cc_library( srcs = ["bad_variant_access.cc"], hdrs = ["bad_variant_access.h"], copts = ABSL_EXCEPTIONS_FLAG + ABSL_DEFAULT_COPTS, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base", "//absl/base:config", @@ -206,7 +213,7 @@ cc_test( "optional_test.cc", ], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":optional", "//absl/base", @@ -223,7 +230,7 @@ cc_test( "optional_exception_safety_test.cc", ], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":optional", "//absl/base:exception_safety_testing", @@ -236,6 +243,7 @@ cc_library( srcs = ["internal/variant.h"], hdrs = ["variant.h"], copts = ABSL_DEFAULT_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":bad_variant_access", "//absl/base:base_internal", @@ -251,7 +259,7 @@ cc_test( size = "small", srcs = ["variant_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":variant", "//absl/base:config", @@ -269,6 +277,7 @@ cc_test( "variant_benchmark.cc", ], copts = ABSL_TEST_COPTS, + linkopts = ABSL_DEFAULT_LINKOPTS, tags = ["benchmark"], deps = [ ":variant", @@ -284,7 +293,7 @@ cc_test( "variant_exception_safety_test.cc", ], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, - linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS, deps = [ ":variant", "//absl/base:config", diff --git a/absl/types/CMakeLists.txt b/absl/types/CMakeLists.txt index 8afde466..910c099a 100644 --- a/absl/types/CMakeLists.txt +++ b/absl/types/CMakeLists.txt @@ -172,12 +172,11 @@ absl_cc_library( optional HDRS "optional.h" - SRCS - "optional.cc" COPTS ${ABSL_DEFAULT_COPTS} DEPS absl::bad_optional_access + absl::base_internal absl::config absl::core_headers absl::memory @@ -297,7 +296,8 @@ absl_cc_test( ) # TODO(cohenjon,zhangxy) Figure out why this test is failing on gcc 4.8 -if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9) +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) +else() absl_cc_test( NAME variant_exception_safety_test diff --git a/absl/types/optional.cc b/absl/types/optional.cc deleted file mode 100644 index 44ff8294..00000000 --- a/absl/types/optional.cc +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2017 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/types/optional.h" - -#ifndef ABSL_HAVE_STD_OPTIONAL -namespace absl { - -nullopt_t::init_t nullopt_t::init; -extern const nullopt_t nullopt{nullopt_t::init}; - -} // namespace absl -#endif // ABSL_HAVE_STD_OPTIONAL diff --git a/absl/types/optional.h b/absl/types/optional.h index f0ae9a17..6806160d 100644 --- a/absl/types/optional.h +++ b/absl/types/optional.h @@ -61,6 +61,7 @@ using std::nullopt; #include #include "absl/base/attributes.h" +#include "absl/base/internal/inline_variable.h" #include "absl/meta/type_traits.h" #include "absl/types/bad_optional_access.h" @@ -126,32 +127,30 @@ namespace absl { template class optional; +namespace optional_internal { + +// This tag type is used as a constructor parameter type for `nullopt_t`. +struct init_t { + explicit init_t() = default; +}; + +} // namespace optional_internal + // nullopt_t // // Class type for `absl::nullopt` used to indicate an `absl::optional` type // that does not contain a value. struct nullopt_t { - struct init_t {}; - static init_t init; - // It must not be default-constructible to avoid ambiguity for opt = {}. - // Note the non-const reference, which is to eliminate ambiguity for code - // like: - // - // struct S { int value; }; - // - // void Test() { - // optional opt; - // opt = {{}}; - // } - explicit constexpr nullopt_t(init_t& /*unused*/) {} + explicit constexpr nullopt_t(optional_internal::init_t) noexcept {} }; // nullopt // // A tag constant of type `absl::nullopt_t` used to indicate an empty // `absl::optional` in certain functions, such as construction or assignment. -extern const nullopt_t nullopt; +ABSL_INTERNAL_INLINE_CONSTEXPR(nullopt_t, nullopt, + nullopt_t(optional_internal::init_t())); namespace optional_internal { diff --git a/absl/types/optional_test.cc b/absl/types/optional_test.cc index 0665488e..897c183a 100644 --- a/absl/types/optional_test.cc +++ b/absl/types/optional_test.cc @@ -179,15 +179,7 @@ TEST(optionalTest, DefaultConstructor) { TEST(optionalTest, nulloptConstructor) { absl::optional empty(absl::nullopt); EXPECT_FALSE(empty); - -#ifdef ABSL_HAVE_STD_OPTIONAL constexpr absl::optional cempty{absl::nullopt}; -#else - // Creating a temporary absl::nullopt_t object instead of using absl::nullopt - // because absl::nullopt cannot be constexpr and have external linkage at the - // same time. - constexpr absl::optional cempty{absl::nullopt_t(absl::nullopt_t::init)}; -#endif static_assert(!cempty.has_value(), ""); EXPECT_TRUE((std::is_nothrow_constructible, absl::nullopt_t>::value)); diff --git a/absl/types/span.h b/absl/types/span.h index d7f48d9f..e5c4fe1e 100644 --- a/absl/types/span.h +++ b/absl/types/span.h @@ -73,9 +73,6 @@ namespace absl { -template -class Span; - namespace span_internal { // A constexpr min function constexpr size_t Min(size_t a, size_t b) noexcept { return a < b ? a : b; } @@ -133,14 +130,16 @@ template using EnableIfMutable = typename std::enable_if::value, int>::type; -template -bool EqualImpl(Span a, Span b) { +template