xref: /aosp_15_r20/external/cronet/base/values_nocompile.nc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker// Copyright 2013 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker// Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker// found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker
5*6777b538SAndroid Build Coastguard Worker// This is a "No Compile Test" suite.
6*6777b538SAndroid Build Coastguard Worker// http://dev.chromium.org/developers/testing/no-compile-tests
7*6777b538SAndroid Build Coastguard Worker
8*6777b538SAndroid Build Coastguard Worker#include "base/values.h"
9*6777b538SAndroid Build Coastguard Worker
10*6777b538SAndroid Build Coastguard Worker#include <stdint.h>
11*6777b538SAndroid Build Coastguard Worker
12*6777b538SAndroid Build Coastguard Workernamespace base {
13*6777b538SAndroid Build Coastguard Worker
14*6777b538SAndroid Build Coastguard Worker// Trying to construct a Value from a pointer should not work or implicitly
15*6777b538SAndroid Build Coastguard Worker// convert to bool.
16*6777b538SAndroid Build Coastguard Workervoid DisallowValueConstructionFromPointers() {
17*6777b538SAndroid Build Coastguard Worker  int* ptr = nullptr;
18*6777b538SAndroid Build Coastguard Worker
19*6777b538SAndroid Build Coastguard Worker  {
20*6777b538SAndroid Build Coastguard Worker    Value v(ptr);  // expected-error {{call to deleted constructor of 'Value'}}
21*6777b538SAndroid Build Coastguard Worker  }
22*6777b538SAndroid Build Coastguard Worker
23*6777b538SAndroid Build Coastguard Worker  {
24*6777b538SAndroid Build Coastguard Worker    Value::Dict dict;
25*6777b538SAndroid Build Coastguard Worker    dict.Set("moo", ptr);  // expected-error {{call to deleted member function 'Set'}}
26*6777b538SAndroid Build Coastguard Worker    dict.SetByDottedPath("moo.moo", ptr);  // expected-error {{call to deleted member function 'SetByDottedPath'}}
27*6777b538SAndroid Build Coastguard Worker
28*6777b538SAndroid Build Coastguard Worker    Value::Dict().Set("moo", ptr);  // expected-error {{call to deleted member function 'Set'}}
29*6777b538SAndroid Build Coastguard Worker    Value::Dict().SetByDottedPath("moo", ptr);  // expected-error {{call to deleted member function 'SetByDottedPath'}}
30*6777b538SAndroid Build Coastguard Worker  }
31*6777b538SAndroid Build Coastguard Worker
32*6777b538SAndroid Build Coastguard Worker  {
33*6777b538SAndroid Build Coastguard Worker    Value::List list;
34*6777b538SAndroid Build Coastguard Worker    list.Append(ptr);  // expected-error {{call to deleted member function 'Append'}}
35*6777b538SAndroid Build Coastguard Worker
36*6777b538SAndroid Build Coastguard Worker    Value::List().Append(ptr);  // expected-error {{call to deleted member function 'Append'}}
37*6777b538SAndroid Build Coastguard Worker  }
38*6777b538SAndroid Build Coastguard Worker}
39*6777b538SAndroid Build Coastguard Worker
40*6777b538SAndroid Build Coastguard Worker// Value (largely) follows the semantics of JSON, which does not support 64-bit
41*6777b538SAndroid Build Coastguard Worker// integers. Constructing a Value from a 64-bit integer should not work.
42*6777b538SAndroid Build Coastguard Worker
43*6777b538SAndroid Build Coastguard Workervoid DisallowValueConstructionFromInt64() {
44*6777b538SAndroid Build Coastguard Worker  int64_t big_int = 0;
45*6777b538SAndroid Build Coastguard Worker
46*6777b538SAndroid Build Coastguard Worker  {
47*6777b538SAndroid Build Coastguard Worker    Value v(big_int);  // expected-error {{call to constructor of 'Value' is ambiguous}}
48*6777b538SAndroid Build Coastguard Worker  }
49*6777b538SAndroid Build Coastguard Worker
50*6777b538SAndroid Build Coastguard Worker  {
51*6777b538SAndroid Build Coastguard Worker    Value::Dict dict;
52*6777b538SAndroid Build Coastguard Worker    dict.Set("あいうえお", big_int);  // expected-error {{call to member function 'Set' is ambiguous}}
53*6777b538SAndroid Build Coastguard Worker    dict.SetByDottedPath("あいうえお", big_int);  // expected-error {{call to member function 'SetByDottedPath' is ambiguous}}
54*6777b538SAndroid Build Coastguard Worker
55*6777b538SAndroid Build Coastguard Worker    Value::Dict().Set("あいうえお", big_int);  // expected-error {{call to member function 'Set' is ambiguous}}
56*6777b538SAndroid Build Coastguard Worker    Value::Dict().SetByDottedPath("あいうえお", big_int);  // expected-error {{call to member function 'SetByDottedPath' is ambiguous}}
57*6777b538SAndroid Build Coastguard Worker  }
58*6777b538SAndroid Build Coastguard Worker
59*6777b538SAndroid Build Coastguard Worker  {
60*6777b538SAndroid Build Coastguard Worker    Value::List list;
61*6777b538SAndroid Build Coastguard Worker    list.Append(big_int);  // expected-error {{call to member function 'Append' is ambiguous}}
62*6777b538SAndroid Build Coastguard Worker
63*6777b538SAndroid Build Coastguard Worker    Value::List().Append(big_int);  // expected-error {{call to member function 'Append' is ambiguous}}
64*6777b538SAndroid Build Coastguard Worker  }
65*6777b538SAndroid Build Coastguard Worker}
66*6777b538SAndroid Build Coastguard Worker
67*6777b538SAndroid Build Coastguard Workervoid TakesValueView(ValueView v) {}
68*6777b538SAndroid Build Coastguard Worker
69*6777b538SAndroid Build Coastguard Worker// Trying to construct a ValueView from a pointer should not work or implicitly
70*6777b538SAndroid Build Coastguard Worker// convert to bool.
71*6777b538SAndroid Build Coastguard Workervoid DisallowValueViewConstructionFromPointers() {
72*6777b538SAndroid Build Coastguard Worker  int* ptr = nullptr;
73*6777b538SAndroid Build Coastguard Worker
74*6777b538SAndroid Build Coastguard Worker  ValueView v(ptr);  // expected-error {{call to deleted constructor of 'ValueView'}}
75*6777b538SAndroid Build Coastguard Worker  TakesValueView(ptr);  // expected-error {{conversion function from 'int *' to 'ValueView' invokes a deleted function}}
76*6777b538SAndroid Build Coastguard Worker}
77*6777b538SAndroid Build Coastguard Worker
78*6777b538SAndroid Build Coastguard Worker// Verify that obvious ways of unsafely constructing a ValueView from a
79*6777b538SAndroid Build Coastguard Worker// temporary are disallowed.
80*6777b538SAndroid Build Coastguard Workervoid DisallowValueViewConstructionFromTemporaryString() {
81*6777b538SAndroid Build Coastguard Worker  [[maybe_unused]] ValueView v = std::string();  // expected-error {{object backing the pointer will be destroyed at the end of the full-expression}}
82*6777b538SAndroid Build Coastguard Worker  // Not an error here since the lifetime of the temporary lasts until the end
83*6777b538SAndroid Build Coastguard Worker  // of the full expression, i.e. until TakesValueView() returns.
84*6777b538SAndroid Build Coastguard Worker  TakesValueView(std::string());
85*6777b538SAndroid Build Coastguard Worker}
86*6777b538SAndroid Build Coastguard Worker
87*6777b538SAndroid Build Coastguard Workervoid DisallowValueViewConstructionFromTemporaryBlob() {
88*6777b538SAndroid Build Coastguard Worker  [[maybe_unused]] ValueView v = Value::BlobStorage();  // expected-error {{object backing the pointer will be destroyed at the end of the full-expression}}
89*6777b538SAndroid Build Coastguard Worker  // Not an error here since the lifetime of the temporary lasts until the end
90*6777b538SAndroid Build Coastguard Worker  // of the full expression, i.e. until TakesValueView() returns.
91*6777b538SAndroid Build Coastguard Worker  TakesValueView(Value::BlobStorage());
92*6777b538SAndroid Build Coastguard Worker}
93*6777b538SAndroid Build Coastguard Worker
94*6777b538SAndroid Build Coastguard Workervoid DisallowValueViewConstructionFromTemporaryDict() {
95*6777b538SAndroid Build Coastguard Worker  [[maybe_unused]] ValueView v = Value::Dict();  // expected-error {{object backing the pointer will be destroyed at the end of the full-expression}}
96*6777b538SAndroid Build Coastguard Worker  // Not an error here since the lifetime of the temporary lasts until the end
97*6777b538SAndroid Build Coastguard Worker  // of the full expression, i.e. until TakesValueView() returns.
98*6777b538SAndroid Build Coastguard Worker  TakesValueView(Value::Dict());
99*6777b538SAndroid Build Coastguard Worker}
100*6777b538SAndroid Build Coastguard Worker
101*6777b538SAndroid Build Coastguard Workervoid DisallowValueViewConstructionFromTemporaryList() {
102*6777b538SAndroid Build Coastguard Worker  [[maybe_unused]] ValueView v = Value::List();  // expected-error {{object backing the pointer will be destroyed at the end of the full-expression}}
103*6777b538SAndroid Build Coastguard Worker  // Not an error here since the lifetime of the temporary lasts until the end
104*6777b538SAndroid Build Coastguard Worker  // of the full expression, i.e. until TakesValueView() returns.
105*6777b538SAndroid Build Coastguard Worker  TakesValueView(Value::List());
106*6777b538SAndroid Build Coastguard Worker}
107*6777b538SAndroid Build Coastguard Worker
108*6777b538SAndroid Build Coastguard Workervoid DisallowValueViewConstructionFromTemporaryValue() {
109*6777b538SAndroid Build Coastguard Worker  [[maybe_unused]] ValueView v = Value();  // expected-error {{object backing the pointer will be destroyed at the end of the full-expression}}
110*6777b538SAndroid Build Coastguard Worker  // Not an error here since the lifetime of the temporary lasts until the end
111*6777b538SAndroid Build Coastguard Worker  // of the full expression, i.e. until TakesValueView() returns.
112*6777b538SAndroid Build Coastguard Worker  TakesValueView(Value());
113*6777b538SAndroid Build Coastguard Worker}
114*6777b538SAndroid Build Coastguard Worker
115*6777b538SAndroid Build Coastguard Worker}  // namespace base
116