[PATCH] D24101: [LLVM/Support] - Create no-arguments constructor for llvm::Regex

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 31 14:26:06 PDT 2016


How are you going to use this in LLD?

On Wed, Aug 31, 2016 at 2:18 PM, George Rimar <grimar at accesssoftek.com>
wrote:

> grimar created this revision.
> grimar added reviewers: rafael, dblaikie, ruiu, davide.
> grimar added subscribers: llvm-commits, grimar.
>
> This is useful when need to defer the construction,
> e.g. using Regex as a member of class.
>
> https://reviews.llvm.org/D24101
>
> Files:
>   include/llvm/Support/Regex.h
>   lib/Support/Regex.cpp
>   unittests/Support/RegexTest.cpp
>
> Index: unittests/Support/RegexTest.cpp
> ===================================================================
> --- unittests/Support/RegexTest.cpp
> +++ unittests/Support/RegexTest.cpp
> @@ -100,7 +100,7 @@
>
>    EXPECT_EQ("aber", Regex("[0-9]+").sub("\\", "a1234ber", &Error));
>    EXPECT_EQ(Error, "replacement string contained trailing backslash");
> -
> +
>    // Backreferences
>    EXPECT_EQ("aa1234bber", Regex("a[0-9]+b").sub("a\\0b", "a1234ber",
> &Error));
>    EXPECT_EQ("", Error);
> @@ -153,4 +153,13 @@
>    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));
> +}
> +
>  }
> Index: lib/Support/Regex.cpp
> ===================================================================
> --- lib/Support/Regex.cpp
> +++ lib/Support/Regex.cpp
> @@ -19,6 +19,8 @@
>  #include <string>
>  using namespace llvm;
>
> +Regex::Regex() : error(REG_BADPAT), preg(nullptr) {}
> +
>  Regex::Regex(StringRef regex, unsigned Flags) {
>    unsigned flags = 0;
>    preg = new llvm_regex();
> Index: include/llvm/Support/Regex.h
> ===================================================================
> --- include/llvm/Support/Regex.h
> +++ include/llvm/Support/Regex.h
> @@ -43,6 +43,7 @@
>        BasicRegex=4
>      };
>
> +    Regex();
>      /// Compiles the given regular expression \p Regex.
>      Regex(StringRef Regex, unsigned Flags = NoFlags);
>      Regex(const Regex &) = delete;
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160831/eb072c56/attachment.html>


More information about the llvm-commits mailing list