| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7a166a2 commit 4190d70
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -469,7 +469,7 @@ internal::ParamConverterGenerator<T> ConvertGenerator( | |||
| 469 | 469 | ::testing::internal::CodeLocation(__FILE__, __LINE__)); \ | |
| 470 | 470 | return 0; \ | |
| 471 | 471 | } \ | |
| 472 | - static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \ | ||
| 472 | + GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static int gtest_registering_dummy_; \ | ||
| 473 | 473 | }; \ | |
| 474 | 474 | int GTEST_TEST_CLASS_NAME_(test_suite_name, \ | |
| 475 | 475 | test_name)::gtest_registering_dummy_ = \ | |
@@ -514,8 +514,8 @@ internal::ParamConverterGenerator<T> ConvertGenerator( | |||
| 514 | 514 | ::testing::internal::DefaultParamName<test_suite_name::ParamType>, \ | |
| 515 | 515 | DUMMY_PARAM_))))(info); \ | |
| 516 | 516 | } \ | |
| 517 | - static int gtest_##prefix##test_suite_name##_dummy_ \ | ||
| 518 | - GTEST_ATTRIBUTE_UNUSED_ = \ | ||
| 517 | + GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static int \ | ||
| 518 | + gtest_##prefix##test_suite_name##_dummy_ = \ | ||
| 519 | 519 | ::testing::UnitTest::GetInstance() \ | |
| 520 | 520 | ->parameterized_test_registry() \ | |
| 521 | 521 | .GetTestSuitePatternHolder<test_suite_name>( \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -194,33 +194,34 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); | |||
| 194 | 194 | typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \ | |
| 195 | 195 | GTEST_NAME_GENERATOR_(CaseName) | |
| 196 | 196 | ||
| 197 | - #define TYPED_TEST(CaseName, TestName) \ | ||
| 198 | - static_assert(sizeof(GTEST_STRINGIFY_(TestName)) > 1, \ | ||
| 199 | - "test-name must not be empty"); \ | ||
| 200 | - template <typename gtest_TypeParam_> \ | ||
| 201 | - class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \ | ||
| 202 | - : public CaseName<gtest_TypeParam_> { \ | ||
| 203 | - private: \ | ||
| 204 | - typedef CaseName<gtest_TypeParam_> TestFixture; \ | ||
| 205 | - typedef gtest_TypeParam_ TypeParam; \ | ||
| 206 | - void TestBody() override; \ | ||
| 207 | - }; \ | ||
| 208 | - static bool gtest_##CaseName##_##TestName##_registered_ \ | ||
| 209 | - GTEST_ATTRIBUTE_UNUSED_ = ::testing::internal::TypeParameterizedTest< \ | ||
| 210 | - CaseName, \ | ||
| 211 | - ::testing::internal::TemplateSel<GTEST_TEST_CLASS_NAME_(CaseName, \ | ||
| 212 | - TestName)>, \ | ||
| 213 | - GTEST_TYPE_PARAMS_( \ | ||
| 214 | - CaseName)>::Register("", \ | ||
| 215 | - ::testing::internal::CodeLocation( \ | ||
| 216 | - __FILE__, __LINE__), \ | ||
| 217 | - GTEST_STRINGIFY_(CaseName), \ | ||
| 218 | - GTEST_STRINGIFY_(TestName), 0, \ | ||
| 219 | - ::testing::internal::GenerateNames< \ | ||
| 220 | - GTEST_NAME_GENERATOR_(CaseName), \ | ||
| 221 | - GTEST_TYPE_PARAMS_(CaseName)>()); \ | ||
| 222 | - template <typename gtest_TypeParam_> \ | ||
| 223 | - void GTEST_TEST_CLASS_NAME_(CaseName, \ | ||
| 197 | + #define TYPED_TEST(CaseName, TestName) \ | ||
| 198 | + static_assert(sizeof(GTEST_STRINGIFY_(TestName)) > 1, \ | ||
| 199 | + "test-name must not be empty"); \ | ||
| 200 | + template <typename gtest_TypeParam_> \ | ||
| 201 | + class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \ | ||
| 202 | + : public CaseName<gtest_TypeParam_> { \ | ||
| 203 | + private: \ | ||
| 204 | + typedef CaseName<gtest_TypeParam_> TestFixture; \ | ||
| 205 | + typedef gtest_TypeParam_ TypeParam; \ | ||
| 206 | + void TestBody() override; \ | ||
| 207 | + }; \ | ||
| 208 | + GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static bool \ | ||
| 209 | + gtest_##CaseName##_##TestName##_registered_ = \ | ||
| 210 | + ::testing::internal::TypeParameterizedTest< \ | ||
| 211 | + CaseName, \ | ||
| 212 | + ::testing::internal::TemplateSel<GTEST_TEST_CLASS_NAME_( \ | ||
| 213 | + CaseName, TestName)>, \ | ||
| 214 | + GTEST_TYPE_PARAMS_( \ | ||
| 215 | + CaseName)>::Register("", \ | ||
| 216 | + ::testing::internal::CodeLocation( \ | ||
| 217 | + __FILE__, __LINE__), \ | ||
| 218 | + GTEST_STRINGIFY_(CaseName), \ | ||
| 219 | + GTEST_STRINGIFY_(TestName), 0, \ | ||
| 220 | + ::testing::internal::GenerateNames< \ | ||
| 221 | + GTEST_NAME_GENERATOR_(CaseName), \ | ||
| 222 | + GTEST_TYPE_PARAMS_(CaseName)>()); \ | ||
| 223 | + template <typename gtest_TypeParam_> \ | ||
| 224 | + void GTEST_TEST_CLASS_NAME_(CaseName, \ | ||
| 224 | 225 | TestName)<gtest_TypeParam_>::TestBody() | |
| 225 | 226 | ||
| 226 | 227 | // Legacy API is deprecated but still available | |
@@ -267,31 +268,32 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); | |||
| 267 | 268 | TYPED_TEST_SUITE_P | |
| 268 | 269 | #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |
| 269 | 270 | ||
| 270 | - #define TYPED_TEST_P(SuiteName, TestName) \ | ||
| 271 | - namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \ | ||
| 272 | - template <typename gtest_TypeParam_> \ | ||
| 273 | - class TestName : public SuiteName<gtest_TypeParam_> { \ | ||
| 274 | - private: \ | ||
| 275 | - typedef SuiteName<gtest_TypeParam_> TestFixture; \ | ||
| 276 | - typedef gtest_TypeParam_ TypeParam; \ | ||
| 277 | - void TestBody() override; \ | ||
| 278 | - }; \ | ||
| 279 | - static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \ | ||
| 280 | - GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \ | ||
| 281 | - __FILE__, __LINE__, GTEST_STRINGIFY_(SuiteName), \ | ||
| 282 | - GTEST_STRINGIFY_(TestName)); \ | ||
| 283 | - } \ | ||
| 284 | - template <typename gtest_TypeParam_> \ | ||
| 285 | - void GTEST_SUITE_NAMESPACE_( \ | ||
| 271 | + #define TYPED_TEST_P(SuiteName, TestName) \ | ||
| 272 | + namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \ | ||
| 273 | + template <typename gtest_TypeParam_> \ | ||
| 274 | + class TestName : public SuiteName<gtest_TypeParam_> { \ | ||
| 275 | + private: \ | ||
| 276 | + typedef SuiteName<gtest_TypeParam_> TestFixture; \ | ||
| 277 | + typedef gtest_TypeParam_ TypeParam; \ | ||
| 278 | + void TestBody() override; \ | ||
| 279 | + }; \ | ||
| 280 | + GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static bool \ | ||
| 281 | + gtest_##TestName##_defined_ = \ | ||
| 282 | + GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \ | ||
| 283 | + __FILE__, __LINE__, GTEST_STRINGIFY_(SuiteName), \ | ||
| 284 | + GTEST_STRINGIFY_(TestName)); \ | ||
| 285 | + } \ | ||
| 286 | + template <typename gtest_TypeParam_> \ | ||
| 287 | + void GTEST_SUITE_NAMESPACE_( \ | ||
| 286 | 288 | SuiteName)::TestName<gtest_TypeParam_>::TestBody() | |
| 287 | 289 | ||
| 288 | 290 | // Note: this won't work correctly if the trailing arguments are macros. | |
| 289 | 291 | #define REGISTER_TYPED_TEST_SUITE_P(SuiteName, ...) \ | |
| 290 | 292 | namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \ | |
| 291 | 293 | typedef ::testing::internal::Templates<__VA_ARGS__> gtest_AllTests_; \ | |
| 292 | 294 | } \ | |
| 293 | - static const char* const GTEST_REGISTERED_TEST_NAMES_( \ | ||
| 294 | - SuiteName) GTEST_ATTRIBUTE_UNUSED_ = \ | ||
| 295 | + GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static const char* const \ | ||
| 296 | + GTEST_REGISTERED_TEST_NAMES_(SuiteName) = \ | ||
| 295 | 297 | GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).VerifyRegisteredTestNames( \ | |
| 296 | 298 | GTEST_STRINGIFY_(SuiteName), __FILE__, __LINE__, #__VA_ARGS__) | |
| 297 | 299 | ||
@@ -303,22 +305,24 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); | |||
| 303 | 305 | REGISTER_TYPED_TEST_SUITE_P | |
| 304 | 306 | #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |
| 305 | 307 | ||
| 306 | - #define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \ | ||
| 307 | - static_assert(sizeof(GTEST_STRINGIFY_(Prefix)) > 1, \ | ||
| 308 | - "test-suit-prefix must not be empty"); \ | ||
| 309 | - static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \ | ||
| 310 | - ::testing::internal::TypeParameterizedTestSuite< \ | ||
| 311 | - SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \ | ||
| 312 | - ::testing::internal::GenerateTypeList<Types>::type>:: \ | ||
| 313 | - Register(GTEST_STRINGIFY_(Prefix), \ | ||
| 314 | - ::testing::internal::CodeLocation(__FILE__, __LINE__), \ | ||
| 315 | - >EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), \ | ||
| 316 | - GTEST_STRINGIFY_(SuiteName), \ | ||
| 317 | - GTEST_REGISTERED_TEST_NAMES_(SuiteName), \ | ||
| 318 | - ::testing::internal::GenerateNames< \ | ||
| 319 | - ::testing::internal::NameGeneratorSelector< \ | ||
| 320 | - __VA_ARGS__>::type, \ | ||
| 321 | - ::testing::internal::GenerateTypeList<Types>::type>()) | ||
| 308 | + #define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \ | ||
| 309 | + static_assert(sizeof(GTEST_STRINGIFY_(Prefix)) > 1, \ | ||
| 310 | + "test-suit-prefix must not be empty"); \ | ||
| 311 | + GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static bool \ | ||
| 312 | + gtest_##Prefix##_##SuiteName = \ | ||
| 313 | + ::testing::internal::TypeParameterizedTestSuite< \ | ||
| 314 | + SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \ | ||
| 315 | + ::testing::internal::GenerateTypeList<Types>::type>:: \ | ||
| 316 | + Register( \ | ||
| 317 | + GTEST_STRINGIFY_(Prefix), \ | ||
| 318 | + ::testing::internal::CodeLocation(__FILE__, __LINE__), \ | ||
| 319 | + >EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), \ | ||
| 320 | + GTEST_STRINGIFY_(SuiteName), \ | ||
| 321 | + GTEST_REGISTERED_TEST_NAMES_(SuiteName), \ | ||
| 322 | + ::testing::internal::GenerateNames< \ | ||
| 323 | + ::testing::internal::NameGeneratorSelector< \ | ||
| 324 | + __VA_ARGS__>::type, \ | ||
| 325 | + ::testing::internal::GenerateTypeList<Types>::type>()) | ||
| 322 | 326 | ||
| 323 | 327 | // Legacy API is deprecated but still available | |
| 324 | 328 | #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1501,7 +1501,8 @@ class NeverThrown { | |||
| 1501 | 1501 | \ | |
| 1502 | 1502 | private: \ | |
| 1503 | 1503 | void TestBody() override; \ | |
| 1504 | - static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \ | ||
| 1504 | + GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static ::testing::TestInfo* const \ | ||
| 1505 | + test_info_; \ | ||
| 1505 | 1506 | }; \ | |
| 1506 | 1507 | \ | |
| 1507 | 1508 | ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_suite_name, \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -194,8 +194,6 @@ | |||
| 194 | 194 | // | |
| 195 | 195 | // Macros for basic C++ coding: | |
| 196 | 196 | // GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning. | |
| 197 | - // GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances or a | ||
| 198 | - // variable don't have to be used. | ||
| 199 | 197 | // GTEST_MUST_USE_RESULT_ - declares that a function's result must be used. | |
| 200 | 198 | // GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is | |
| 201 | 199 | // suppressed (constant conditional). | |
@@ -749,6 +747,20 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; | |||
| 749 | 747 | #define GTEST_HAVE_ATTRIBUTE_(x) 0 | |
| 750 | 748 | #endif | |
| 751 | 749 | ||
| 750 | + // GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE | ||
| 751 | + // | ||
| 752 | + // A function-like feature checking macro that accepts C++11 style attributes. | ||
| 753 | + // It's a wrapper around `__has_cpp_attribute`, defined by ISO C++ SD-6 | ||
| 754 | + // (https://en.cppreference.com/w/cpp/experimental/feature_test). If we don't | ||
| 755 | + // find `__has_cpp_attribute`, will evaluate to 0. | ||
| 756 | + #if defined(__has_cpp_attribute) | ||
| 757 | + // NOTE: requiring __cplusplus above should not be necessary, but | ||
| 758 | + // works around https://bugs.llvm.org/show_bug.cgi?id=23435. | ||
| 759 | + #define GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) | ||
| 760 | + #else | ||
| 761 | + #define GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(x) 0 | ||
| 762 | + #endif | ||
| 763 | + | ||
| 752 | 764 | // GTEST_HAVE_FEATURE_ | |
| 753 | 765 | // | |
| 754 | 766 | // A function-like feature checking macro that is a wrapper around | |
@@ -760,14 +772,22 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; | |||
| 760 | 772 | #endif | |
| 761 | 773 | ||
| 762 | 774 | // Use this annotation after a variable or parameter declaration to tell the | |
| 763 | - // compiler the variable/parameter does not have to be used. | ||
| 775 | + // compiler the variable/parameter may be used. | ||
| 764 | 776 | // Example: | |
| 765 | 777 | // | |
| 766 | - // GTEST_ATTRIBUTE_UNUSED_ int foo = bar(); | ||
| 767 | - #if GTEST_HAVE_ATTRIBUTE_(unused) | ||
| 768 | - #define GTEST_ATTRIBUTE_UNUSED_ __attribute__((unused)) | ||
| 778 | + // GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED int foo = bar(); | ||
| 779 | + // | ||
| 780 | + // This can be removed once we only support only C++17 or newer and | ||
| 781 | + // [[maybe_unused]] is available on all supported platforms. | ||
| 782 | + #if GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(maybe_unused) | ||
| 783 | + #define GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED [[maybe_unused]] | ||
| 784 | + #elif GTEST_HAVE_ATTRIBUTE_(unused) | ||
| 785 | + // This is inferior to [[maybe_unused]] as it can produce a | ||
| 786 | + // -Wused-but-marked-unused warning on optionally used symbols, but it is all we | ||
| 787 | + // have. | ||
| 788 | + #define GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED __attribute__((__unused__)) | ||
| 769 | 789 | #else | |
| 770 | - #define GTEST_ATTRIBUTE_UNUSED_ | ||
| 790 | + #define GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED | ||
| 771 | 791 | #endif | |
| 772 | 792 | ||
| 773 | 793 | // Use this annotation before a function that takes a printf format string. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments