1 // Copyright 2013 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.
5 // This is a "No Compile Test" suite.
6 // http://dev.chromium.org/developers/testing/no-compile-tests
8 #include "base/values.h"
14 // Trying to construct a Value from a pointer should not work or implicitly
16 void DisallowValueConstructionFromPointers() {
20 Value v(ptr); // expected-error {{call to deleted constructor of 'Value'}}
25 dict.Set("moo", ptr); // expected-error {{call to deleted member function 'Set'}}
26 dict.SetByDottedPath("moo.moo", ptr); // expected-error {{call to deleted member function 'SetByDottedPath'}}
28 Value::Dict().Set("moo", ptr); // expected-error {{call to deleted member function 'Set'}}
29 Value::Dict().SetByDottedPath("moo", ptr); // expected-error {{call to deleted member function 'SetByDottedPath'}}
34 list.Append(ptr); // expected-error {{call to deleted member function 'Append'}}
36 Value::List().Append(ptr); // expected-error {{call to deleted member function 'Append'}}
40 // Value (largely) follows the semantics of JSON, which does not support 64-bit
41 // integers. Constructing a Value from a 64-bit integer should not work.
43 void DisallowValueConstructionFromInt64() {
47 Value v(big_int); // expected-error {{call to constructor of 'Value' is ambiguous}}
52 dict.Set("あいうえお", big_int); // expected-error {{call to member function 'Set' is ambiguous}}
53 dict.SetByDottedPath("あいうえお", big_int); // expected-error {{call to member function 'SetByDottedPath' is ambiguous}}
55 Value::Dict().Set("あいうえお", big_int); // expected-error {{call to member function 'Set' is ambiguous}}
56 Value::Dict().SetByDottedPath("あいうえお", big_int); // expected-error {{call to member function 'SetByDottedPath' is ambiguous}}
61 list.Append(big_int); // expected-error {{call to member function 'Append' is ambiguous}}
63 Value::List().Append(big_int); // expected-error {{call to member function 'Append' is ambiguous}}
67 void TakesValueView(ValueView v) {}
69 // Trying to construct a ValueView from a pointer should not work or implicitly
71 void DisallowValueViewConstructionFromPointers() {
74 ValueView v(ptr); // expected-error {{call to deleted constructor of 'ValueView'}}
75 TakesValueView(ptr); // expected-error {{conversion function from 'int *' to 'ValueView' invokes a deleted function}}
78 // Verify that obvious ways of unsafely constructing a ValueView from a
79 // temporary are disallowed.
80 void DisallowValueViewConstructionFromTemporaryString() {
81 [[maybe_unused]] ValueView v = std::string(); // expected-error {{object backing the pointer will be destroyed at the end of the full-expression}}
82 // Not an error here since the lifetime of the temporary lasts until the end
83 // of the full expression, i.e. until TakesValueView() returns.
84 TakesValueView(std::string());
87 void DisallowValueViewConstructionFromTemporaryBlob() {
88 [[maybe_unused]] ValueView v = Value::BlobStorage(); // expected-error {{object backing the pointer will be destroyed at the end of the full-expression}}
89 // Not an error here since the lifetime of the temporary lasts until the end
90 // of the full expression, i.e. until TakesValueView() returns.
91 TakesValueView(Value::BlobStorage());
94 void DisallowValueViewConstructionFromTemporaryDict() {
95 [[maybe_unused]] ValueView v = Value::Dict(); // expected-error {{object backing the pointer will be destroyed at the end of the full-expression}}
96 // Not an error here since the lifetime of the temporary lasts until the end
97 // of the full expression, i.e. until TakesValueView() returns.
98 TakesValueView(Value::Dict());
101 void DisallowValueViewConstructionFromTemporaryList() {
102 [[maybe_unused]] ValueView v = Value::List(); // expected-error {{object backing the pointer will be destroyed at the end of the full-expression}}
103 // Not an error here since the lifetime of the temporary lasts until the end
104 // of the full expression, i.e. until TakesValueView() returns.
105 TakesValueView(Value::List());
108 void DisallowValueViewConstructionFromTemporaryValue() {
109 [[maybe_unused]] ValueView v = Value(); // expected-error {{object backing the pointer will be destroyed at the end of the full-expression}}
110 // Not an error here since the lifetime of the temporary lasts until the end
111 // of the full expression, i.e. until TakesValueView() returns.
112 TakesValueView(Value());