Title: [249906] trunk/Tools
Revision
249906
Author
[email protected]
Date
2019-09-16 10:44:48 -0700 (Mon, 16 Sep 2019)

Log Message

check-webkit-style: Fix warning message for std::make_unique<typename[]>
<https://webkit.org/b/201818>

Reviewed by Darin Adler.

* Scripts/webkitpy/style/checkers/cpp.py:
(check_wtf_make_unique): Emit different error message when using
std::make_unique<>() to create an array.  Personalize the error
message by including the original type name, which also
demonstrates that WTF::makeUniqueArray<>() does not need square
brackets for its typename.
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(WebKitStyleTest.test_wtf_make_unique): Add test.
(WebKitStyleTest.test_wtf_make_unique_array): Ditto.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (249905 => 249906)


--- trunk/Tools/ChangeLog	2019-09-16 17:30:19 UTC (rev 249905)
+++ trunk/Tools/ChangeLog	2019-09-16 17:44:48 UTC (rev 249906)
@@ -1,3 +1,20 @@
+2019-09-16  David Kilzer  <[email protected]>
+
+        check-webkit-style: Fix warning message for std::make_unique<typename[]>
+        <https://webkit.org/b/201818>
+
+        Reviewed by Darin Adler.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_wtf_make_unique): Emit different error message when using
+        std::make_unique<>() to create an array.  Personalize the error
+        message by including the original type name, which also
+        demonstrates that WTF::makeUniqueArray<>() does not need square
+        brackets for its typename.
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (WebKitStyleTest.test_wtf_make_unique): Add test.
+        (WebKitStyleTest.test_wtf_make_unique_array): Ditto.
+
 2019-09-16  Andres Gonzalez  <[email protected]>
 
         Rename [WebAccessibilityObjectWrapper _accessibilityInsertText] to accessibilityInsertText to match accessibility client.

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (249905 => 249906)


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2019-09-16 17:30:19 UTC (rev 249905)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2019-09-16 17:44:48 UTC (rev 249906)
@@ -2411,11 +2411,18 @@
 
     line = clean_lines.elided[line_number]  # Get rid of comments and strings.
 
-    using_std_make_unique = search(r'\bstd::make_unique\s*\<', line)
-    if not using_std_make_unique:
+    using_std_make_unique_search = search(r'\bstd::make_unique\s*<([^(]+)', line)
+    if not using_std_make_unique_search:
         return
 
-    error(line_number, 'runtime/wtf_make_unique', 4, "Use 'WTF::makeUnique<>' instead of 'std::make_unique<>'.")
+    typename = using_std_make_unique_search.group(1).strip()[:-1].strip()
+    if typename.endswith('[]'):
+        error(line_number, 'runtime/wtf_make_unique', 4,
+              "Use 'WTF::makeUniqueArray<{new_typename}>' instead of 'std::make_unique<{original_typename}>'.".format(
+                  new_typename=typename[:-2], original_typename=typename))
+    else:
+        error(line_number, 'runtime/wtf_make_unique', 4,
+              "Use 'WTF::makeUnique<{typename}>' instead of 'std::make_unique<{typename}>'.".format(typename=typename))
 
 
 def check_ctype_functions(clean_lines, line_number, file_state, error):

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (249905 => 249906)


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2019-09-16 17:30:19 UTC (rev 249905)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2019-09-16 17:44:48 UTC (rev 249906)
@@ -5217,6 +5217,42 @@
             '  [runtime/max_min_macros] [4]',
             'foo.h')
 
+    def test_wtf_make_unique(self):
+        self.assert_lint(
+             'std::unique_ptr<Foo> foo = WTF::makeUnique<Foo>();',
+             '',
+             'foo.cpp')
+
+        self.assert_lint(
+            'std::unique_ptr<Foo> foo = std::make_unique<Foo>();',
+            "Use 'WTF::makeUnique<Foo>' instead of 'std::make_unique<Foo>'."
+            "  [runtime/wtf_make_unique] [4]",
+            'foo.cpp')
+
+        self.assert_lint(
+            'std::unique_ptr<Foo> foo = std::make_unique<Foo>();',
+            "Use 'WTF::makeUnique<Foo>' instead of 'std::make_unique<Foo>'."
+            "  [runtime/wtf_make_unique] [4]",
+            'foo.mm')
+
+    def test_wtf_make_unique_array(self):
+        self.assert_lint(
+             'WTF::UniqueArray<uint32_t> array = WTF::makeUniqueArray<uint32_t>(10);',
+             '',
+             'foo.cpp')
+
+        self.assert_lint(
+            'std::unique_ptr<uint32_t[]> array = std::make_unique<uint32_t[]>(10);',
+            "Use 'WTF::makeUniqueArray<uint32_t>' instead of 'std::make_unique<uint32_t[]>'."
+            "  [runtime/wtf_make_unique] [4]",
+            'foo.cpp')
+
+        self.assert_lint(
+            'std::unique_ptr<uint32_t[]> array = std::make_unique<uint32_t[]>(10);',
+            "Use 'WTF::makeUniqueArray<uint32_t>' instead of 'std::make_unique<uint32_t[]>'."
+            "  [runtime/wtf_make_unique] [4]",
+            'foo.mm')
+
     def test_wtf_move(self):
         self.assert_lint(
              'A a = WTFMove(b);',
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to