no_destructor_unittest.nc 1.3 KB

123456789101112131415161718192021222324252627282930
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // This is a "No Compile Test" suite.
  5. // http://dev.chromium.org/developers/testing/no-compile-tests
  6. #include "base/no_destructor.h"
  7. #include <string>
  8. namespace base {
  9. #if defined(NCTEST_NODESTRUCTOR_REQUIRES_NONTRIVIAL_DESTRUCTOR) // [r"fatal error: static_assert failed due to requirement '!std::is_trivially_destructible<bool>::value || std::is_same<nullptr_t, base::AllowForTriviallyDestructibleType>::value': base::NoDestructor is not needed because the templated class has a trivial destructor"]
  10. // Attempt to make a NoDestructor for a type with a trivial destructor.
  11. void WontCompile() {
  12. NoDestructor<bool> nd;
  13. }
  14. #elif defined(NCTEST_NODESTRUCTOR_PARAMETER) // [r"fatal error: static_assert failed due to requirement 'std::is_same<std::string, base::AllowForTriviallyDestructibleType>::value || std::is_same<std::string, nullptr_t>::value': AllowForTriviallyDestructibleType is the only valid option for the second template parameter of NoDestructor"]
  15. // Attempt to make a NoDestructor for a type with an invalid option.
  16. void WontCompile() {
  17. NoDestructor<std::string, std::string> nd;
  18. }
  19. #endif
  20. } // namespace base