1// Copyright 2021 The Chromium Authors 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// This is a "No Compile Test" suite. 6// http://dev.chromium.org/developers/testing/no-compile-tests 7 8#include "base/no_destructor.h" 9 10namespace base { 11 12void WontCompileWithTrivialTypes() { 13 // NoDestructor should not be used with trivial types; trivial types can 14 // simply be directly declared as globals. 15 static NoDestructor<bool> x; // expected-error@*:* {{static assertion failed due to requirement '!(std::is_trivially_constructible_v<bool> && std::is_trivially_destructible_v<bool>)'}} 16} 17 18struct TypeWithUserConstructor { 19 TypeWithUserConstructor() {} 20}; 21 22void WontCompileWithTriviallyDestructibleTypes() { 23 // NoDestructor should only be used for non-trivially destructible types; 24 // they should be declared as function-level statics instead. 25 static NoDestructor<TypeWithUserConstructor> x; // expected-error@*:* {{static assertion failed due to requirement '!std::is_trivially_destructible_v<base::TypeWithUserConstructor>'}} 26} 27 28} // namespace base 29