Fix Bug 38644: multimap::clear() missing exception specifier. Add noexcept tests for all the containers that have clear().

llvm-svn: 340385
This commit is contained in:
Marshall Clow 2018-08-22 04:28:43 +00:00
parent fdd73b5037
commit 934e9a3976
13 changed files with 114 additions and 12 deletions

View File

@ -1884,7 +1884,7 @@ public:
#endif
_LIBCPP_INLINE_VISIBILITY
void clear() {__tree_.clear();}
void clear() _NOEXCEPT {__tree_.clear();}
_LIBCPP_INLINE_VISIBILITY
void swap(multimap& __m)

View File

@ -11,11 +11,12 @@
// class map
// void clear();
// void clear() noexcept;
#include <map>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main()
@ -36,6 +37,7 @@ int main()
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}
@ -56,6 +58,7 @@ int main()
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}

View File

@ -11,11 +11,12 @@
// class multimap
// void clear();
// void clear() noexcept;
#include <map>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main()
@ -36,6 +37,7 @@ int main()
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}
@ -56,6 +58,7 @@ int main()
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}

View File

@ -11,11 +11,12 @@
// class multiset
// void clear();
// void clear() noexcept;
#include <set>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main()
@ -36,6 +37,7 @@ int main()
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}
@ -56,6 +58,7 @@ int main()
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}

View File

@ -11,11 +11,12 @@
// class set
// void clear();
// void clear() noexcept;
#include <set>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main()
@ -36,6 +37,7 @@ int main()
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}
@ -56,6 +58,7 @@ int main()
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}

View File

@ -0,0 +1,67 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <deque>
// void clear() noexcept;
#include <deque>
#include <cassert>
#include "test_macros.h"
#include "../../../NotConstructible.h"
#include "min_allocator.h"
int main()
{
{
typedef NotConstructible T;
typedef std::deque<T> C;
C c;
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(distance(c.begin(), c.end()) == 0);
}
{
typedef int T;
typedef std::deque<T> C;
const T t[] = {0, 1, 2, 3, 4};
C c(std::begin(t), std::end(t));
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(distance(c.begin(), c.end()) == 0);
c.clear();
assert(distance(c.begin(), c.end()) == 0);
}
#if TEST_STD_VER >= 11
{
typedef NotConstructible T;
typedef std::deque<T, min_allocator<T>> C;
C c;
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(distance(c.begin(), c.end()) == 0);
}
{
typedef int T;
typedef std::deque<T, min_allocator<T>> C;
const T t[] = {0, 1, 2, 3, 4};
C c(std::begin(t), std::end(t));
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(distance(c.begin(), c.end()) == 0);
c.clear();
assert(distance(c.begin(), c.end()) == 0);
}
#endif
}

View File

@ -9,11 +9,12 @@
// <forward_list>
// void clear();
// void clear() noexcept;
#include <forward_list>
#include <cassert>
#include "test_macros.h"
#include "../../../NotConstructible.h"
#include "min_allocator.h"
@ -23,6 +24,7 @@ int main()
typedef NotConstructible T;
typedef std::forward_list<T> C;
C c;
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(distance(c.begin(), c.end()) == 0);
}
@ -32,6 +34,7 @@ int main()
const T t[] = {0, 1, 2, 3, 4};
C c(std::begin(t), std::end(t));
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(distance(c.begin(), c.end()) == 0);
@ -43,6 +46,7 @@ int main()
typedef NotConstructible T;
typedef std::forward_list<T, min_allocator<T>> C;
C c;
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(distance(c.begin(), c.end()) == 0);
}
@ -52,6 +56,7 @@ int main()
const T t[] = {0, 1, 2, 3, 4};
C c(std::begin(t), std::end(t));
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(distance(c.begin(), c.end()) == 0);

View File

@ -9,11 +9,12 @@
// <list>
// void clear();
// void clear() noexcept;
#include <list>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main()
@ -21,6 +22,7 @@ int main()
{
int a[] = {1, 2, 3};
std::list<int> c(a, a+3);
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.empty());
}
@ -28,6 +30,7 @@ int main()
{
int a[] = {1, 2, 3};
std::list<int, min_allocator<int>> c(a, a+3);
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.empty());
}

View File

@ -9,11 +9,12 @@
// <vector>
// void clear();
// void clear() noexcept;
#include <vector>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
#include "asan_testing.h"
@ -22,6 +23,7 @@ int main()
{
int a[] = {1, 2, 3};
std::vector<int> c(a, a+3);
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.empty());
LIBCPP_ASSERT(c.__invariants());
@ -31,6 +33,7 @@ int main()
{
int a[] = {1, 2, 3};
std::vector<int, min_allocator<int>> c(a, a+3);
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.empty());
LIBCPP_ASSERT(c.__invariants());

View File

@ -13,12 +13,13 @@
// class Alloc = allocator<pair<const Key, T>>>
// class unordered_map
// void clear()
// void clear() noexcept;
#include <unordered_map>
#include <string>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main()
@ -36,6 +37,7 @@ int main()
P(2, "four"),
};
C c(a, a + sizeof(a)/sizeof(a[0]));
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}
@ -54,6 +56,7 @@ int main()
P(2, "four"),
};
C c(a, a + sizeof(a)/sizeof(a[0]));
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}

View File

@ -13,12 +13,13 @@
// class Alloc = allocator<pair<const Key, T>>>
// class unordered_multimap
// void clear()
// void clear() noexcept;
#include <unordered_map>
#include <string>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main()
@ -36,6 +37,7 @@ int main()
P(2, "four"),
};
C c(a, a + sizeof(a)/sizeof(a[0]));
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}
@ -54,6 +56,7 @@ int main()
P(2, "four"),
};
C c(a, a + sizeof(a)/sizeof(a[0]));
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}

View File

@ -13,11 +13,12 @@
// class Alloc = allocator<Value>>
// class unordered_multiset
// void clear()
// void clear() noexcept;
#include <unordered_set>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main()
@ -35,6 +36,7 @@ int main()
P(2)
};
C c(a, a + sizeof(a)/sizeof(a[0]));
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}
@ -53,6 +55,7 @@ int main()
P(2)
};
C c(a, a + sizeof(a)/sizeof(a[0]));
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}

View File

@ -13,11 +13,12 @@
// class Alloc = allocator<Value>>
// class unordered_set
// void clear()
// void clear() noexcept;
#include <unordered_set>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main()
@ -35,6 +36,7 @@ int main()
P(2)
};
C c(a, a + sizeof(a)/sizeof(a[0]));
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}
@ -52,6 +54,7 @@ int main()
P(2)
};
C c(a, a + sizeof(a)/sizeof(a[0]));
ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}