<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 9, 2014 at 3:32 PM, Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> writes:<br>
> Author: dblaikie<br>
> Date: Tue Sep  2 13:13:54 2014<br>
> New Revision: 216925<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=216925&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=216925&view=rev</a><br>
> Log:<br>
> unique_ptrify the result of SpecialCaseList::create<br>
><br>
> Modified:<br>
>     llvm/trunk/include/llvm/Support/SpecialCaseList.h<br>
>     llvm/trunk/lib/Support/SpecialCaseList.cpp<br>
>     llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp<br>
>     llvm/trunk/unittests/Support/SpecialCaseListTest.cpp<br>
><br>
> Modified: llvm/trunk/include/llvm/Support/SpecialCaseList.h<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/SpecialCaseList.h?rev=216925&r1=216924&r2=216925&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/SpecialCaseList.h?rev=216925&r1=216924&r2=216925&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Support/SpecialCaseList.h (original)<br>
> +++ llvm/trunk/include/llvm/Support/SpecialCaseList.h Tue Sep  2 13:13:54 2014<br>
> @@ -60,13 +60,15 @@ class SpecialCaseList {<br>
>    /// Parses the special case list from a file. If Path is empty, returns<br>
>    /// an empty special case list. On failure, returns 0 and writes an error<br>
>    /// message to string.<br>
> -  static SpecialCaseList *create(StringRef Path, std::string &Error);<br>
> +   static std::unique_ptr<SpecialCaseList> create(StringRef Path,<br>
> +                                                  std::string &Error);<br>
>    /// Parses the special case list from a memory buffer. On failure, returns<br>
>    /// 0 and writes an error message to string.<br>
> -  static SpecialCaseList *create(const MemoryBuffer *MB, std::string &Error);<br>
> +   static std::unique_ptr<SpecialCaseList> create(const MemoryBuffer *MB,<br>
> +                                                  std::string &Error);<br>
>    /// Parses the special case list from a file. On failure, reports a fatal<br>
>    /// error.<br>
> -  static SpecialCaseList *createOrDie(StringRef Path);<br>
> +   static std::unique_ptr<SpecialCaseList> createOrDie(StringRef Path);<br>
<br>
</div></div>Something funny happened to the whitespace here.<br></blockquote><div><br></div><div>Thanks for the catch - the one-space-indented access specifier threw clang-format off. Fixed in r217837.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span class=""><br>
><br>
>    ~SpecialCaseList();<br>
><br>
><br>
> Modified: llvm/trunk/lib/Support/SpecialCaseList.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SpecialCaseList.cpp?rev=216925&r1=216924&r2=216925&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SpecialCaseList.cpp?rev=216925&r1=216924&r2=216925&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Support/SpecialCaseList.cpp (original)<br>
> +++ llvm/trunk/lib/Support/SpecialCaseList.cpp Tue Sep  2 13:13:54 2014<br>
> @@ -48,9 +48,10 @@ struct SpecialCaseList::Entry {<br>
><br>
>  SpecialCaseList::SpecialCaseList() : Entries() {}<br>
><br>
> -SpecialCaseList *SpecialCaseList::create(StringRef Path, std::string &Error) {<br>
> +std::unique_ptr<SpecialCaseList> SpecialCaseList::create(StringRef Path,<br>
> +                                                         std::string &Error) {<br>
>    if (Path.empty())<br>
> -    return new SpecialCaseList();<br>
> +    return std::unique_ptr<SpecialCaseList>(new SpecialCaseList());<br>
<br>
</span>make_unique?<br></blockquote><div><br></div><div>Unfortunately not - SpecialCaseList's ctor is private, so make_unique cannot call it. This is common in factory functions/'named constructors' like this one.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5"><br>
>    ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =<br>
>        MemoryBuffer::getFile(Path);<br>
>    if (std::error_code EC = FileOrErr.getError()) {<br>
> @@ -60,17 +61,17 @@ SpecialCaseList *SpecialCaseList::create<br>
>    return create(FileOrErr.get().get(), Error);<br>
>  }<br>
><br>
> -SpecialCaseList *SpecialCaseList::create(<br>
> -    const MemoryBuffer *MB, std::string &Error) {<br>
> +std::unique_ptr<SpecialCaseList> SpecialCaseList::create(const MemoryBuffer *MB,<br>
> +                                                         std::string &Error) {<br>
>    std::unique_ptr<SpecialCaseList> SCL(new SpecialCaseList());<br>
>    if (!SCL->parse(MB, Error))<br>
>      return nullptr;<br>
> -  return SCL.release();<br>
> +  return SCL;<br>
>  }<br>
><br>
> -SpecialCaseList *SpecialCaseList::createOrDie(StringRef Path) {<br>
> +std::unique_ptr<SpecialCaseList> SpecialCaseList::createOrDie(StringRef Path) {<br>
>    std::string Error;<br>
> -  if (SpecialCaseList *SCL = create(Path, Error))<br>
> +  if (auto SCL = create(Path, Error))<br>
>      return SCL;<br>
>    report_fatal_error(Error);<br>
>  }<br>
><br>
> Modified: llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp?rev=216925&r1=216924&r2=216925&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp?rev=216925&r1=216924&r2=216925&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp Tue Sep  2 13:13:54 2014<br>
> @@ -139,7 +139,7 @@ class DFSanABIList {<br>
>    std::unique_ptr<SpecialCaseList> SCL;<br>
><br>
>   public:<br>
> -  DFSanABIList(SpecialCaseList *SCL) : SCL(SCL) {}<br>
> +   DFSanABIList(std::unique_ptr<SpecialCaseList> SCL) : SCL(std::move(SCL)) {}<br>
><br>
>    /// Returns whether either this function or its source file are listed in the<br>
>    /// given category.<br>
><br>
> Modified: llvm/trunk/unittests/Support/SpecialCaseListTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/SpecialCaseListTest.cpp?rev=216925&r1=216924&r2=216925&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/SpecialCaseListTest.cpp?rev=216925&r1=216924&r2=216925&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/unittests/Support/SpecialCaseListTest.cpp (original)<br>
> +++ llvm/trunk/unittests/Support/SpecialCaseListTest.cpp Tue Sep  2 13:13:54 2014<br>
> @@ -17,14 +17,15 @@ namespace {<br>
><br>
>  class SpecialCaseListTest : public ::testing::Test {<br>
>  protected:<br>
> -  SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) {<br>
> +  std::unique_ptr<SpecialCaseList> makeSpecialCaseList(StringRef List,<br>
> +                                                       std::string &Error) {<br>
>      std::unique_ptr<MemoryBuffer> MB = MemoryBuffer::getMemBuffer(List);<br>
>      return SpecialCaseList::create(MB.get(), Error);<br>
>    }<br>
><br>
> -  SpecialCaseList *makeSpecialCaseList(StringRef List) {<br>
> +  std::unique_ptr<SpecialCaseList> makeSpecialCaseList(StringRef List) {<br>
>      std::string Error;<br>
> -    SpecialCaseList *SCL = makeSpecialCaseList(List, Error);<br>
> +    auto SCL = makeSpecialCaseList(List, Error);<br>
>      assert(SCL);<br>
>      assert(Error == "");<br>
>      return SCL;<br>
> @@ -32,13 +33,13 @@ protected:<br>
>  };<br>
><br>
>  TEST_F(SpecialCaseListTest, Basic) {<br>
> -  std::unique_ptr<SpecialCaseList> SCL(<br>
> +  std::unique_ptr<SpecialCaseList> SCL =<br>
>        makeSpecialCaseList("# This is a comment.\n"<br>
>                            "\n"<br>
>                            "src:hello\n"<br>
>                            "src:bye\n"<br>
>                            "src:hi=category\n"<br>
> -                          "src:z*=category\n"));<br>
> +                          "src:z*=category\n");<br>
>    EXPECT_TRUE(SCL->inSection("src", "hello"));<br>
>    EXPECT_TRUE(SCL->inSection("src", "bye"));<br>
>    EXPECT_TRUE(SCL->inSection("src", "hi", "category"));<br>
> @@ -49,38 +50,38 @@ TEST_F(SpecialCaseListTest, Basic) {<br>
>  }<br>
><br>
>  TEST_F(SpecialCaseListTest, GlobalInitCompat) {<br>
> -  std::unique_ptr<SpecialCaseList> SCL(<br>
> -      makeSpecialCaseList("global:foo=init\n"));<br>
> +  std::unique_ptr<SpecialCaseList> SCL =<br>
> +      makeSpecialCaseList("global:foo=init\n");<br>
>    EXPECT_FALSE(SCL->inSection("global", "foo"));<br>
>    EXPECT_FALSE(SCL->inSection("global", "bar"));<br>
>    EXPECT_TRUE(SCL->inSection("global", "foo", "init"));<br>
>    EXPECT_FALSE(SCL->inSection("global", "bar", "init"));<br>
><br>
> -  SCL.reset(makeSpecialCaseList("global-init:foo\n"));<br>
> +  SCL = makeSpecialCaseList("global-init:foo\n");<br>
>    EXPECT_FALSE(SCL->inSection("global", "foo"));<br>
>    EXPECT_FALSE(SCL->inSection("global", "bar"));<br>
>    EXPECT_TRUE(SCL->inSection("global", "foo", "init"));<br>
>    EXPECT_FALSE(SCL->inSection("global", "bar", "init"));<br>
><br>
> -  SCL.reset(makeSpecialCaseList("type:t2=init\n"));<br>
> +  SCL = makeSpecialCaseList("type:t2=init\n");<br>
>    EXPECT_FALSE(SCL->inSection("type", "t1"));<br>
>    EXPECT_FALSE(SCL->inSection("type", "t2"));<br>
>    EXPECT_FALSE(SCL->inSection("type", "t1", "init"));<br>
>    EXPECT_TRUE(SCL->inSection("type", "t2", "init"));<br>
><br>
> -  SCL.reset(makeSpecialCaseList("global-init-type:t2\n"));<br>
> +  SCL = makeSpecialCaseList("global-init-type:t2\n");<br>
>    EXPECT_FALSE(SCL->inSection("type", "t1"));<br>
>    EXPECT_FALSE(SCL->inSection("type", "t2"));<br>
>    EXPECT_FALSE(SCL->inSection("type", "t1", "init"));<br>
>    EXPECT_TRUE(SCL->inSection("type", "t2", "init"));<br>
><br>
> -  SCL.reset(makeSpecialCaseList("src:hello=init\n"));<br>
> +  SCL = makeSpecialCaseList("src:hello=init\n");<br>
>    EXPECT_FALSE(SCL->inSection("src", "hello"));<br>
>    EXPECT_FALSE(SCL->inSection("src", "bye"));<br>
>    EXPECT_TRUE(SCL->inSection("src", "hello", "init"));<br>
>    EXPECT_FALSE(SCL->inSection("src", "bye", "init"));<br>
><br>
> -  SCL.reset(makeSpecialCaseList("global-init-src:hello\n"));<br>
> +  SCL = makeSpecialCaseList("global-init-src:hello\n");<br>
>    EXPECT_FALSE(SCL->inSection("src", "hello"));<br>
>    EXPECT_FALSE(SCL->inSection("src", "bye"));<br>
>    EXPECT_TRUE(SCL->inSection("src", "hello", "init"));<br>
> @@ -88,14 +89,14 @@ TEST_F(SpecialCaseListTest, GlobalInitCo<br>
>  }<br>
><br>
>  TEST_F(SpecialCaseListTest, Substring) {<br>
> -  std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList("src:hello\n"<br>
> -                                                           "fun:foo\n"<br>
> -                                                           "global:bar\n"));<br>
> +  std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("src:hello\n"<br>
> +                                                             "fun:foo\n"<br>
> +                                                             "global:bar\n");<br>
>    EXPECT_FALSE(SCL->inSection("src", "othello"));<br>
>    EXPECT_FALSE(SCL->inSection("fun", "tomfoolery"));<br>
>    EXPECT_FALSE(SCL->inSection("global", "bartender"));<br>
><br>
> -  SCL.reset(makeSpecialCaseList("fun:*foo*\n"));<br>
> +  SCL = makeSpecialCaseList("fun:*foo*\n");<br>
>    EXPECT_TRUE(SCL->inSection("fun", "tomfoolery"));<br>
>    EXPECT_TRUE(SCL->inSection("fun", "foobar"));<br>
>  }<br>
> @@ -117,7 +118,7 @@ TEST_F(SpecialCaseListTest, InvalidSpeci<br>
>  }<br>
><br>
>  TEST_F(SpecialCaseListTest, EmptySpecialCaseList) {<br>
> -  std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList(""));<br>
> +  std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("");<br>
>    EXPECT_FALSE(SCL->inSection("foo", "bar"));<br>
>  }<br>
><br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div></div>