llvm.org GIT mirror llvm / c265f06
Make llvm::Regex non-copyable but movable. Based on a patch by Maciej Piechotka. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198334 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 6 years ago
3 changed file(s) with 33 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
1616 #ifndef LLVM_SUPPORT_REGEX_H
1717 #define LLVM_SUPPORT_REGEX_H
1818
19 #include "llvm/Support/Compiler.h"
1920 #include
2021
2122 struct llvm_regex;
4445
4546 /// Compiles the given regular expression \p Regex.
4647 Regex(StringRef Regex, unsigned Flags = NoFlags);
48 Regex(const Regex &) LLVM_DELETED_FUNCTION;
49 Regex &operator=(Regex regex) {
50 std::swap(preg, regex.preg);
51 std::swap(error, regex.error);
52 return *this;
53 }
54 #if LLVM_HAS_RVALUE_REFERENCES
55 Regex(Regex &®ex) {
56 preg = regex.preg;
57 error = regex.error;
58 regex.preg = NULL;
59 }
60 #endif
4761 ~Regex();
4862
4963 /// isValid - returns the error encountered during regex compilation, or
3232 }
3333
3434 Regex::~Regex() {
35 llvm_regfree(preg);
36 delete preg;
35 if (preg) {
36 llvm_regfree(preg);
37 delete preg;
38 }
3739 }
3840
3941 bool Regex::isValid(std::string &Error) {
139139 EXPECT_EQ("invalid character range", Error);
140140 }
141141
142 #if LLVM_HAS_RVALUE_REFERENCES
143 TEST_F(RegexTest, MoveConstruct) {
144 Regex r1("^[0-9]+$");
145 Regex r2(std::move(r1));
146 EXPECT_TRUE(r2.match("916"));
142147 }
148
149 TEST_F(RegexTest, MoveAssign) {
150 Regex r1("^[0-9]+$");
151 Regex r2("abc");
152 r2 = std::move(r1);
153 EXPECT_TRUE(r2.match("916"));
154 }
155 #endif
156
157 }