From ee728f88304756c286e5e425d06c82bbc4d16155 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Thu, 1 Sep 2016 08:00:28 +0000 Subject: [PATCH] [LLVM/Support] - Create no-arguments constructor for llvm::Regex This is useful when need to defer the construction, e.g. using Regex as a member of class. Differential revision: https://reviews.llvm.org/D24101 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280339 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Regex.cpp | 2 ++ unittests/Support/RegexTest.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/Support/Regex.cpp b/lib/Support/Regex.cpp index e8344ef74d9..60ce528e577 100644 --- a/lib/Support/Regex.cpp +++ b/lib/Support/Regex.cpp @@ -19,6 +19,8 @@ #include using namespace llvm; +Regex::Regex() : error(REG_BADPAT), preg(nullptr) {} + Regex::Regex(StringRef regex, unsigned Flags) { unsigned flags = 0; preg = new llvm_regex(); diff --git a/unittests/Support/RegexTest.cpp b/unittests/Support/RegexTest.cpp index c045c49bc3d..7b61a03dd9b 100644 --- a/unittests/Support/RegexTest.cpp +++ b/unittests/Support/RegexTest.cpp @@ -153,4 +153,13 @@ TEST_F(RegexTest, MoveAssign) { EXPECT_TRUE(r2.match("916")); } +TEST_F(RegexTest, NoArgConstructor) { + std::string Error; + Regex r1; + EXPECT_FALSE(r1.isValid(Error)); + EXPECT_EQ("invalid regular expression", Error); + r1 = Regex("abc"); + EXPECT_TRUE(r1.isValid(Error)); +} + }