xref: /aosp_15_r20/external/cronet/base/traits_bag_nocompile.nc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1// Copyright 2018 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/traits_bag.h"
9
10namespace base {
11
12enum class RequiredTrait {
13  A,
14  B,
15  C
16};
17
18struct BooleanTrait {};
19
20struct NotAValidTrait {};
21
22struct TestTraits {
23  // List of traits that are valid inputs for the constructor below.
24  struct ValidTrait {
25    ValidTrait(RequiredTrait);
26    ValidTrait(BooleanTrait);
27  };
28
29  template <class... ArgTypes>
30    requires trait_helpers::AreValidTraits<ValidTrait, ArgTypes...>
31  constexpr TestTraits(ArgTypes... args)
32      : required_trait(trait_helpers::GetEnum<RequiredTrait>(args...)),
33        boolean_trait(trait_helpers::HasTrait<BooleanTrait, ArgTypes...>()) {}
34
35  const RequiredTrait required_trait;
36  const bool boolean_trait;
37};
38
39constexpr TestTraits traits = {};  // expected-error {{constexpr variable 'traits' must be initialized by a constant expression}}
40                                   // expected-error@base/traits_bag.h:* {{The traits bag is missing a required trait.}}
41                                   // expected-error@*:* {{no matching constructor for initialization of 'base::trait_helpers::RequiredEnumTraitFilter<base::RequiredTrait>'}}
42
43constexpr TestTraits traits2 = {RequiredTrait::A, NotAValidTrait{}};  // expected-error {{no matching constructor for initialization of 'const TestTraits'}}
44                                                                      // expected-error@*:* {{type occurs more than once in type list}}
45
46constexpr TestTraits traits3 = {RequiredTrait::A, RequiredTrait::B};  // expected-error {{constexpr variable 'traits3' must be initialized by a constant expression}}
47                                                                      // expected-error@base/traits_bag.h:* {{The traits bag contains multiple traits of the same type.}}
48
49constexpr TestTraits traits4 = {RequiredTrait::A, BooleanTrait(),  // expected-error {{constexpr variable 'traits4' must be initialized by a constant expression}}
50                                BooleanTrait()};                   // expected-error@base/traits_bag.h:* {{The traits bag contains multiple traits of the same type.}}
51
52}  // namespace base
53