2015-05-22 04:14:25 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2020-03-28 16:57:20 +03:00
|
|
|
#include <type_traits>
|
2020-01-20 19:18:20 +03:00
|
|
|
#include <utility>
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
|
|
|
|
#include "mozilla/Assertions.h"
|
2020-03-17 15:42:12 +03:00
|
|
|
#include "mozilla/CompactPair.h"
|
2015-05-22 04:14:25 +03:00
|
|
|
#include "mozilla/Tuple.h"
|
|
|
|
#include "mozilla/UniquePtr.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-05-22 04:14:25 +03:00
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
using mozilla::CompactPair;
|
2015-05-22 04:14:25 +03:00
|
|
|
using mozilla::Get;
|
|
|
|
using mozilla::MakeTuple;
|
|
|
|
using mozilla::MakeUnique;
|
2015-07-18 10:48:39 +03:00
|
|
|
using mozilla::Tie;
|
2015-05-22 04:14:25 +03:00
|
|
|
using mozilla::Tuple;
|
|
|
|
using mozilla::UniquePtr;
|
2015-11-02 08:53:26 +03:00
|
|
|
using mozilla::Unused;
|
2015-07-24 01:42:00 +03:00
|
|
|
using std::pair;
|
2015-05-22 04:14:25 +03:00
|
|
|
|
|
|
|
#define CHECK(c) \
|
|
|
|
do { \
|
|
|
|
bool cond = !!(c); \
|
|
|
|
MOZ_RELEASE_ASSERT(cond, "Failed assertion: " #c); \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
// The second argument is the expected type. It's variadic to allow the
|
|
|
|
// type to contain commas.
|
2020-03-28 16:57:20 +03:00
|
|
|
#define CHECK_TYPE(expression, ...) \
|
|
|
|
static_assert(std::is_same_v<decltype(expression), __VA_ARGS__>, \
|
2015-05-22 04:14:25 +03:00
|
|
|
"Type mismatch!")
|
|
|
|
|
|
|
|
struct ConvertibleToInt {
|
2015-07-18 10:48:39 +03:00
|
|
|
operator int() const { return 42; }
|
2015-05-22 04:14:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static void TestConstruction() {
|
|
|
|
// Default construction
|
|
|
|
Tuple<> a;
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << a;
|
2015-05-22 04:14:25 +03:00
|
|
|
Tuple<int> b;
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << b;
|
2015-05-22 04:14:25 +03:00
|
|
|
|
|
|
|
// Construction from elements
|
|
|
|
int x = 1, y = 1;
|
|
|
|
Tuple<int, int> c{x, y};
|
|
|
|
Tuple<int&, const int&> d{x, y};
|
|
|
|
x = 42;
|
|
|
|
y = 42;
|
|
|
|
CHECK(Get<0>(c) == 1);
|
|
|
|
CHECK(Get<1>(c) == 1);
|
|
|
|
CHECK(Get<0>(d) == 42);
|
|
|
|
CHECK(Get<1>(d) == 42);
|
|
|
|
|
|
|
|
// Construction from objects convertible to the element types
|
|
|
|
Tuple<int, int> e{1.0, ConvertibleToInt{}};
|
|
|
|
|
|
|
|
// Copy construction
|
|
|
|
Tuple<int> x1;
|
|
|
|
Tuple<int> x2{x1};
|
|
|
|
|
|
|
|
Tuple<int, int> f(c);
|
|
|
|
CHECK(Get<0>(f) == 1);
|
|
|
|
CHECK(Get<0>(f) == 1);
|
|
|
|
|
|
|
|
// Move construction
|
|
|
|
Tuple<UniquePtr<int>> g{MakeUnique<int>(42)};
|
2018-05-30 22:15:35 +03:00
|
|
|
Tuple<UniquePtr<int>> h{std::move(g)};
|
2015-05-22 04:14:25 +03:00
|
|
|
CHECK(Get<0>(g) == nullptr);
|
|
|
|
CHECK(*Get<0>(h) == 42);
|
|
|
|
}
|
|
|
|
|
2015-07-24 01:42:00 +03:00
|
|
|
static void TestConstructionFromMozPair() {
|
|
|
|
// Construction from elements
|
|
|
|
int x = 1, y = 1;
|
2020-03-17 15:42:12 +03:00
|
|
|
CompactPair<int, int> a{x, y};
|
|
|
|
CompactPair<int&, const int&> b{x, y};
|
2015-07-24 01:42:00 +03:00
|
|
|
Tuple<int, int> c(a);
|
|
|
|
Tuple<int&, const int&> d(b);
|
|
|
|
x = 42;
|
|
|
|
y = 42;
|
|
|
|
CHECK(Get<0>(c) == 1);
|
|
|
|
CHECK(Get<1>(c) == 1);
|
|
|
|
CHECK(Get<0>(d) == 42);
|
|
|
|
CHECK(Get<1>(d) == 42);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TestConstructionFromStdPair() {
|
|
|
|
// Construction from elements
|
|
|
|
int x = 1, y = 1;
|
|
|
|
pair<int, int> a{x, y};
|
|
|
|
pair<int&, const int&> b{x, y};
|
|
|
|
Tuple<int, int> c(a);
|
|
|
|
Tuple<int&, const int&> d(b);
|
|
|
|
x = 42;
|
|
|
|
y = 42;
|
|
|
|
CHECK(Get<0>(c) == 1);
|
|
|
|
CHECK(Get<1>(c) == 1);
|
|
|
|
CHECK(Get<0>(d) == 42);
|
|
|
|
CHECK(Get<1>(d) == 42);
|
|
|
|
}
|
|
|
|
|
2015-05-22 04:14:25 +03:00
|
|
|
static void TestAssignment() {
|
|
|
|
// Copy assignment
|
|
|
|
Tuple<int> a{0};
|
|
|
|
Tuple<int> b{42};
|
|
|
|
a = b;
|
|
|
|
CHECK(Get<0>(a) == 42);
|
|
|
|
|
|
|
|
// Assignment to reference member
|
|
|
|
int i = 0;
|
|
|
|
int j = 42;
|
|
|
|
Tuple<int&> c{i};
|
|
|
|
Tuple<int&> d{j};
|
|
|
|
c = d;
|
|
|
|
CHECK(i == 42);
|
|
|
|
|
|
|
|
// Move assignment
|
|
|
|
Tuple<UniquePtr<int>> e{MakeUnique<int>(0)};
|
|
|
|
Tuple<UniquePtr<int>> f{MakeUnique<int>(42)};
|
2018-05-30 22:15:35 +03:00
|
|
|
e = std::move(f);
|
2015-05-22 04:14:25 +03:00
|
|
|
CHECK(*Get<0>(e) == 42);
|
|
|
|
CHECK(Get<0>(f) == nullptr);
|
|
|
|
}
|
|
|
|
|
2015-07-24 01:42:00 +03:00
|
|
|
static void TestAssignmentFromMozPair() {
|
|
|
|
// Copy assignment
|
|
|
|
Tuple<int, int> a{0, 0};
|
2020-03-17 15:42:12 +03:00
|
|
|
CompactPair<int, int> b{42, 42};
|
2015-07-24 01:42:00 +03:00
|
|
|
a = b;
|
|
|
|
CHECK(Get<0>(a) == 42);
|
|
|
|
CHECK(Get<1>(a) == 42);
|
|
|
|
|
|
|
|
// Assignment to reference member
|
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
|
|
|
int k = 42;
|
|
|
|
Tuple<int&, int&> c{i, j};
|
2020-03-17 15:42:12 +03:00
|
|
|
CompactPair<int&, int&> d{k, k};
|
2015-07-24 01:42:00 +03:00
|
|
|
c = d;
|
|
|
|
CHECK(i == 42);
|
|
|
|
CHECK(j == 42);
|
|
|
|
|
|
|
|
// Move assignment
|
|
|
|
Tuple<UniquePtr<int>, UniquePtr<int>> e{MakeUnique<int>(0),
|
|
|
|
MakeUnique<int>(0)};
|
2020-03-17 15:42:12 +03:00
|
|
|
CompactPair<UniquePtr<int>, UniquePtr<int>> f{MakeUnique<int>(42),
|
|
|
|
MakeUnique<int>(42)};
|
2018-05-30 22:15:35 +03:00
|
|
|
e = std::move(f);
|
2015-07-24 01:42:00 +03:00
|
|
|
CHECK(*Get<0>(e) == 42);
|
|
|
|
CHECK(*Get<1>(e) == 42);
|
|
|
|
CHECK(f.first() == nullptr);
|
|
|
|
CHECK(f.second() == nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TestAssignmentFromStdPair() {
|
|
|
|
// Copy assignment
|
|
|
|
Tuple<int, int> a{0, 0};
|
|
|
|
pair<int, int> b{42, 42};
|
|
|
|
a = b;
|
|
|
|
CHECK(Get<0>(a) == 42);
|
|
|
|
CHECK(Get<1>(a) == 42);
|
|
|
|
|
|
|
|
// Assignment to reference member
|
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
|
|
|
int k = 42;
|
|
|
|
Tuple<int&, int&> c{i, j};
|
|
|
|
pair<int&, int&> d{k, k};
|
|
|
|
c = d;
|
|
|
|
CHECK(i == 42);
|
|
|
|
CHECK(j == 42);
|
|
|
|
|
|
|
|
// Move assignment.
|
|
|
|
Tuple<UniquePtr<int>, UniquePtr<int>> e{MakeUnique<int>(0),
|
|
|
|
MakeUnique<int>(0)};
|
|
|
|
// XXX: On some platforms std::pair doesn't support move constructor.
|
|
|
|
pair<UniquePtr<int>, UniquePtr<int>> f;
|
|
|
|
f.first = MakeUnique<int>(42);
|
|
|
|
f.second = MakeUnique<int>(42);
|
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
e = std::move(f);
|
2015-07-24 01:42:00 +03:00
|
|
|
CHECK(*Get<0>(e) == 42);
|
|
|
|
CHECK(*Get<1>(e) == 42);
|
|
|
|
CHECK(f.first == nullptr);
|
|
|
|
CHECK(f.second == nullptr);
|
|
|
|
}
|
|
|
|
|
2015-05-22 04:14:25 +03:00
|
|
|
static void TestGet() {
|
|
|
|
int x = 1;
|
|
|
|
int y = 2;
|
|
|
|
int z = 3;
|
|
|
|
Tuple<int, int&, const int&> tuple(x, y, z);
|
|
|
|
|
|
|
|
// Using Get<>() to read elements
|
|
|
|
CHECK(Get<0>(tuple) == 1);
|
|
|
|
CHECK(Get<1>(tuple) == 2);
|
|
|
|
CHECK(Get<2>(tuple) == 3);
|
|
|
|
|
|
|
|
// Using Get<>() to write to elements
|
|
|
|
Get<0>(tuple) = 41;
|
|
|
|
CHECK(Get<0>(tuple) == 41);
|
|
|
|
|
|
|
|
// Writing through reference elements
|
|
|
|
Get<1>(tuple) = 42;
|
|
|
|
CHECK(Get<1>(tuple) == 42);
|
|
|
|
CHECK(y == 42);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TestMakeTuple() {
|
|
|
|
auto tuple = MakeTuple(42, 0.5f, 'c');
|
|
|
|
CHECK_TYPE(tuple, Tuple<int, float, char>);
|
|
|
|
CHECK(Get<0>(tuple) == 42);
|
2015-07-21 23:54:00 +03:00
|
|
|
CHECK(Get<1>(tuple) == 0.5f);
|
2015-05-22 04:14:25 +03:00
|
|
|
CHECK(Get<2>(tuple) == 'c');
|
2015-11-03 03:50:06 +03:00
|
|
|
|
|
|
|
// Make sure we don't infer the type to be Tuple<int&>.
|
|
|
|
int x = 1;
|
|
|
|
auto tuple2 = MakeTuple(x);
|
|
|
|
CHECK_TYPE(tuple2, Tuple<int>);
|
|
|
|
x = 2;
|
|
|
|
CHECK(Get<0>(tuple2) == 1);
|
2015-05-22 04:14:25 +03:00
|
|
|
}
|
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
static bool TestTieMozPair() {
|
2015-07-18 10:48:39 +03:00
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
char c;
|
|
|
|
Tuple<int, float, char> rhs1(42, 0.5f, 'c');
|
|
|
|
Tie(i, f, c) = rhs1;
|
|
|
|
CHECK(i == Get<0>(rhs1));
|
|
|
|
CHECK(f == Get<1>(rhs1));
|
|
|
|
CHECK(c == Get<2>(rhs1));
|
|
|
|
// Test conversions
|
|
|
|
Tuple<ConvertibleToInt, double, unsigned char> rhs2(ConvertibleToInt(), 0.7f,
|
|
|
|
'd');
|
|
|
|
Tie(i, f, c) = rhs2;
|
|
|
|
CHECK(i == Get<0>(rhs2));
|
|
|
|
CHECK(f == Get<1>(rhs2));
|
|
|
|
CHECK(c == Get<2>(rhs2));
|
2015-07-24 01:42:00 +03:00
|
|
|
|
|
|
|
// Test Pair
|
2020-03-17 15:42:12 +03:00
|
|
|
CompactPair<int, float> rhs3(42, 1.5f);
|
2015-07-24 01:42:00 +03:00
|
|
|
Tie(i, f) = rhs3;
|
|
|
|
CHECK(i == rhs3.first());
|
|
|
|
CHECK(f == rhs3.second());
|
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool TestTie() {
|
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
char c;
|
|
|
|
Tuple<int, float, char> rhs1(42, 0.5f, 'c');
|
|
|
|
Tie(i, f, c) = rhs1;
|
|
|
|
CHECK(i == Get<0>(rhs1));
|
|
|
|
CHECK(f == Get<1>(rhs1));
|
|
|
|
CHECK(c == Get<2>(rhs1));
|
|
|
|
// Test conversions
|
|
|
|
Tuple<ConvertibleToInt, double, unsigned char> rhs2(ConvertibleToInt(), 0.7f,
|
|
|
|
'd');
|
|
|
|
Tie(i, f, c) = rhs2;
|
|
|
|
CHECK(i == Get<0>(rhs2));
|
|
|
|
CHECK(f == Get<1>(rhs2));
|
|
|
|
CHECK(c == Get<2>(rhs2));
|
|
|
|
|
|
|
|
// Test Pair
|
|
|
|
pair<int, float> rhs3(42, 1.5f);
|
|
|
|
Tie(i, f) = rhs3;
|
|
|
|
CHECK(i == rhs3.first);
|
|
|
|
CHECK(f == rhs3.second);
|
2015-07-24 01:42:00 +03:00
|
|
|
|
2015-07-18 10:48:39 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-31 15:36:22 +03:00
|
|
|
static bool TestTieIgnore() {
|
|
|
|
int i;
|
|
|
|
char c;
|
|
|
|
Tuple<int, float, char> rhs1(42, 0.5f, 'c');
|
|
|
|
|
|
|
|
Tie(i, mozilla::Ignore, c) = rhs1;
|
|
|
|
|
|
|
|
CHECK(i == Get<0>(rhs1));
|
|
|
|
CHECK(c == Get<2>(rhs1));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-22 04:14:25 +03:00
|
|
|
int main() {
|
|
|
|
TestConstruction();
|
2015-07-24 01:42:00 +03:00
|
|
|
TestConstructionFromMozPair();
|
|
|
|
TestConstructionFromStdPair();
|
2015-05-22 04:14:25 +03:00
|
|
|
TestAssignment();
|
2015-07-24 01:42:00 +03:00
|
|
|
TestAssignmentFromMozPair();
|
|
|
|
TestAssignmentFromStdPair();
|
2015-05-22 04:14:25 +03:00
|
|
|
TestGet();
|
|
|
|
TestMakeTuple();
|
2015-07-18 10:48:39 +03:00
|
|
|
TestTie();
|
2020-03-31 15:36:22 +03:00
|
|
|
TestTieIgnore();
|
2020-03-17 15:42:12 +03:00
|
|
|
TestTieMozPair();
|
2015-05-22 04:14:25 +03:00
|
|
|
return 0;
|
|
|
|
}
|