Commit ce65509a authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

Only exclude const-qualified char pointers.

String literals cannot be used to initialize *non-const* fields - such
usage would trigger the following warning: ISO C++11 does not allow
conversion from string literal to 'char *' [-Wwritable-strings].

Because of the above, this CL ensures makes a change to include in the
rewrite the fields below:
      char* char_ptr;
      wchar_t* wide_char_ptr;
while continuing to exclude the fields below:
      const char* const_char_ptr;
      const wchar_t* const_wide_char_ptr;

Bug: 1069567
Change-Id: Id660806c9e947220644b1ad10b083eeebaae36e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2283771
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarBartek Nowierski <bartekn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786549}
parent 6bb7033a
...@@ -988,9 +988,10 @@ int main(int argc, const char* argv[]) { ...@@ -988,9 +988,10 @@ int main(int argc, const char* argv[]) {
// See the doc comment for the anyCharType matcher // See the doc comment for the anyCharType matcher
// and the testcases in tests/gen-char-test.cc. // and the testcases in tests/gen-char-test.cc.
auto char_ptr_field_decl_matcher = fieldDecl(allOf( auto char_ptr_field_decl_matcher = fieldDecl(allOf(
field_decl_matcher, hasType(pointerType(pointee( field_decl_matcher,
hasUnqualifiedDesugaredType(anyCharType())))))); hasType(pointerType(pointee(qualType(allOf(
FilteredExprWriter char_ptr_field_decl_writer(&output_helper, "char"); isConstQualified(), hasUnqualifiedDesugaredType(anyCharType()))))))));
FilteredExprWriter char_ptr_field_decl_writer(&output_helper, "const-char");
match_finder.addMatcher(char_ptr_field_decl_matcher, match_finder.addMatcher(char_ptr_field_decl_matcher,
&char_ptr_field_decl_writer); &char_ptr_field_decl_writer);
......
==== BEGIN EDITS ==== ==== BEGIN EDITS ====
include-user-header:::gen-char-actual.cc:::-1:::-1:::base/memory/checked_ptr.h include-user-header:::gen-char-actual.cc:::-1:::-1:::base/memory/checked_ptr.h
r:::gen-char-actual.cc:::1343:::6:::CheckedPtr<char> r:::gen-char-actual.cc:::1478:::12:::CheckedPtr<const char>
r:::gen-char-actual.cc:::1361:::12:::CheckedPtr<const char> r:::gen-char-actual.cc:::1508:::15:::CheckedPtr<const wchar_t>
r:::gen-char-actual.cc:::1391:::9:::CheckedPtr<wchar_t> r:::gen-char-actual.cc:::1995:::6:::CheckedPtr<char>
r:::gen-char-actual.cc:::1417:::15:::CheckedPtr<const wchar_t> r:::gen-char-actual.cc:::2013:::9:::CheckedPtr<wchar_t>
==== END EDITS ==== ==== END EDITS ====
==== BEGIN FIELD FILTERS ==== ==== BEGIN FIELD FILTERS ====
MyStruct::char_ptr # char MyStruct::const_char_ptr # const-char
MyStruct::const_char_ptr # char MyStruct::const_wide_char_ptr # const-char
MyStruct::const_wide_char_ptr # char
MyStruct::wide_char_ptr # char
==== END FIELD FILTERS ==== ==== END FIELD FILTERS ====
...@@ -15,8 +15,9 @@ ...@@ -15,8 +15,9 @@
struct MyStruct { struct MyStruct {
// Chromium is built with a warning/error that there are no user-defined // Chromium is built with a warning/error that there are no user-defined
// constructors invoked when initializing global-scoped values. // constructors invoked when initializing global-scoped values.
// CheckedPtr<char> conversion might trigger a global constructor for string // CheckedPtr<char> conversion might trigger a global constructor call when a
// literals: // pointer field is initialized with a non-null value. This frequently
// happens when initializing |const char*| fields with a string literal:
// struct MyStruct { // struct MyStruct {
// int foo; // int foo;
// CheckedPtr<const char> bar; // CheckedPtr<const char> bar;
...@@ -26,8 +27,16 @@ struct MyStruct { ...@@ -26,8 +27,16 @@ struct MyStruct {
// Because of the above, we have a heuristic for all fields that point to a // Because of the above, we have a heuristic for all fields that point to a
// char-like type - the heuristic causes such fields to be emitted as // char-like type - the heuristic causes such fields to be emitted as
// candidates for the --field-filter-file. // candidates for the --field-filter-file.
char* char_ptr;
const char* const_char_ptr; const char* const_char_ptr;
wchar_t* wide_char_ptr;
const wchar_t* const_wide_char_ptr; const wchar_t* const_wide_char_ptr;
// String literals cannot be used to initialize non-const fields - such usage
// would trigger the following warning: ISO C++11 does not allow conversion
// from string literal to 'char *' [-Wwritable-strings].
//
// Because of the above, we want to exclude non-const char pointers from the
// heuristic that excludes such fields from the rewrite. Avoiding the
// double-negative: we want to include the fields below in the rewrite.
char* char_ptr;
wchar_t* wide_char_ptr;
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment