Skip to content

Commit

Permalink
Export of internal Abseil changes
Browse files Browse the repository at this point in the history
--
c385118b3ef0528d150bfe7aeeb63e77f9e463cd by Matt Calabrese <calabrese@google.com>:

Internal-only Archetype generation for testing generic code with user-defined types of various properties.

PiperOrigin-RevId: 283833099

--
4ccf340d3b295aa5b796ee5c97128b61d38899ea by Derek Mauro <dmauro@google.com>:

Fixes the flags parse_test.
Windows doesn't like consecutive path separators.

PiperOrigin-RevId: 283614649

--
5df6d83acb1e49cd1da785cfaf7551f05149f3c9 by Andy Getzendanner <durandal@google.com>:

ABSL_INTERNAL_LOG: forward complete __FILE__ to internal_log_function; not just basename.

PiperOrigin-RevId: 283406080
GitOrigin-RevId: c385118b3ef0528d150bfe7aeeb63e77f9e463cd
Change-Id: Ib0782354691a73fc40185c3262cfd507085b3393
  • Loading branch information
Abseil Team authored and mbxx committed Dec 5, 2019
1 parent a4b757b commit d659fe5
Show file tree
Hide file tree
Showing 10 changed files with 3,112 additions and 43 deletions.
12 changes: 4 additions & 8 deletions absl/base/internal/raw_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,10 @@
//
// The API is a subset of the above: each macro only takes two arguments. Use
// StrCat if you need to build a richer message.
#define ABSL_INTERNAL_LOG(severity, message) \
do { \
constexpr const char* absl_raw_logging_internal_basename = \
::absl::raw_logging_internal::Basename(__FILE__, \
sizeof(__FILE__) - 1); \
::absl::raw_logging_internal::internal_log_function( \
ABSL_RAW_LOGGING_INTERNAL_##severity, \
absl_raw_logging_internal_basename, __LINE__, message); \
#define ABSL_INTERNAL_LOG(severity, message) \
do { \
::absl::raw_logging_internal::internal_log_function( \
ABSL_RAW_LOGGING_INTERNAL_##severity, __FILE__, __LINE__, message); \
} while (0)

#define ABSL_INTERNAL_CHECK(condition, message) \
Expand Down
16 changes: 10 additions & 6 deletions absl/flags/parse_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "absl/base/internal/raw_logging.h"
#include "absl/base/internal/scoped_set_env.h"
#include "absl/flags/flag.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/substitute.h"
#include "absl/types/span.h"
Expand Down Expand Up @@ -92,8 +93,11 @@ const std::string& GetTestTempDir() {

auto len = GetTempPathA(MAX_PATH, temp_path_buffer);
if (len < MAX_PATH && len != 0) {
std::string temp_dir_name = absl::StrCat(
temp_path_buffer, "\\parse_test.", GetCurrentProcessId());
std::string temp_dir_name = temp_path_buffer;
if (!absl::EndsWith(temp_dir_name, "\\")) {
temp_dir_name.push_back('\\');
}
absl::StrAppend(&temp_dir_name, "parse_test.", GetCurrentProcessId());
if (CreateDirectoryA(temp_dir_name.c_str(), nullptr)) {
*res = temp_dir_name;
}
Expand All @@ -104,11 +108,11 @@ const std::string& GetTestTempDir() {
*res = unique_name;
}
#endif
}

if (res->empty()) {
ABSL_INTERNAL_LOG(FATAL,
"Failed to make temporary directory for data files");
}
if (res->empty()) {
ABSL_INTERNAL_LOG(FATAL,
"Failed to make temporary directory for data files");
}

#ifdef _WIN32
Expand Down
45 changes: 37 additions & 8 deletions absl/meta/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,18 @@

#include "absl/base/config.h"

// MSVC constructibility traits do not detect destructor properties and so our
// implementations should not use them as a source-of-truth.
#if defined(_MSC_VER) && !defined(__clang__) && !defined(__GNUC__)
#define ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION 1
#endif

namespace absl {

// Defined and documented later on in this file.
template <typename T>
struct is_trivially_destructible;

// Defined and documented later on in this file.
template <typename T>
struct is_trivially_move_assignable;
Expand All @@ -65,6 +75,20 @@ union SingleMemberUnion {
#pragma warning(pop)
#endif // defined(_MSC_VER) && !defined(__GNUC__)

template <class T>
struct IsTriviallyMoveConstructibleObject
: std::integral_constant<
bool, std::is_move_constructible<
type_traits_internal::SingleMemberUnion<T>>::value &&
absl::is_trivially_destructible<T>::value> {};

template <class T>
struct IsTriviallyCopyConstructibleObject
: std::integral_constant<
bool, std::is_copy_constructible<
type_traits_internal::SingleMemberUnion<T>>::value &&
absl::is_trivially_destructible<T>::value> {};

template <class T>
struct IsTriviallyMoveAssignableReference : std::false_type {};

Expand Down Expand Up @@ -323,7 +347,9 @@ struct is_trivially_default_constructible
: std::integral_constant<bool, __has_trivial_constructor(T) &&
std::is_default_constructible<T>::value &&
is_trivially_destructible<T>::value> {
#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \
!defined( \
ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION)
private:
static constexpr bool compliant =
std::is_trivially_default_constructible<T>::value ==
Expand Down Expand Up @@ -354,10 +380,11 @@ template <typename T>
struct is_trivially_move_constructible
: std::conditional<
std::is_object<T>::value && !std::is_array<T>::value,
std::is_move_constructible<
type_traits_internal::SingleMemberUnion<T>>,
type_traits_internal::IsTriviallyMoveConstructibleObject<T>,
std::is_reference<T>>::type::type {
#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \
!defined( \
ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION)
private:
static constexpr bool compliant =
std::is_trivially_move_constructible<T>::value ==
Expand Down Expand Up @@ -388,10 +415,11 @@ template <typename T>
struct is_trivially_copy_constructible
: std::conditional<
std::is_object<T>::value && !std::is_array<T>::value,
std::is_copy_constructible<
type_traits_internal::SingleMemberUnion<T>>,
type_traits_internal::IsTriviallyCopyConstructibleObject<T>,
std::is_lvalue_reference<T>>::type::type {
#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \
!defined( \
ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION)
private:
static constexpr bool compliant =
std::is_trivially_copy_constructible<T>::value ==
Expand Down Expand Up @@ -423,7 +451,8 @@ struct is_trivially_copy_constructible
template <typename T>
struct is_trivially_move_assignable
: std::conditional<
std::is_object<T>::value && !std::is_array<T>::value,
std::is_object<T>::value && !std::is_array<T>::value &&
std::is_move_assignable<T>::value,
std::is_move_assignable<type_traits_internal::SingleMemberUnion<T>>,
type_traits_internal::IsTriviallyMoveAssignableReference<T>>::type::
type {
Expand Down
21 changes: 0 additions & 21 deletions absl/meta/type_traits_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,21 +347,6 @@ class Base {
virtual ~Base() {}
};

// In GCC/Clang, std::is_trivially_constructible requires that the destructor is
// trivial. However, MSVC doesn't require that. This results in different
// behavior when checking is_trivially_constructible on any type with
// nontrivial destructor. Since absl::is_trivially_default_constructible and
// absl::is_trivially_copy_constructible both follows Clang/GCC's interpretation
// and check is_trivially_destructible, it results in inconsistency with
// std::is_trivially_xxx_constructible on MSVC. This macro is used to work
// around this issue in test. In practice, a trivially constructible type
// should also be trivially destructible.
// GCC bug 51452: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51452
// LWG issue 2116: http://cplusplus.github.io/LWG/lwg-active.html#2116
#ifndef _MSC_VER
#define ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE 1
#endif

// Old versions of libc++, around Clang 3.5 to 3.6, consider deleted destructors
// as also being trivial. With the resolution of CWG 1928 and CWG 1734, this
// is no longer considered true and has thus been amended.
Expand Down Expand Up @@ -499,11 +484,9 @@ TEST(TypeTraitsTest, TestTrivialDefaultCtor) {
EXPECT_FALSE(
absl::is_trivially_default_constructible<DeletedDefaultCtor>::value);

#ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE
// types with nontrivial destructor are nontrivial
EXPECT_FALSE(
absl::is_trivially_default_constructible<NontrivialDestructor>::value);
#endif

// types with vtables
EXPECT_FALSE(absl::is_trivially_default_constructible<Base>::value);
Expand Down Expand Up @@ -607,11 +590,9 @@ TEST(TypeTraitsTest, TestTrivialMoveCtor) {
EXPECT_FALSE(
absl::is_trivially_move_constructible<NonCopyableOrMovable>::value);

#ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE
// type with nontrivial destructor are nontrivial move construbtible
EXPECT_FALSE(
absl::is_trivially_move_constructible<NontrivialDestructor>::value);
#endif

// types with vtables
EXPECT_FALSE(absl::is_trivially_move_constructible<Base>::value);
Expand Down Expand Up @@ -682,11 +663,9 @@ TEST(TypeTraitsTest, TestTrivialCopyCtor) {
EXPECT_FALSE(
absl::is_trivially_copy_constructible<NonCopyableOrMovable>::value);

#ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE
// type with nontrivial destructor are nontrivial copy construbtible
EXPECT_FALSE(
absl::is_trivially_copy_constructible<NontrivialDestructor>::value);
#endif

// types with vtables
EXPECT_FALSE(absl::is_trivially_copy_constructible<Base>::value);
Expand Down
34 changes: 34 additions & 0 deletions absl/types/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,40 @@ cc_test(
],
)

cc_library(
name = "conformance_testing",
testonly = 1,
hdrs = [
"internal/conformance_aliases.h",
"internal/conformance_archetype.h",
"internal/conformance_profile.h",
],
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
"//absl/debugging:demangle_internal",
"//absl/meta:type_traits",
"//absl/strings",
"//absl/utility",
"@com_google_googletest//:gtest",
],
)

cc_test(
name = "conformance_testing_test",
size = "small",
srcs = [
"internal/conformance_testing_test.cc",
],
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":conformance_testing",
"//absl/meta:type_traits",
"@com_google_googletest//:gtest_main",
],
)

cc_library(
name = "variant",
srcs = ["internal/variant.h"],
Expand Down
46 changes: 46 additions & 0 deletions absl/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,52 @@ absl_cc_test(
gmock_main
)

absl_cc_library(
NAME
conformance_testing
HDRS
"internal/conformance_aliases.h"
"internal/conformance_archetype.h"
"internal/conformance_profile.h"
COPTS
${ABSL_DEFAULT_COPTS}
DEPS
absl::debugging
absl::type_traits
absl::strings
absl::utility
gmock_main
PUBLIC
)

absl_cc_test(
NAME
conformance_testing_test
SRCS
"internal/conformance_testing_test.cc"
COPTS
${ABSL_TEST_COPTS}
${ABSL_EXCEPTIONS_FLAG}
LINKOPTS
${ABSL_EXCEPTIONS_FLAG_LINKOPTS}
DEPS
absl::conformance_testing
absl::type_traits
gmock_main
)

absl_cc_test(
NAME
conformance_testing_test_no_exceptions
SRCS
"internal/conformance_testing_test.cc"
COPTS
${ABSL_TEST_COPTS}
DEPS
absl::conformance_testing
gmock_main
)

absl_cc_library(
NAME
variant
Expand Down
Loading

0 comments on commit d659fe5

Please sign in to comment.