Skip to content

Commit

Permalink
ui: Add another presubmit check to catch two more scoped_ptr usages.
Browse files Browse the repository at this point in the history
This should catch the following usages:

1- return scoped_ptr<T>(foo)
2- bar = scoped_ptr<T>(foo)

And recommend the solo usage of make_scoped_ptr().

The entries were found with the following command line:

$ git grep -E '(=|\breturn)\s*scoped_ptr<.*?>([^)]+)'

BUG=None
TEST=g cl presubmit -uv
R=sky@chromium.org,maruel@chromium.org

Review URL: https://codereview.chromium.org/919253002

Cr-Commit-Position: refs/heads/master@{#317669}
  • Loading branch information
tfarina authored and Commit bot committed Feb 23, 2015
1 parent 68c37ac commit 63f25be
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions ui/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
r'.*\.(cc|h|mm)$',
)


def CheckScopedPtr(input_api, output_api,
white_list=INCLUDE_CPP_FILES_ONLY, black_list=None):
black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
Expand All @@ -22,11 +23,22 @@ def CheckScopedPtr(input_api, output_api,
for f in input_api.AffectedSourceFiles(source_file_filter):
for line_number, line in f.ChangedContents():
# Disallow:
# return scoped_ptr<T>(foo);
# bar = scoped_ptr<T>(foo);
# But allow:
# return scoped_ptr<T[]>(foo);
# bar = scoped_ptr<T[]>(foo);
if input_api.re.search(
r'(=|\breturn)\s*scoped_ptr<[^\[\]>]+>\([^)]+\)', line):
errors.append(output_api.PresubmitError(
('%s:%d uses explicit scoped_ptr constructor. ' +
'Use make_scoped_ptr() instead.') % (f.LocalPath(), line_number)))
# Disallow:
# scoped_ptr<T>()
if input_api.re.search(r'\bscoped_ptr<.*?>\(\)', line):
if re.search(r'\bscoped_ptr<.*?>\(\)', line):
errors.append(output_api.PresubmitError(
'%s:%d uses scoped_ptr<T>(). Use nullptr instead.' %
(f.LocalPath(), line_number)))
'%s:%d uses scoped_ptr<T>(). Use nullptr instead.' %
(f.LocalPath(), line_number)))
return errors


Expand Down

0 comments on commit 63f25be

Please sign in to comment.