Skip to content

Commit

Permalink
Merged master:1b749c0cb5c0 into amd-gfx:b0c49b5d37c9
Browse files Browse the repository at this point in the history
Local branch amd-gfx b0c49b5 Merged master:6af81ea1d6d3 into amd-gfx:3a41fc55fff6
Remote branch master 1b749c0 [flang][driver] Remove unnecessary CMake dependencies (nfc)
  • Loading branch information
Sw authored and Sw committed Nov 20, 2020
2 parents b0c49b5 + 1b749c0 commit dfe1411
Show file tree
Hide file tree
Showing 108 changed files with 8,282 additions and 1,519 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace clang {
namespace tidy {
namespace readability {

const char DefaultStringNames[] = "::std::basic_string";
const char DefaultStringNames[] =
"::std::basic_string_view;::std::basic_string";

static ast_matchers::internal::Matcher<NamedDecl>
hasAnyNameStdString(std::vector<std::string> Names) {
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ Changes in existing checks
- Removed `google-runtime-references` check because the rule it checks does
not exist in the Google Style Guide anymore.

- Improved :doc:`readability-redundant-string-init
<clang-tidy/checks/readability-redundant-string-init>` check.

Added `std::basic_string_view` to default list of ``string``-like types.

Improvements to include-fixer
-----------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ Examples
std::string a;
std::string b;

// Initializing a string_view with an empty string literal produces an
// instance that compares equal to string_view().
std::string_view a = "";
std::string_view b("");

// becomes
std::string_view a;
std::string_view b;

Options
-------

.. option:: StringNames

Default is `::std::basic_string`.
Default is `::std::basic_string;::std::basic_string_view`.

Semicolon-delimited list of class names to apply this check to.
By default `::std::basic_string` applies to ``std::string`` and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %check_clang_tidy -std=c++11,c++14 %s readability-redundant-string-init %t \
// RUN: -config="{CheckOptions: \
// RUN: [{key: readability-redundant-string-init.StringNames, \
// RUN: value: '::std::basic_string;our::TestString'}] \
// RUN: value: '::std::basic_string;::std::basic_string_view;our::TestString'}] \
// RUN: }"
// FIXME: Fix the checker to work in C++17 mode.

Expand All @@ -19,6 +19,20 @@ struct basic_string {
};
typedef basic_string<char> string;
typedef basic_string<wchar_t> wstring;

template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C>>
struct basic_string_view {
using size_type = decltype(sizeof(0));

basic_string_view();
basic_string_view(const basic_string_view &);
basic_string_view(const C *, size_type);
basic_string_view(const C *);
template <class It, class End>
basic_string_view(It, End);
};
typedef basic_string_view<char> string_view;
typedef basic_string_view<wchar_t> wstring_view;
}

void f() {
Expand Down Expand Up @@ -48,6 +62,33 @@ void f() {
std::string z;
}

void fview() {
std::string_view a = "";
// CHECK-MESSAGES: [[@LINE-1]]:20: warning: redundant string initialization [readability-redundant-string-init]
// CHECK-FIXES: std::string_view a;
std::string_view b("");
// CHECK-MESSAGES: [[@LINE-1]]:20: warning: redundant string initialization
// CHECK-FIXES: std::string_view b;
std::string_view c = R"()";
// CHECK-MESSAGES: [[@LINE-1]]:20: warning: redundant string initialization
// CHECK-FIXES: std::string_view c;
std::string_view d(R"()");
// CHECK-MESSAGES: [[@LINE-1]]:20: warning: redundant string initialization
// CHECK-FIXES: std::string_view d;
std::string_view e{""};
// CHECK-MESSAGES: [[@LINE-1]]:20: warning: redundant string initialization
// CHECK-FIXES: std::string_view e;
std::string_view f = {""};
// CHECK-MESSAGES: [[@LINE-1]]:20: warning: redundant string initialization
// CHECK-FIXES: std::string_view f;

std::string_view u = "u";
std::string_view w("w");
std::string_view x = R"(x)";
std::string_view y(R"(y)");
std::string_view z;
}

void g() {
std::wstring a = L"";
// CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
Expand All @@ -69,6 +110,33 @@ void g() {
std::wstring z;
}

void gview() {
std::wstring_view a = L"";
// CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization [readability-redundant-string-init]
// CHECK-FIXES: std::wstring_view a;
std::wstring_view b(L"");
// CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization
// CHECK-FIXES: std::wstring_view b;
std::wstring_view c = L"";
// CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization
// CHECK-FIXES: std::wstring_view c;
std::wstring_view d(L"");
// CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization
// CHECK-FIXES: std::wstring_view d;
std::wstring_view e{L""};
// CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization
// CHECK-FIXES: std::wstring_view e;
std::wstring_view f = {L""};
// CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization
// CHECK-FIXES: std::wstring_view f;

std::wstring_view u = L"u";
std::wstring_view w(L"w");
std::wstring_view x = LR"(x)";
std::wstring_view y(LR"(y)");
std::wstring_view z;
}

template <typename T>
void templ() {
std::string s = "";
Expand Down Expand Up @@ -274,7 +342,6 @@ class Foo {
// CHECK-MESSAGES: [[@LINE-2]]:23: warning: redundant string initialization
// CHECK-FIXES: Foo(float) {}


// Check how it handles removing some redundant initializers while leaving
// valid initializers intact.
Foo(std::string Arg) : A(Arg), B(""), C("NonEmpty"), D(R"()"), E("") {}
Expand Down
Loading

0 comments on commit dfe1411

Please sign in to comment.