Skip to content

Commit 09366cc

Browse files
committed
Bug#30343887: NEW COMPILATION WARNINGS WITH XCODE 11
Fix new compilation warnings that appeared with XCode 11. The warnings are deprecation warnings about std::random_shuffle() which was deprecated in C++14. Replace with std::shuffle(). Only affects unit tests. Change-Id: I773f5f7c3e30afb8d62815e35d6ccdb67b54d751
1 parent a895165 commit 09366cc

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

router/src/harness/include/random_generator.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -25,6 +25,7 @@
2525
#ifndef MYSQL_HARNESS_RANDOM_GENERATOR_INCLUDED
2626
#define MYSQL_HARNESS_RANDOM_GENERATOR_INCLUDED
2727

28+
#include <random>
2829
#include <string>
2930

3031
#include "harness_export.h"
@@ -78,7 +79,10 @@ class HARNESS_EXPORT RandomGeneratorInterface {
7879
};
7980

8081
class HARNESS_EXPORT RandomGenerator : public RandomGeneratorInterface {
82+
std::mt19937 urng;
83+
8184
public:
85+
RandomGenerator() : urng(std::random_device().operator()()) {}
8286
std::string generate_identifier(
8387
unsigned length, unsigned alphabet_mask = AlphabetAll) override;
8488
std::string generate_strong_password(unsigned length) override;

router/src/harness/src/random_generator.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -97,7 +97,7 @@ std::string RandomGenerator::generate_strong_password(
9797
length -= static_cast<unsigned>(result.length());
9898
result += generate_identifier(length, AlphabetAll);
9999

100-
std::random_shuffle(result.begin(), result.end());
100+
std::shuffle(result.begin(), result.end(), urng);
101101

102102
return result;
103103
}

unittest/gunit/alignment-t.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <gtest/gtest.h>
2626
#include <algorithm>
27+
#include <random>
2728
#include <vector>
2829

2930
#include "my_byteorder.h"
@@ -51,7 +52,9 @@ class AlignmentTest : public ::testing::Test {
5152
for (int ix = 0; ix < num_records; ++ix) {
5253
aligned_data[ix] = ix / 10;
5354
}
54-
std::random_shuffle(aligned_data, aligned_data + num_records);
55+
std::random_device rng;
56+
std::mt19937 urng(rng());
57+
std::shuffle(aligned_data, aligned_data + num_records, urng);
5558
memcpy(unaligned_data + 1, aligned_data, num_records * sizeof(int));
5659
}
5760

unittest/gunit/bounds_checked_array-t.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -22,6 +22,7 @@
2222

2323
#include <gtest/gtest.h>
2424
#include <algorithm>
25+
#include <random>
2526

2627
#include "sql/sql_array.h"
2728

@@ -171,7 +172,9 @@ TEST_F(BoundsCheckedArray, Equality) {
171172

172173
TEST_F(BoundsCheckedArray, Sort) {
173174
int_array = Int_array(c_array, c_array_size);
174-
std::random_shuffle(int_array.begin(), int_array.end());
175+
std::random_device rng;
176+
std::mt19937 urng(rng());
177+
std::shuffle(int_array.begin(), int_array.end(), urng);
175178
std::sort(int_array.begin(), int_array.end());
176179
Int_array::const_iterator it;
177180
int ix;

unittest/gunit/prealloced_array-t.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -26,6 +26,7 @@
2626
#include <gtest/gtest.h>
2727
#include <algorithm>
2828
#include <memory>
29+
#include <random>
2930

3031
#include "prealloced_array.h"
3132

@@ -186,7 +187,9 @@ TEST_F(PreallocedArrayTest, InsertUnique) {
186187
int_10.push_back(ix);
187188
int_10.push_back(ix);
188189
}
189-
std::random_shuffle(int_10.begin(), int_10.end());
190+
std::random_device rng;
191+
std::mt19937 urng(rng());
192+
std::shuffle(int_10.begin(), int_10.end(), urng);
190193
Prealloced_array<int, 1> unique_arr(PSI_NOT_INSTRUMENTED);
191194
for (int *pi = int_10.begin(); pi != int_10.end(); ++pi) {
192195
unique_arr.insert_unique(*pi);

unittest/gunit/priority_queue-t.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -26,6 +26,7 @@
2626
#include <functional>
2727
#include <iostream>
2828
#include <iterator>
29+
#include <random>
2930
#include <sstream>
3031
#include <vector>
3132
#include "my_config.h"
@@ -613,7 +614,9 @@ TEST_F(PriorityQueueTest, DifferentCtors) {
613614
}
614615

615616
TEST_F(PriorityQueueTest, Swap) {
616-
std::random_shuffle(keys, keys + 10);
617+
std::random_device rng;
618+
std::mt19937 urng(rng());
619+
std::shuffle(keys, keys + 10, urng);
617620
Priority_queue<int> pq(keys, keys + 10);
618621
std::stringstream ss1, ss2;
619622
ss1 << pq;

0 commit comments

Comments
 (0)