forked from crosswalk-project/chromium-crosswalk
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools/clang: Add an error if auto deduces to be a pointer type.
This patch ensures that when auto is used, it is not deduced to be a pointer type, since that can lead to confusion when reading code. BUG=554600 Review-Url: https://codereview.chromium.org/1691113003 Cr-Commit-Position: refs/heads/master@{#398987}
- Loading branch information
Showing
7 changed files
with
163 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
class Foo {}; | ||
|
||
void f(); | ||
|
||
int main() { | ||
int integer; | ||
Foo foo; | ||
|
||
auto int_copy = integer; | ||
const auto const_int_copy = integer; | ||
const auto& const_int_ref = integer; | ||
|
||
auto raw_int_ptr = &integer; | ||
const auto const_raw_int_ptr = &integer; | ||
const auto& const_raw_int_ptr_ref = &integer; | ||
|
||
auto* raw_int_ptr_valid = &integer; | ||
const auto* const_raw_int_ptr_valid = &integer; | ||
|
||
auto raw_foo_ptr = &foo; | ||
const auto const_raw_foo_ptr = &foo; | ||
const auto& const_raw_foo_ptr_ref = &foo; | ||
|
||
auto* raw_foo_ptr_valid = &foo; | ||
const auto* const_raw_foo_ptr_valid = &foo; | ||
|
||
int *int_ptr; | ||
|
||
auto double_ptr_auto = &int_ptr; | ||
auto* double_ptr_auto_ptr = &int_ptr; | ||
auto** double_ptr_auto_double_ptr = &int_ptr; | ||
|
||
auto function_ptr = &f; | ||
|
||
int *const *const volatile **const *pointer_awesomeness; | ||
auto auto_awesome = pointer_awesomeness; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-Xclang -plugin-arg-find-bad-constructs -Xclang check-auto-raw-pointer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
auto_raw_pointer.cpp:17:3: warning: [chromium-style] auto variable type must not deduce to a raw pointer type. | ||
auto raw_int_ptr = &integer; | ||
^~~~ | ||
auto* | ||
auto_raw_pointer.cpp:18:3: warning: [chromium-style] auto variable type must not deduce to a raw pointer type. | ||
const auto const_raw_int_ptr = &integer; | ||
^~~~~~~~~~ | ||
auto* const | ||
auto_raw_pointer.cpp:19:3: warning: [chromium-style] auto variable type must not deduce to a raw pointer type. | ||
const auto& const_raw_int_ptr_ref = &integer; | ||
^~~~~~~~~~~ | ||
auto* const | ||
auto_raw_pointer.cpp:24:3: warning: [chromium-style] auto variable type must not deduce to a raw pointer type. | ||
auto raw_foo_ptr = &foo; | ||
^~~~ | ||
auto* | ||
auto_raw_pointer.cpp:25:3: warning: [chromium-style] auto variable type must not deduce to a raw pointer type. | ||
const auto const_raw_foo_ptr = &foo; | ||
^~~~~~~~~~ | ||
auto* const | ||
auto_raw_pointer.cpp:26:3: warning: [chromium-style] auto variable type must not deduce to a raw pointer type. | ||
const auto& const_raw_foo_ptr_ref = &foo; | ||
^~~~~~~~~~~ | ||
auto* const | ||
auto_raw_pointer.cpp:33:3: warning: [chromium-style] auto variable type must not deduce to a raw pointer type. | ||
auto double_ptr_auto = &int_ptr; | ||
^~~~ | ||
auto** | ||
auto_raw_pointer.cpp:34:3: warning: [chromium-style] auto variable type must not deduce to a raw pointer type. | ||
auto* double_ptr_auto_ptr = &int_ptr; | ||
^~~~~ | ||
auto** | ||
auto_raw_pointer.cpp:40:3: warning: [chromium-style] auto variable type must not deduce to a raw pointer type. | ||
auto auto_awesome = pointer_awesomeness; | ||
^~~~ | ||
auto* const* const volatile** const* | ||
9 warnings generated. |