[PATCH] D33385: __cxa_demangle: Fix constructor cv qualifier handling

2017-05-24 Thread Tamas Berghammer via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL303737: __cxa_demangle: Fix constructor cv qualifier 
handling (authored by tberghammer).

Changed prior to commit:
  https://reviews.llvm.org/D33385?vs=99694&id=100067#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33385

Files:
  libcxxabi/trunk/src/cxa_demangle.cpp
  libcxxabi/trunk/test/test_demangle.pass.cpp


Index: libcxxabi/trunk/test/test_demangle.pass.cpp
===
--- libcxxabi/trunk/test/test_demangle.pass.cpp
+++ libcxxabi/trunk/test/test_demangle.pass.cpp
@@ -29500,6 +29500,7 @@
 {"_ZZ2f6vE1b", "f6()::b"},
 {"_ZNV3$_35test9Ev", "$_3::test9() volatile"},
 {"_ZN5Test8I3$_2EC1ES0_", "Test8<$_2>::Test8($_2)"},
+{"_Z3fooIZN3BarC1EvE3$_0EvT_", "void 
foo(Bar::Bar()::$_0)"},
 {"_ZGVZN1N1gEvE1a", "guard variable for N::g()::a"},
 {"_ZplRK1YRA100_P1X", "operator+(Y const&, X* (&) [100])"},
 {"_Z1fno", "f(__int128, unsigned __int128)"},
Index: libcxxabi/trunk/src/cxa_demangle.cpp
===
--- libcxxabi/trunk/src/cxa_demangle.cpp
+++ libcxxabi/trunk/src/cxa_demangle.cpp
@@ -4571,6 +4571,8 @@
 save_value sb(db.tag_templates);
 if (db.encoding_depth > 1)
 db.tag_templates = true;
+save_value 
sp(db.parsed_ctor_dtor_cv);
+db.parsed_ctor_dtor_cv = false;
 switch (*first)
 {
 case 'G':


Index: libcxxabi/trunk/test/test_demangle.pass.cpp
===
--- libcxxabi/trunk/test/test_demangle.pass.cpp
+++ libcxxabi/trunk/test/test_demangle.pass.cpp
@@ -29500,6 +29500,7 @@
 {"_ZZ2f6vE1b", "f6()::b"},
 {"_ZNV3$_35test9Ev", "$_3::test9() volatile"},
 {"_ZN5Test8I3$_2EC1ES0_", "Test8<$_2>::Test8($_2)"},
+{"_Z3fooIZN3BarC1EvE3$_0EvT_", "void foo(Bar::Bar()::$_0)"},
 {"_ZGVZN1N1gEvE1a", "guard variable for N::g()::a"},
 {"_ZplRK1YRA100_P1X", "operator+(Y const&, X* (&) [100])"},
 {"_Z1fno", "f(__int128, unsigned __int128)"},
Index: libcxxabi/trunk/src/cxa_demangle.cpp
===
--- libcxxabi/trunk/src/cxa_demangle.cpp
+++ libcxxabi/trunk/src/cxa_demangle.cpp
@@ -4571,6 +4571,8 @@
 save_value sb(db.tag_templates);
 if (db.encoding_depth > 1)
 db.tag_templates = true;
+save_value sp(db.parsed_ctor_dtor_cv);
+db.parsed_ctor_dtor_cv = false;
 switch (*first)
 {
 case 'G':
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140018: [clang-tidy] Support std::string_view in readability-redundant-string-cstr

2023-01-02 Thread Tamas Berghammer via Phabricator via cfe-commits
tberghammer updated this revision to Diff 485853.
tberghammer added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140018/new/

https://reviews.llvm.org/D140018

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -48,6 +48,15 @@
 typedef basic_string, std::allocator> wstring;
 typedef basic_string, std::allocator> u16string;
 typedef basic_string, std::allocator> u32string;
+
+template 
+struct basic_string_view {
+  basic_string_view(const C* s);
+};
+typedef basic_string_view> string_view;
+typedef basic_string_view> wstring_view;
+typedef basic_string_view> u16string_view;
+typedef basic_string_view> u32string_view;
 }
 
 std::string operator+(const std::string&, const std::string&);
@@ -169,6 +178,15 @@
   tmp.insert(1, s);
   tmp.insert(1, s.c_str(), 2);
 }
+void f7(std::string_view sv) {
+  std::string s;
+  f7(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+  f7(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+}
 
 // Tests for std::wstring.
 
@@ -177,6 +195,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}g1(s);{{$}}
 }
+void g2(std::wstring_view sv) {
+  std::wstring s;
+  g2(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}g2(s);{{$}}
+  g2(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}g2(s);{{$}}
+}
 
 // Tests for std::u16string.
 
@@ -185,6 +212,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}h1(s);{{$}}
 }
+void h2(std::u16string_view sv) {
+  std::u16string s;
+  h2(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}h2(s);{{$}}
+  h2(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}h2(s);{{$}}
+}
 
 // Tests for std::u32string.
 
@@ -193,6 +229,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}k1(s);{{$}}
 }
+void k2(std::u32string_view sv) {
+  std::u32string s;
+  k2(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}k2(s);{{$}}
+  k2(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}k2(s);{{$}}
+}
 
 // Tests on similar classes that aren't good candidates for this checker.
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -204,6 +204,10 @@
   The check now skips concept definitions since redundant expressions still make sense
   inside them.
 
+- Support removing ``c_str`` calls from ``std::string_view`` constructor calls in
+  :doc: `readability-redundant-string-cstr `
+  check.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -86,6 +86,11 @@
   // be present explicitly.
   hasArgument(1, cxxDefaultArgExpr();
 
+  // Match string constructor.
+  const auto StringViewConstructorExpr = cxxConstructExpr(
+  argumentCountIs(1),
+  hasDeclaration(cxxMethodDecl(hasName("basic_string_view";
+
   // Match a call to the string 'c_str()' method.
   const auto StringCStrCallExpr =
   cxxMemberCallExpr(on(StringExpr.bind("arg")),
@@ -101,7 +106,8 @@
   traverse(
   TK_AsIs,
   cxxConstructExpr(
-  StringConstructorExpr, hasArgument(0, StringCStrCallExpr),
+  anyOf(StringConstructorExpr, Strin

[PATCH] D140018: [clang-tidy] Support std::string_view in readability-redundant-string-cstr

2023-01-02 Thread Tamas Berghammer via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf325b5b8cb1d: [clang-tidy] Support std::string_view in 
readability-redundant-string-cstr (authored by tberghammer).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140018/new/

https://reviews.llvm.org/D140018

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -48,6 +48,15 @@
 typedef basic_string, std::allocator> wstring;
 typedef basic_string, std::allocator> u16string;
 typedef basic_string, std::allocator> u32string;
+
+template 
+struct basic_string_view {
+  basic_string_view(const C* s);
+};
+typedef basic_string_view> string_view;
+typedef basic_string_view> wstring_view;
+typedef basic_string_view> u16string_view;
+typedef basic_string_view> u32string_view;
 }
 
 std::string operator+(const std::string&, const std::string&);
@@ -169,6 +178,15 @@
   tmp.insert(1, s);
   tmp.insert(1, s.c_str(), 2);
 }
+void f7(std::string_view sv) {
+  std::string s;
+  f7(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+  f7(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+}
 
 // Tests for std::wstring.
 
@@ -177,6 +195,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}g1(s);{{$}}
 }
+void g2(std::wstring_view sv) {
+  std::wstring s;
+  g2(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}g2(s);{{$}}
+  g2(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}g2(s);{{$}}
+}
 
 // Tests for std::u16string.
 
@@ -185,6 +212,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}h1(s);{{$}}
 }
+void h2(std::u16string_view sv) {
+  std::u16string s;
+  h2(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}h2(s);{{$}}
+  h2(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}h2(s);{{$}}
+}
 
 // Tests for std::u32string.
 
@@ -193,6 +229,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}k1(s);{{$}}
 }
+void k2(std::u32string_view sv) {
+  std::u32string s;
+  k2(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}k2(s);{{$}}
+  k2(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}k2(s);{{$}}
+}
 
 // Tests on similar classes that aren't good candidates for this checker.
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -204,6 +204,10 @@
   The check now skips concept definitions since redundant expressions still make sense
   inside them.
 
+- Support removing ``c_str`` calls from ``std::string_view`` constructor calls in
+  :doc: `readability-redundant-string-cstr `
+  check.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -86,6 +86,11 @@
   // be present explicitly.
   hasArgument(1, cxxDefaultArgExpr();
 
+  // Match string constructor.
+  const auto StringViewConstructorExpr = cxxConstructExpr(
+  argumentCountIs(1),
+  hasDeclaration(cxxMethodDecl(hasName("basic_string_view";
+
   // Match a call to the string 'c_str()' method.
   const auto StringCStrCallExpr =
   cxxMemberCallExpr(on(StringExpr.bind("arg")),
@@ -101,7 +106,8 @@
   trav

[PATCH] D140018: [clang-tidy] Support std::string_view in readability-redundant-string-cstr

2023-01-02 Thread Tamas Berghammer via Phabricator via cfe-commits
tberghammer added a comment.

Sorry, I was away during the holidays but just pushed the change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140018/new/

https://reviews.llvm.org/D140018

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39239: [AST] Incorrectly qualified unscoped enumeration as template actual parameter.

2017-10-30 Thread Tamas Berghammer via Phabricator via cfe-commits
tberghammer added a comment.

2 fairly random ideas without looking into it too much:

- Can you do a diff of the debug_info dump before and after your change? 
Understanding what have changed should give us a pretty good clue about the 
issue.
- My first guess is that after your change we emit DW_TAG_enumeration_type for 
scoped enums (what seems to be the correct thing to do) instead of something 
else (not sure what) and you have to update 
https://github.com/llvm-mirror/lldb/blob/master/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp#L1512
 to handle it correctly.


https://reviews.llvm.org/D39239



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39239: [AST] Incorrectly qualified unscoped enumeration as template actual parameter.

2017-11-02 Thread Tamas Berghammer via Phabricator via cfe-commits
tberghammer added a comment.

In https://reviews.llvm.org/D39239#911696, @CarlosAlbertoEnciso wrote:

> Hi Tamas,
>
> Thanks very much for your message.
>
> In https://reviews.llvm.org/D39239#910797, @tberghammer wrote:
>
> > - Can you do a diff of the debug_info dump before and after your change? 
> > Understanding what have changed should give us a pretty good clue about the 
> > issue.
>
>
> For this specific case, the debug_info is the same before and after my 
> change, as the patch affects only unscoped enums.


If this patch doesn't effect the debug info generated for this specific case 
then my guess is that when LLDB builds the EnumDecl for the scoped enumeration 
it will incorrectly build one for an unscoped enum instead. Looking at the code 
at 
https://github.com/llvm-mirror/lldb/blob/master/source/Symbol/ClangASTContext.cpp#L2170
 we even have a TODO in the LLDB to fix handling for this case. Can you try out 
your patch with https://reviews.llvm.org/D39545 what supposed to fix the 
problem on the LLDB side (haven't tested it at all)?


https://reviews.llvm.org/D39239



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39239: [AST] Incorrectly qualified unscoped enumeration as template actual parameter.

2017-11-04 Thread Tamas Berghammer via Phabricator via cfe-commits
tberghammer added a comment.

I verified that https://reviews.llvm.org/D39545 will be fixing the problem on 
the LLDB side (previously we had no proper scoped enum support in LLDB)


https://reviews.llvm.org/D39239



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140018: [clang-tidy] Support std::string_view in readability-redundant-string-cstr

2022-12-14 Thread Tamas Berghammer via Phabricator via cfe-commits
tberghammer created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
tberghammer requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Previously we were matching constructor calls for std::string and
llvm::StringRef and this change extends this set with including
std::string_view as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140018

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -48,6 +48,12 @@
 typedef basic_string, 
std::allocator> wstring;
 typedef basic_string, std::allocator> 
u16string;
 typedef basic_string, std::allocator> 
u32string;
+
+template 
+struct basic_string_view {
+  basic_string_view(const C* s);
+};
+typedef basic_string_view> string_view;
 }
 
 std::string operator+(const std::string&, const std::string&);
@@ -169,6 +175,15 @@
   tmp.insert(1, s);
   tmp.insert(1, s.c_str(), 2);
 }
+void f7(std::string_view sv) {
+  std::string s;
+  f7(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' 
[readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+  f7(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' 
[readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+}
 
 // Tests for std::wstring.
 
Index: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -86,6 +86,11 @@
   // be present explicitly.
   hasArgument(1, cxxDefaultArgExpr();
 
+  // Match string constructor.
+  const auto StringViewConstructorExpr = cxxConstructExpr(
+  argumentCountIs(1),
+  hasDeclaration(cxxMethodDecl(hasName("basic_string_view";
+
   // Match a call to the string 'c_str()' method.
   const auto StringCStrCallExpr =
   cxxMemberCallExpr(on(StringExpr.bind("arg")),
@@ -101,7 +106,8 @@
   traverse(
   TK_AsIs,
   cxxConstructExpr(
-  StringConstructorExpr, hasArgument(0, StringCStrCallExpr),
+  anyOf(StringConstructorExpr, StringViewConstructorExpr),
+  hasArgument(0, StringCStrCallExpr),
   unless(anyOf(HasRValueTempParent, hasParent(cxxBindTemporaryExpr(
 HasRValueTempParent)),
   this);


Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -48,6 +48,12 @@
 typedef basic_string, std::allocator> wstring;
 typedef basic_string, std::allocator> u16string;
 typedef basic_string, std::allocator> u32string;
+
+template 
+struct basic_string_view {
+  basic_string_view(const C* s);
+};
+typedef basic_string_view> string_view;
 }
 
 std::string operator+(const std::string&, const std::string&);
@@ -169,6 +175,15 @@
   tmp.insert(1, s);
   tmp.insert(1, s.c_str(), 2);
 }
+void f7(std::string_view sv) {
+  std::string s;
+  f7(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+  f7(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+}
 
 // Tests for std::wstring.
 
Index: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -86,6 +86,11 @@
   // be present explicitly.
   hasArgument(1, cxxDefaultArgExpr();
 
+  // Match string constructor.
+  const auto StringViewConstructorExpr = cxxConstructExpr(
+  argumentCountIs(1),
+  hasDeclaration(cxxMethodDecl(hasName("basic_string_view";
+
   // Match a call to the string 'c_str()' method.
   const auto StringCStrCallExpr =
   cxxMemberCallExpr(on(StringExpr.bind("arg")),
@@ -101,7 +106,8 @@
   traverse(
  

[PATCH] D140018: [clang-tidy] Support std::string_view in readability-redundant-string-cstr

2022-12-14 Thread Tamas Berghammer via Phabricator via cfe-commits
tberghammer updated this revision to Diff 482870.
tberghammer added a comment.

Add release notes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140018/new/

https://reviews.llvm.org/D140018

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -48,6 +48,12 @@
 typedef basic_string, 
std::allocator> wstring;
 typedef basic_string, std::allocator> 
u16string;
 typedef basic_string, std::allocator> 
u32string;
+
+template 
+struct basic_string_view {
+  basic_string_view(const C* s);
+};
+typedef basic_string_view> string_view;
 }
 
 std::string operator+(const std::string&, const std::string&);
@@ -169,6 +175,15 @@
   tmp.insert(1, s);
   tmp.insert(1, s.c_str(), 2);
 }
+void f7(std::string_view sv) {
+  std::string s;
+  f7(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' 
[readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+  f7(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' 
[readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+}
 
 // Tests for std::wstring.
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -201,6 +201,10 @@
   The check now skips concept definitions since redundant expressions still 
make sense
   inside them.
 
+- Support removing ``c_str`` calls from std::string_view constructor calls in
+  :doc: `readability-redundant-string-cstr 
`
+  check.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -86,6 +86,11 @@
   // be present explicitly.
   hasArgument(1, cxxDefaultArgExpr();
 
+  // Match string constructor.
+  const auto StringViewConstructorExpr = cxxConstructExpr(
+  argumentCountIs(1),
+  hasDeclaration(cxxMethodDecl(hasName("basic_string_view";
+
   // Match a call to the string 'c_str()' method.
   const auto StringCStrCallExpr =
   cxxMemberCallExpr(on(StringExpr.bind("arg")),
@@ -101,7 +106,8 @@
   traverse(
   TK_AsIs,
   cxxConstructExpr(
-  StringConstructorExpr, hasArgument(0, StringCStrCallExpr),
+  anyOf(StringConstructorExpr, StringViewConstructorExpr),
+  hasArgument(0, StringCStrCallExpr),
   unless(anyOf(HasRValueTempParent, hasParent(cxxBindTemporaryExpr(
 HasRValueTempParent)),
   this);


Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -48,6 +48,12 @@
 typedef basic_string, std::allocator> wstring;
 typedef basic_string, std::allocator> u16string;
 typedef basic_string, std::allocator> u32string;
+
+template 
+struct basic_string_view {
+  basic_string_view(const C* s);
+};
+typedef basic_string_view> string_view;
 }
 
 std::string operator+(const std::string&, const std::string&);
@@ -169,6 +175,15 @@
   tmp.insert(1, s);
   tmp.insert(1, s.c_str(), 2);
 }
+void f7(std::string_view sv) {
+  std::string s;
+  f7(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+  f7(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+}
 
 // Tests for std::wstring.
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -201,6 +201,10 @@
   The check now skips concept definitions since redundant expressions still make sense
   inside them.
 
+- Support removing ``c_str`` calls from std::string_view constructor calls in
+  :doc: `readability-redundant-string-cstr `
+  check.
+
 Removed checks
 ^^
 
Index

[PATCH] D140018: [clang-tidy] Support std::string_view in readability-redundant-string-cstr

2022-12-14 Thread Tamas Berghammer via Phabricator via cfe-commits
tberghammer updated this revision to Diff 482871.
tberghammer added a comment.

Fix formatting type in release notes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140018/new/

https://reviews.llvm.org/D140018

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -48,6 +48,12 @@
 typedef basic_string, 
std::allocator> wstring;
 typedef basic_string, std::allocator> 
u16string;
 typedef basic_string, std::allocator> 
u32string;
+
+template 
+struct basic_string_view {
+  basic_string_view(const C* s);
+};
+typedef basic_string_view> string_view;
 }
 
 std::string operator+(const std::string&, const std::string&);
@@ -169,6 +175,15 @@
   tmp.insert(1, s);
   tmp.insert(1, s.c_str(), 2);
 }
+void f7(std::string_view sv) {
+  std::string s;
+  f7(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' 
[readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+  f7(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' 
[readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+}
 
 // Tests for std::wstring.
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -201,6 +201,10 @@
   The check now skips concept definitions since redundant expressions still 
make sense
   inside them.
 
+- Support removing ``c_str`` calls from ``std::string_view`` constructor calls 
in
+  :doc: `readability-redundant-string-cstr 
`
+  check.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -86,6 +86,11 @@
   // be present explicitly.
   hasArgument(1, cxxDefaultArgExpr();
 
+  // Match string constructor.
+  const auto StringViewConstructorExpr = cxxConstructExpr(
+  argumentCountIs(1),
+  hasDeclaration(cxxMethodDecl(hasName("basic_string_view";
+
   // Match a call to the string 'c_str()' method.
   const auto StringCStrCallExpr =
   cxxMemberCallExpr(on(StringExpr.bind("arg")),
@@ -101,7 +106,8 @@
   traverse(
   TK_AsIs,
   cxxConstructExpr(
-  StringConstructorExpr, hasArgument(0, StringCStrCallExpr),
+  anyOf(StringConstructorExpr, StringViewConstructorExpr),
+  hasArgument(0, StringCStrCallExpr),
   unless(anyOf(HasRValueTempParent, hasParent(cxxBindTemporaryExpr(
 HasRValueTempParent)),
   this);


Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -48,6 +48,12 @@
 typedef basic_string, std::allocator> wstring;
 typedef basic_string, std::allocator> u16string;
 typedef basic_string, std::allocator> u32string;
+
+template 
+struct basic_string_view {
+  basic_string_view(const C* s);
+};
+typedef basic_string_view> string_view;
 }
 
 std::string operator+(const std::string&, const std::string&);
@@ -169,6 +175,15 @@
   tmp.insert(1, s);
   tmp.insert(1, s.c_str(), 2);
 }
+void f7(std::string_view sv) {
+  std::string s;
+  f7(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+  f7(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+}
 
 // Tests for std::wstring.
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -201,6 +201,10 @@
   The check now skips concept definitions since redundant expressions still make sense
   inside them.
 
+- Support removing ``c_str`` calls from ``std::string_view`` constructor calls in
+  :doc: `readability-redundant-string-cstr `
+  check.
+
 Removed ch

[PATCH] D140018: [clang-tidy] Support std::string_view in readability-redundant-string-cstr

2022-12-16 Thread Tamas Berghammer via Phabricator via cfe-commits
tberghammer updated this revision to Diff 483553.
tberghammer added a comment.

Add wstring_view test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140018/new/

https://reviews.llvm.org/D140018

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -48,6 +48,15 @@
 typedef basic_string, std::allocator> wstring;
 typedef basic_string, std::allocator> u16string;
 typedef basic_string, std::allocator> u32string;
+
+template 
+struct basic_string_view {
+  basic_string_view(const C* s);
+};
+typedef basic_string_view> string_view;
+typedef basic_string_view> wstring_view;
+typedef basic_string_view> u16string_view;
+typedef basic_string_view> u32string_view;
 }
 
 std::string operator+(const std::string&, const std::string&);
@@ -169,6 +178,15 @@
   tmp.insert(1, s);
   tmp.insert(1, s.c_str(), 2);
 }
+void f7(std::string_view sv) {
+  std::string s;
+  f7(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+  f7(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}f7(s);{{$}}
+}
 
 // Tests for std::wstring.
 
@@ -177,6 +195,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}g1(s);{{$}}
 }
+void g2(std::wstring_view sv) {
+  std::wstring s;
+  g2(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}g2(s);{{$}}
+  g2(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}g2(s);{{$}}
+}
 
 // Tests for std::u16string.
 
@@ -185,6 +212,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}h1(s);{{$}}
 }
+void h2(std::u16string_view sv) {
+  std::u16string s;
+  h2(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}h2(s);{{$}}
+  h2(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}h2(s);{{$}}
+}
 
 // Tests for std::u32string.
 
@@ -193,6 +229,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}k1(s);{{$}}
 }
+void k2(std::u32string_view sv) {
+  std::u32string s;
+  k2(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}k2(s);{{$}}
+  k2(s.data());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}k2(s);{{$}}
+}
 
 // Tests on similar classes that aren't good candidates for this checker.
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -201,6 +201,10 @@
   The check now skips concept definitions since redundant expressions still make sense
   inside them.
 
+- Support removing ``c_str`` calls from ``std::string_view`` constructor calls in
+  :doc: `readability-redundant-string-cstr `
+  check.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -86,6 +86,11 @@
   // be present explicitly.
   hasArgument(1, cxxDefaultArgExpr();
 
+  // Match string constructor.
+  const auto StringViewConstructorExpr = cxxConstructExpr(
+  argumentCountIs(1),
+  hasDeclaration(cxxMethodDecl(hasName("basic_string_view";
+
   // Match a call to the string 'c_str()' method.
   const auto StringCStrCallExpr =
   cxxMemberCallExpr(on(StringExpr.bind("arg")),
@@ -101,7 +106,8 @@
   traverse(
   TK_AsIs,
   cxxConstructExpr(
-  StringConstructorExpr, hasArgument(0, StringCStrCallExpr),
+  anyOf(StringConstru

[PATCH] D33385: __cxa_demangle: Fix constructor cv qualifier handling

2017-05-21 Thread Tamas Berghammer via Phabricator via cfe-commits
tberghammer created this revision.

Previously if we parsed a constructor then we set parsed_ctor_dtor_cv
to true and never reseted it. This causes issue when a template argument
references a constructor (e.g. type of lambda defined inside a
constructor) as we will have the parsed_ctor_dtor_cv flag set what will
cause issues when parsing later arguments.


https://reviews.llvm.org/D33385

Files:
  src/cxa_demangle.cpp
  test/test_demangle.pass.cpp


Index: test/test_demangle.pass.cpp
===
--- test/test_demangle.pass.cpp
+++ test/test_demangle.pass.cpp
@@ -29500,6 +29500,7 @@
 {"_ZZ2f6vE1b", "f6()::b"},
 {"_ZNV3$_35test9Ev", "$_3::test9() volatile"},
 {"_ZN5Test8I3$_2EC1ES0_", "Test8<$_2>::Test8($_2)"},
+{"_Z3fooIZN3BarC1EvE3$_0EvT_", "void 
foo(Bar::Bar()::$_0)"},
 {"_ZGVZN1N1gEvE1a", "guard variable for N::g()::a"},
 {"_ZplRK1YRA100_P1X", "operator+(Y const&, X* (&) [100])"},
 {"_Z1fno", "f(__int128, unsigned __int128)"},
Index: src/cxa_demangle.cpp
===
--- src/cxa_demangle.cpp
+++ src/cxa_demangle.cpp
@@ -4564,6 +4564,8 @@
 save_value sb(db.tag_templates);
 if (db.encoding_depth > 1)
 db.tag_templates = true;
+save_value 
sp(db.parsed_ctor_dtor_cv);
+db.parsed_ctor_dtor_cv = false;
 switch (*first)
 {
 case 'G':


Index: test/test_demangle.pass.cpp
===
--- test/test_demangle.pass.cpp
+++ test/test_demangle.pass.cpp
@@ -29500,6 +29500,7 @@
 {"_ZZ2f6vE1b", "f6()::b"},
 {"_ZNV3$_35test9Ev", "$_3::test9() volatile"},
 {"_ZN5Test8I3$_2EC1ES0_", "Test8<$_2>::Test8($_2)"},
+{"_Z3fooIZN3BarC1EvE3$_0EvT_", "void foo(Bar::Bar()::$_0)"},
 {"_ZGVZN1N1gEvE1a", "guard variable for N::g()::a"},
 {"_ZplRK1YRA100_P1X", "operator+(Y const&, X* (&) [100])"},
 {"_Z1fno", "f(__int128, unsigned __int128)"},
Index: src/cxa_demangle.cpp
===
--- src/cxa_demangle.cpp
+++ src/cxa_demangle.cpp
@@ -4564,6 +4564,8 @@
 save_value sb(db.tag_templates);
 if (db.encoding_depth > 1)
 db.tag_templates = true;
+save_value sp(db.parsed_ctor_dtor_cv);
+db.parsed_ctor_dtor_cv = false;
 switch (*first)
 {
 case 'G':
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits