Skip to content

Commit c827bf4

Browse files
rsgowmanwilhuff
authored andcommitted
Fix a number of c++ build errors (firebase#715)
* Move -fvisibility-inlines-hidden from common_flags to cxx_flags This option isn't supported by C (and causes the build to fail under at least rodete). Manifested error was: ``` -- Looking for include file openssl/rand.h -- Looking for include file openssl/rand.h - not found CMake Error at core/src/firebase/firestore/util/CMakeLists.txt:94 (message): No implementation for SecureRandom available. -- Configuring incomplete, errors occurred! ``` which is completely misleading. :( * Fix exception include for std::logic_error Was causing compiler error on (at least) rodete. (http://en.cppreference.com/w/cpp/error/logic_error suggests that stdexcept is the correct header.) * Remove 'const' from vector contents. vectors cannot contain const objects as the contained objects are required to be assignable and copy constructable. (Not *quite* strictly true; since c++11, this requirement now depends on the operations performed on the container. But my compiler objects at any rate.) http://en.cppreference.com/w/cpp/container/vector https://stackoverflow.com/questions/8685257/why-cant-you-put-a-const-object-into-a-stl-container * Add brackets as suggested (required) by my compiler. * Add missing include For LLONG_MIN, etc. * Enable gnu extension to c++11 for firestore/util *test*. We disable them by default (in cmake/CompilerSetup.cmake) but our tests requires hexidecimal floating point, which is not supported in c++11 (though is supported in C++17, gnu++11, and others). http://en.cppreference.com/w/cpp/language/floating_literal https://bugzilla.redhat.com/show_bug.cgi?id=1321986 * Fix printf format for uint64_t http://en.cppreference.com/w/cpp/types/integer https://stackoverflow.com/questions/9225567/how-to-print-a-int64-t-type-in-c * Allow 0 length printf template strings in tests. * Get rid of a multi line comment. The backslash is apparently interpreted by the compiler cause the next line to be ignored too. In this case, the next line is (currently) a comment, and would be ignored anyways. (But that doesn't stop the compiler from yelling.) * Run ./scripts/style.sh
1 parent aaa968e commit c827bf4

File tree

9 files changed

+54
-44
lines changed

9 files changed

+54
-44
lines changed

Firestore/core/src/firebase/firestore/model/field_value.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ FieldValue& FieldValue::operator=(const FieldValue& value) {
9595
break;
9696
case Type::Blob: {
9797
// copy-and-swap
98-
std::vector<const uint8_t> tmp = value.blob_value_;
98+
std::vector<uint8_t> tmp = value.blob_value_;
9999
std::swap(blob_value_, tmp);
100100
break;
101101
}
@@ -104,7 +104,7 @@ FieldValue& FieldValue::operator=(const FieldValue& value) {
104104
break;
105105
case Type::Array: {
106106
// copy-and-swap
107-
std::vector<const FieldValue> tmp = value.array_value_;
107+
std::vector<FieldValue> tmp = value.array_value_;
108108
std::swap(array_value_, tmp);
109109
break;
110110
}
@@ -228,7 +228,7 @@ FieldValue FieldValue::StringValue(std::string&& value) {
228228
FieldValue FieldValue::BlobValue(const uint8_t* source, size_t size) {
229229
FieldValue result;
230230
result.SwitchTo(Type::Blob);
231-
std::vector<const uint8_t> copy(source, source + size);
231+
std::vector<uint8_t> copy(source, source + size);
232232
std::swap(result.blob_value_, copy);
233233
return result;
234234
}
@@ -240,12 +240,12 @@ FieldValue FieldValue::GeoPointValue(const GeoPoint& value) {
240240
return result;
241241
}
242242

243-
FieldValue FieldValue::ArrayValue(const std::vector<const FieldValue>& value) {
244-
std::vector<const FieldValue> copy(value);
243+
FieldValue FieldValue::ArrayValue(const std::vector<FieldValue>& value) {
244+
std::vector<FieldValue> copy(value);
245245
return ArrayValue(std::move(copy));
246246
}
247247

248-
FieldValue FieldValue::ArrayValue(std::vector<const FieldValue>&& value) {
248+
FieldValue FieldValue::ArrayValue(std::vector<FieldValue>&& value) {
249249
FieldValue result;
250250
result.SwitchTo(Type::Array);
251251
std::swap(result.array_value_, value);
@@ -368,13 +368,13 @@ void FieldValue::SwitchTo(const Type type) {
368368
break;
369369
case Type::Blob:
370370
// Do not even bother to allocate a new array of size 0.
371-
new (&blob_value_) std::vector<const uint8_t>();
371+
new (&blob_value_) std::vector<uint8_t>();
372372
break;
373373
case Type::GeoPoint:
374374
new (&geo_point_value_) GeoPoint();
375375
break;
376376
case Type::Array:
377-
new (&array_value_) std::vector<const FieldValue>();
377+
new (&array_value_) std::vector<FieldValue>();
378378
break;
379379
case Type::Object:
380380
new (&object_value_) std::map<const std::string, const FieldValue>();

Firestore/core/src/firebase/firestore/model/field_value.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class FieldValue {
105105
static FieldValue BlobValue(const uint8_t* source, size_t size);
106106
// static FieldValue ReferenceValue();
107107
static FieldValue GeoPointValue(const GeoPoint& value);
108-
static FieldValue ArrayValue(const std::vector<const FieldValue>& value);
109-
static FieldValue ArrayValue(std::vector<const FieldValue>&& value);
108+
static FieldValue ArrayValue(const std::vector<FieldValue>& value);
109+
static FieldValue ArrayValue(std::vector<FieldValue>&& value);
110110
static FieldValue ObjectValue(
111111
const std::map<const std::string, const FieldValue>& value);
112112
static FieldValue ObjectValue(
@@ -132,9 +132,9 @@ class FieldValue {
132132
Timestamp timestamp_value_;
133133
ServerTimestamp server_timestamp_value_;
134134
std::string string_value_;
135-
std::vector<const uint8_t> blob_value_;
135+
std::vector<uint8_t> blob_value_;
136136
GeoPoint geo_point_value_;
137-
std::vector<const FieldValue> array_value_;
137+
std::vector<FieldValue> array_value_;
138138
std::map<const std::string, const FieldValue> object_value_;
139139
};
140140
};

Firestore/core/src/firebase/firestore/util/assert_stdio.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <stdarg.h>
1818

19-
#include <exception>
19+
#include <stdexcept>
2020
#include <string>
2121

2222
#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h"

Firestore/core/test/firebase/firestore/core/target_id_generator_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ TEST(TargetIdGenerator, SkipPast) {
4343
for (int i = 4; i < 12; ++i) {
4444
TargetIdGenerator a = TargetIdGenerator::LocalStoreTargetIdGenerator(i);
4545
TargetIdGenerator b = TargetIdGenerator::SyncEngineTargetIdGenerator(i);
46-
EXPECT_EQ(i + 2 & ~1, a.NextId());
47-
EXPECT_EQ(i + 1 | 1, b.NextId());
46+
EXPECT_EQ((i + 2) & ~1, a.NextId());
47+
EXPECT_EQ((i + 1) | 1, b.NextId());
4848
}
4949

5050
EXPECT_EQ(13, TargetIdGenerator::SyncEngineTargetIdGenerator(12).NextId());

Firestore/core/test/firebase/firestore/model/field_value_test.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "Firestore/core/src/firebase/firestore/model/field_value.h"
1818

19+
#include <limits.h>
20+
1921
#include <vector>
2022

2123
#include "gtest/gtest.h"
@@ -152,15 +154,14 @@ TEST(FieldValue, GeoPointType) {
152154
}
153155

154156
TEST(FieldValue, ArrayType) {
155-
const FieldValue empty =
156-
FieldValue::ArrayValue(std::vector<const FieldValue>{});
157-
std::vector<const FieldValue> array{FieldValue::NullValue(),
158-
FieldValue::BooleanValue(true),
159-
FieldValue::BooleanValue(false)};
157+
const FieldValue empty = FieldValue::ArrayValue(std::vector<FieldValue>{});
158+
std::vector<FieldValue> array{FieldValue::NullValue(),
159+
FieldValue::BooleanValue(true),
160+
FieldValue::BooleanValue(false)};
160161
// copy the array
161162
const FieldValue small = FieldValue::ArrayValue(array);
162-
std::vector<const FieldValue> another_array{FieldValue::BooleanValue(true),
163-
FieldValue::BooleanValue(false)};
163+
std::vector<FieldValue> another_array{FieldValue::BooleanValue(true),
164+
FieldValue::BooleanValue(false)};
164165
// move the array
165166
const FieldValue large = FieldValue::ArrayValue(std::move(another_array));
166167
EXPECT_EQ(Type::Array, empty.type());
@@ -288,18 +289,17 @@ TEST(FieldValue, Copy) {
288289
clone = null_value;
289290
EXPECT_EQ(FieldValue::NullValue(), clone);
290291

291-
const FieldValue array_value =
292-
FieldValue::ArrayValue(std::vector<const FieldValue>{
293-
FieldValue::TrueValue(), FieldValue::FalseValue()});
292+
const FieldValue array_value = FieldValue::ArrayValue(std::vector<FieldValue>{
293+
FieldValue::TrueValue(), FieldValue::FalseValue()});
294294
clone = array_value;
295-
EXPECT_EQ(FieldValue::ArrayValue(std::vector<const FieldValue>{
295+
EXPECT_EQ(FieldValue::ArrayValue(std::vector<FieldValue>{
296296
FieldValue::TrueValue(), FieldValue::FalseValue()}),
297297
clone);
298-
EXPECT_EQ(FieldValue::ArrayValue(std::vector<const FieldValue>{
298+
EXPECT_EQ(FieldValue::ArrayValue(std::vector<FieldValue>{
299299
FieldValue::TrueValue(), FieldValue::FalseValue()}),
300300
array_value);
301301
clone = clone;
302-
EXPECT_EQ(FieldValue::ArrayValue(std::vector<const FieldValue>{
302+
EXPECT_EQ(FieldValue::ArrayValue(std::vector<FieldValue>{
303303
FieldValue::TrueValue(), FieldValue::FalseValue()}),
304304
clone);
305305
clone = null_value;
@@ -385,10 +385,10 @@ TEST(FieldValue, Move) {
385385
clone = null_value;
386386
EXPECT_EQ(FieldValue::NullValue(), clone);
387387

388-
FieldValue array_value = FieldValue::ArrayValue(std::vector<const FieldValue>{
388+
FieldValue array_value = FieldValue::ArrayValue(std::vector<FieldValue>{
389389
FieldValue::TrueValue(), FieldValue::FalseValue()});
390390
clone = std::move(array_value);
391-
EXPECT_EQ(FieldValue::ArrayValue(std::vector<const FieldValue>{
391+
EXPECT_EQ(FieldValue::ArrayValue(std::vector<FieldValue>{
392392
FieldValue::TrueValue(), FieldValue::FalseValue()}),
393393
clone);
394394
clone = FieldValue::NullValue();
@@ -417,7 +417,7 @@ TEST(FieldValue, CompareMixedType) {
417417
const FieldValue blob_value = FieldValue::BlobValue(Bytes("abc"), 4);
418418
const FieldValue geo_point_value = FieldValue::GeoPointValue({1, 2});
419419
const FieldValue array_value =
420-
FieldValue::ArrayValue(std::vector<const FieldValue>());
420+
FieldValue::ArrayValue(std::vector<FieldValue>());
421421
const FieldValue object_value =
422422
FieldValue::ObjectValue(std::map<const std::string, const FieldValue>());
423423
EXPECT_TRUE(null_value < true_value);

Firestore/core/test/firebase/firestore/util/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
set(CMAKE_CXX_EXTENSIONS ON)
16+
17+
# Required to allow 0 length printf style strings for testing purposes.
18+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format-zero-length")
19+
1520
if(HAVE_ARC4RANDOM)
1621
cc_test(
1722
firebase_firestore_util_arc4random_test

Firestore/core/test/firebase/firestore/util/comparison_test.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "Firestore/core/src/firebase/firestore/util/comparison.h"
1818

19+
#include <inttypes.h>
1920
#include <math.h>
2021

2122
#include <limits>
@@ -84,17 +85,17 @@ TEST(Comparison, DoubleCompare) {
8485
ASSERT_SAME(Compare<double>(-0, 0));
8586
}
8687

87-
#define ASSERT_BIT_EQUALS(expected, actual) \
88-
do { \
89-
uint64_t expectedBits = DoubleBits(expected); \
90-
uint64_t actualBits = DoubleBits(actual); \
91-
if (expectedBits != actualBits) { \
92-
std::string message = StringPrintf( \
93-
"Expected <%f> to compare equal to <%f> " \
94-
"with bits <%llX> equal to <%llX>", \
95-
actual, expected, actualBits, expectedBits); \
96-
FAIL() << message; \
97-
} \
88+
#define ASSERT_BIT_EQUALS(expected, actual) \
89+
do { \
90+
uint64_t expectedBits = DoubleBits(expected); \
91+
uint64_t actualBits = DoubleBits(actual); \
92+
if (expectedBits != actualBits) { \
93+
std::string message = StringPrintf( \
94+
"Expected <%f> to compare equal to <%f> " \
95+
"with bits <%" PRIu64 "> equal to <%" PRIu64 ">", \
96+
actual, expected, actualBits, expectedBits); \
97+
FAIL() << message; \
98+
} \
9899
} while (0);
99100

100101
#define ASSERT_MIXED_SAME(doubleValue, longValue) \

Firestore/core/test/firebase/firestore/util/log_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace util {
3030
//
3131
// You can fix it with:
3232
//
33-
// defaults write firebase_firestore_util_log_apple_test \
33+
// defaults write firebase_firestore_util_log_apple_test
3434
// /google/firebase/debug_mode NO
3535
TEST(Log, SetAndGet) {
3636
LogSetLevel(kLogLevelVerbose);

cmake/CompilerSetup.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ if(CLANG OR GNU)
4141

4242
# Delete unused things
4343
-Wunused-function -Wunused-value -Wunused-variable
44+
)
45+
46+
set(
47+
cxx_flags
4448

4549
# Cut down on symbol clutter
4650
# TODO(wilhuff) try -fvisibility=hidden
@@ -64,7 +68,7 @@ if(CLANG OR GNU)
6468
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
6569
endforeach()
6670

67-
foreach(flag ${common_flags})
71+
foreach(flag ${common_flags} ${cxx_flags})
6872
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
6973
endforeach()
7074
endif()

0 commit comments

Comments
 (0)