Hans Wennborg | e5d14a8 | 2019-01-14 11:31:24 | [diff] [blame] | 1 | // Copyright 2018 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 | |
| 5 | // This is a "No Compile Test" suite. |
| 6 | // http://dev.chromium.org/developers/testing/no-compile-tests |
| 7 | |
| 8 | #include <type_traits> |
| 9 | |
| 10 | #include "base/observer_list.h" |
| 11 | |
| 12 | namespace base { |
| 13 | |
| 14 | #if defined(NCTEST_CHECKED_OBSERVER_USING_UNCHECKED_LIST) // [r"fatal error: static_assert failed due to requirement '!std::is_base_of<base::CheckedObserver, Observer>::value' \"CheckedObserver classes must not use ObserverList<T>::Unchecked.\""] |
| 15 | |
| 16 | void WontCompile() { |
| 17 | struct Observer : public CheckedObserver { |
| 18 | void OnObserve() {} |
| 19 | }; |
| 20 | ObserverList<Observer>::Unchecked list; |
| 21 | for (auto& observer: list) |
| 22 | observer.OnObserve(); |
| 23 | } |
| 24 | |
| 25 | #elif defined(NCTEST_UNCHECKED_OBSERVER_USING_CHECKED_LIST) // [r"fatal error: static_assert failed due to requirement 'std::is_base_of<base::CheckedObserver, UncheckedObserver>::value' \"Observers should inherit from base::CheckedObserver. Use ObserverList<T>::Unchecked to observe with raw pointers.\""] |
| 26 | |
| 27 | void WontCompile() { |
| 28 | struct UncheckedObserver { |
| 29 | void OnObserve() {} |
| 30 | }; |
| 31 | ObserverList<UncheckedObserver> list; |
| 32 | for (auto& observer: list) |
| 33 | observer.OnObserve(); |
| 34 | } |
| 35 | |
| 36 | #endif |
| 37 | |
| 38 | } // namespace base |