[libcxx-commits] [PATCH] D61192: [libcxx] Add precondition check before calling match_results.str() in tests.
Andrey Maksimov via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Apr 26 08:24:56 PDT 2019
amakc11 created this revision.
Herald added a reviewer: EricWF.
Herald added subscribers: libcxx-commits, ldionne.
The `match_results` constructor has the following postcondition <http://eel.is/c++draft/re.results#const-2>: "Ensures: `ready()` returns false". The `str()` method of this class has the following precondition <http://eel.is/c++draft/re.results#acc-5>: "Requires: `ready()` == true". However, some tests call `match_results.str()` right after the constructor without checking the above precondition. This patch fixes this bug in tests.
Repository:
rCXX libc++
https://reviews.llvm.org/D61192
Files:
test/std/re/re.results/re.results.all/get_allocator.pass.cpp
test/std/re/re.results/re.results.const/allocator.pass.cpp
test/std/re/re.results/re.results.const/copy.pass.cpp
test/std/re/re.results/re.results.const/copy_assign.pass.cpp
test/std/re/re.results/re.results.const/default.pass.cpp
test/std/re/re.results/re.results.const/move.pass.cpp
test/std/re/re.results/re.results.const/move_assign.pass.cpp
Index: test/std/re/re.results/re.results.const/move_assign.pass.cpp
===================================================================
--- test/std/re/re.results/re.results.const/move_assign.pass.cpp
+++ test/std/re/re.results/re.results.const/move_assign.pass.cpp
@@ -27,8 +27,8 @@
SM m1;
m1 = std::move(m0);
- assert(m1.size() == 0);
- assert(m1.str() == std::basic_string<CharT>());
+ assert(m1.size() == 0);
+ assert(!m1.ready() || m1.str() == std::basic_string<CharT>());
if (std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value)
assert(m1.get_allocator() == a);
else
Index: test/std/re/re.results/re.results.const/move.pass.cpp
===================================================================
--- test/std/re/re.results/re.results.const/move.pass.cpp
+++ test/std/re/re.results/re.results.const/move.pass.cpp
@@ -31,7 +31,7 @@
SM m1(std::move(m0));
assert(m1.size() == 0);
- assert(m1.str() == std::basic_string<CharT>());
+ assert(!m1.ready() || m1.str() == std::basic_string<CharT>());
assert(m1.get_allocator() == a);
}
Index: test/std/re/re.results/re.results.const/default.pass.cpp
===================================================================
--- test/std/re/re.results/re.results.const/default.pass.cpp
+++ test/std/re/re.results/re.results.const/default.pass.cpp
@@ -22,7 +22,7 @@
{
std::match_results<const CharT*> m;
assert(m.size() == 0);
- assert(m.str() == std::basic_string<CharT>());
+ assert(!m.ready() || m.str() == std::basic_string<CharT>());
assert(m.get_allocator() == std::allocator<std::sub_match<const CharT*> >());
}
Index: test/std/re/re.results/re.results.const/copy_assign.pass.cpp
===================================================================
--- test/std/re/re.results/re.results.const/copy_assign.pass.cpp
+++ test/std/re/re.results/re.results.const/copy_assign.pass.cpp
@@ -26,8 +26,8 @@
SM m1;
m1 = m0;
- assert(m1.size() == m0.size());
- assert(m1.str() == m0.str());
+ assert(m1.size() == m0.size());
+ assert(!m1.ready() || !m0.ready() || m1.str() == m0.str());
if (std::allocator_traits<Allocator>::propagate_on_container_copy_assignment::value)
assert(m1.get_allocator() == m0.get_allocator());
else
Index: test/std/re/re.results/re.results.const/copy.pass.cpp
===================================================================
--- test/std/re/re.results/re.results.const/copy.pass.cpp
+++ test/std/re/re.results/re.results.const/copy.pass.cpp
@@ -25,8 +25,8 @@
SM m0(a);
SM m1(m0);
- assert(m1.size() == m0.size());
- assert(m1.str() == m0.str());
+ assert(m1.size() == m0.size());
+ assert(!m1.ready() || !m0.ready() || m1.str() == m0.str());
assert(m1.get_allocator() == m0.get_allocator());
}
Index: test/std/re/re.results/re.results.const/allocator.pass.cpp
===================================================================
--- test/std/re/re.results/re.results.const/allocator.pass.cpp
+++ test/std/re/re.results/re.results.const/allocator.pass.cpp
@@ -24,7 +24,7 @@
{
std::match_results<const CharT*, Allocator> m(a);
assert(m.size() == 0);
- assert(m.str() == std::basic_string<CharT>());
+ assert(!m.ready() || m.str() == std::basic_string<CharT>());
assert(m.get_allocator() == a);
}
Index: test/std/re/re.results/re.results.all/get_allocator.pass.cpp
===================================================================
--- test/std/re/re.results/re.results.all/get_allocator.pass.cpp
+++ test/std/re/re.results/re.results.all/get_allocator.pass.cpp
@@ -24,7 +24,7 @@
{
std::match_results<const CharT*, Allocator> m(a);
assert(m.size() == 0);
- assert(m.str() == std::basic_string<CharT>());
+ assert(!m.ready() || m.str() == std::basic_string<CharT>());
assert(m.get_allocator() == a);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61192.196852.patch
Type: text/x-patch
Size: 3965 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190426/848a8e92/attachment.bin>
More information about the libcxx-commits
mailing list