[cfe-commits] [libcxx] r121282 - in /libcxx/trunk: include/regex test/re/re.results/re.results.state/ready.pass.cpp test/re/re.submatch/re.submatch.members/default.pass.cpp
Howard Hinnant
hhinnant at apple.com
Wed Dec 8 13:07:55 PST 2010
Author: hhinnant
Date: Wed Dec 8 15:07:55 2010
New Revision: 121282
URL: http://llvm.org/viewvc/llvm-project?rev=121282&view=rev
Log:
N3158 Missing preconditions for default-constructed match_result objects
Added:
libcxx/trunk/test/re/re.results/re.results.state/ready.pass.cpp
libcxx/trunk/test/re/re.submatch/re.submatch.members/default.pass.cpp
Modified:
libcxx/trunk/include/regex
Modified: libcxx/trunk/include/regex
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=121282&r1=121281&r2=121282&view=diff
==============================================================================
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Wed Dec 8 15:07:55 2010
@@ -208,6 +208,8 @@
bool matched;
+ constexpr sub_match();
+
difference_type length() const;
operator string_type() const;
string_type str() const;
@@ -452,6 +454,8 @@
match_results& operator=(match_results&& m);
~match_results();
+ bool ready() const;
+
// size:
size_type size() const;
size_type max_size() const;
@@ -4684,6 +4688,9 @@
bool matched;
_LIBCPP_INLINE_VISIBILITY
+ /*constexpr*/ sub_match() : matched() {}
+
+ _LIBCPP_INLINE_VISIBILITY
difference_type length() const
{return matched ? _STD::distance(this->first, this->second) : 0;}
_LIBCPP_INLINE_VISIBILITY
@@ -5104,6 +5111,7 @@
value_type __unmatched_;
value_type __prefix_;
value_type __suffix_;
+ bool __ready_;
public:
_BidirectionalIterator __position_start_;
typedef const value_type& const_reference;
@@ -5123,6 +5131,9 @@
// match_results& operator=(match_results&& __m) = default;
// ~match_results() = default;
+ _LIBCPP_INLINE_VISIBILITY
+ bool ready() const {return __ready_;}
+
// size:
_LIBCPP_INLINE_VISIBILITY
size_type size() const {return __matches_.size();}
@@ -5224,6 +5235,7 @@
__suffix_.matched = __m.suffix().matched;
if (!__no_update_pos)
__position_start_ = __prefix_.first;
+ __ready_ = __m.ready();
}
private:
@@ -5254,7 +5266,8 @@
__unmatched_(),
__prefix_(),
__suffix_(),
- __position_start_()
+ __position_start_(),
+ __ready_(false)
{
}
@@ -5274,6 +5287,7 @@
__suffix_ = __unmatched_;
if (!__no_update_pos)
__position_start_ = __prefix_.first;
+ __ready_ = true;
}
template <class _BidirectionalIterator, class _Allocator>
@@ -5379,6 +5393,7 @@
swap(__prefix_, __m.__prefix_);
swap(__suffix_, __m.__suffix_);
swap(__position_start_, __m.__position_start_);
+ swap(__ready_, __m.__ready_);
}
typedef match_results<const char*> cmatch;
@@ -5391,10 +5406,13 @@
operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
const match_results<_BidirectionalIterator, _Allocator>& __y)
{
+ if (__x.__ready_ != __y.__ready_)
+ return false;
+ if (!__x.__ready_)
+ return true;
return __x.__matches_ == __y.__matches_ &&
__x.__prefix_ == __y.__prefix_ &&
- __x.__suffix_ == __y.__suffix_ &&
- __x.__position_start_ == __y.__position_start_;
+ __x.__suffix_ == __y.__suffix_;
}
template <class _BidirectionalIterator, class _Allocator>
Added: libcxx/trunk/test/re/re.results/re.results.state/ready.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.results/re.results.state/ready.pass.cpp?rev=121282&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.results/re.results.state/ready.pass.cpp (added)
+++ libcxx/trunk/test/re/re.results/re.results.state/ready.pass.cpp Wed Dec 8 15:07:55 2010
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// bool ready() const;
+
+#include <regex>
+#include <cassert>
+
+void
+test1()
+{
+ std::match_results<const char*> m;
+ const char s[] = "abcdefghijk";
+ assert(m.ready() == false);
+ std::regex_search(s, m, std::regex("cd((e)fg)hi"));
+ assert(m.ready() == true);
+}
+
+void
+test2()
+{
+ std::match_results<const char*> m;
+ const char s[] = "abcdefghijk";
+ assert(m.ready() == false);
+ std::regex_search(s, m, std::regex("z"));
+ assert(m.ready() == true);
+}
+
+int main()
+{
+ test1();
+ test2();
+}
Added: libcxx/trunk/test/re/re.submatch/re.submatch.members/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.submatch/re.submatch.members/default.pass.cpp?rev=121282&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.submatch/re.submatch.members/default.pass.cpp (added)
+++ libcxx/trunk/test/re/re.submatch/re.submatch.members/default.pass.cpp Wed Dec 8 15:07:55 2010
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator> class sub_match;
+
+// constexpr sub_match();
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef char CharT;
+ typedef std::sub_match<const CharT*> SM;
+ SM sm;
+ assert(sm.matched == false);
+ }
+ {
+ typedef wchar_t CharT;
+ typedef std::sub_match<const CharT*> SM;
+ SM sm;
+ assert(sm.matched == false);
+ }
+}
More information about the cfe-commits
mailing list