[PATCH] D97361: [clang-tidy] Add readability-redundant-using check

2021-04-21 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97361

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


[PATCH] D97361: [clang-tidy] Add readability-redundant-using check

2021-04-07 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97361

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


[PATCH] D97361: [clang-tidy] Add readability-redundant-using check

2021-03-29 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

In D97361#2609616 , @nullptr.cpp wrote:

> - Restrict to only run on C++ code
> - Ignore `using` defined in macro
> - Support inline namespace
> - Support global namespace

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97361

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


[PATCH] D98692: [clang-tidy] Add cppcoreguidelines-comparison-operator

2021-03-20 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 332145.
nullptr.cpp edited the summary of this revision.
nullptr.cpp added a comment.

- Warn on both declarations and definitions
- Add check for parameter passing
- Add options `CheckParamPassing` and `ExpensiveToCopySize`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98692

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/ComparisonOperatorCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ComparisonOperatorCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-comparison-operator.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator-check-param-passing.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator-expensive-to-copy-size.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator.cpp
@@ -0,0 +1,194 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-comparison-operator %t -- --fix-notes
+
+/// member function
+namespace test_member_function {
+struct A {
+  int Var;
+
+  bool operator==(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator==' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator!=(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator!=' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator<(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator<' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator<=(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator<=' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator>(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator>' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator>=(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator>=' should not be member function [cppcoreguidelines-comparison-operator]
+};
+} // namespace test_member_function
+
+/// parameters types differ
+namespace test_params_type_differ {
+struct B;
+bool operator==(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator==' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator!=(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator!=' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator<(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator<=(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<=' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator>(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator>' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator>=(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator>=' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+} // namespace test_params_type_differ
+
+/// can throw
+namespace test_can_throw {
+struct C;
+bool operator==(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator==' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator==(const C , const C ) noexcept
+
+bool operator!=(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator!=' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator!=(const C , const C ) noexcept;
+
+bool operator<(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator<(const C , const C ) noexcept;
+
+bool operator<=(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<=' should be marked noexcept [cppcoreguidelines-comparison-operator]

[PATCH] D98692: [clang-tidy] Add cppcoreguidelines-comparison-operator

2021-03-17 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

In D98692#2631182 , @njames93 wrote:

> While we're here, I'm not sure if there is a cppcoreguideline for it, but 
> parameters to comparison functions should be passed by const ref usually, or 
> by value if they are cheap to copy. Maybe there's precedent to extend this to 
> flag parameters that take non const reference, R value reference or by value 
> if not cheap to copy(There's bound to be a function somewhere in clang tidy 
> that determines if a type is a cheap copy)

The relevant rule is F.16: For "in" parameters, pass cheaply-copied types by 
value and others by reference to const 
.
This should be done in another patch dedicated to parameter passing.




Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ComparisonOperatorCheck.cpp:47
+  const auto *Operator = Result.Nodes.getNodeAs("operator");
+  const FunctionDecl *CanonOperator = Operator->getCanonicalDecl();
+

njames93 wrote:
> It might just be better to return here if the matched result isn't the same 
> as the canonical declaration. 
Why only warn on the canonical declaration?
Clients need to find the definition and other declarations by themselves. I 
think it's better to warn about everything found here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98692

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


[PATCH] D97361: [clang-tidy] Add readability-redundant-using check

2021-03-17 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 331188.
nullptr.cpp retitled this revision from "[clang-tidy] Add 
cppcoreguidelines-comparison-operator" to "[clang-tidy] Add 
readability-redundant-using check".
nullptr.cpp edited the summary of this revision.
nullptr.cpp added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97361

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/RedundantUsingCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantUsingCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-redundant-using.rst
  clang-tools-extra/test/clang-tidy/checkers/readability-redundant-using.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-redundant-using.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-redundant-using.cpp
@@ -0,0 +1,188 @@
+// RUN: %check_clang_tidy %s readability-redundant-using %t
+
+// using directive
+namespace n1 {
+using namespace n1;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n1' is redundant, already in namespace 'n1' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+} // namespace n1
+
+namespace n2 {
+using namespace n1; // ok
+}
+
+namespace n3 {
+namespace n = n3;
+using namespace n;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n' is redundant, already in namespace 'n3' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+} // namespace n3
+
+namespace n4 {
+namespace inner {
+using namespace n4;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n4' is redundant, already in namespace 'n4' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+
+using namespace n4::inner;
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: using directive 'inner' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:21: note: remove the using directive
+// CHECK-FIXES: {{^}}
+
+namespace n = n4::inner;
+using namespace n;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+} // namespace inner
+
+using namespace inner; // ok
+} // namespace n4
+
+namespace n5 {
+namespace inner {
+using namespace n4::inner; // ok
+}
+} // namespace n5
+
+#define USING_DIRECTIVE(n) using namespace n
+
+namespace n6 {
+USING_DIRECTIVE(n6); // skip macro
+}
+
+// using declaration
+namespace m1 {
+void func();
+
+using m1::func;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using declaration 'func' is redundant, already in namespace 'm1' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:11: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+} // namespace m1
+
+namespace m2 {
+using m1::func; // ok
+}
+
+namespace m3 {
+void func();
+
+namespace n = m3;
+using n::func;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using declaration 'func' is redundant, already in namespace 'm3' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:10: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+} // namespace m3
+
+namespace m4 {
+void outerFunc();
+
+namespace inner {
+using m4::outerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using declaration 'outerFunc' is redundant, already in namespace 'm4' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:11: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+
+void innerFunc();
+using inner::innerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: using declaration 'innerFunc' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:14: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+
+using m4::inner::innerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: using declaration 'innerFunc' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:18: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+
+namespace n = m4::inner;
+using n::innerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using declaration 'innerFunc' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:10: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+} // namespace inner
+
+using inner::innerFunc; // ok
+} // namespace m4
+
+namespace m5 

[PATCH] D98692: [clang-tidy] Add cppcoreguidelines-comparison-operator

2021-03-17 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 331179.
nullptr.cpp edited the summary of this revision.
nullptr.cpp added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98692

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/ComparisonOperatorCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ComparisonOperatorCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-comparison-operator.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator.cpp
@@ -0,0 +1,129 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-comparison-operator %t -- --fix-notes
+
+// member function
+namespace test_member_function {
+struct A {
+  int Var;
+
+  bool operator==(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator==' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator!=(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator!=' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator<(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator<' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator<=(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator<=' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator>(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator>' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator>=(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator>=' should not be member function [cppcoreguidelines-comparison-operator]
+};
+} // namespace test_member_function
+
+// parameters types differ
+namespace test_params_type_differ {
+struct B;
+bool operator==(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator==' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator!=(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator!=' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator<(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator<=(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<=' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator>(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator>' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator>=(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator>=' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+} // namespace test_params_type_differ
+
+// can throw
+namespace test_can_throw {
+struct C;
+bool operator==(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator==' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator==(const C , const C ) noexcept
+
+bool operator!=(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator!=' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator!=(const C , const C ) noexcept;
+
+bool operator<(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator<(const C , const C ) noexcept;
+
+bool operator<=(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<=' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator<=(const C , const C ) noexcept;
+
+bool operator>(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator>' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// 

[PATCH] D97361: [clang-tidy] Add cppcoreguidelines-comparison-operator

2021-03-17 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 331178.
nullptr.cpp retitled this revision from "[clang-tidy] Add 
readability-redundant-using check" to "[clang-tidy] Add 
cppcoreguidelines-comparison-operator".
nullptr.cpp edited the summary of this revision.
nullptr.cpp added a comment.
Herald added subscribers: shchenz, kbarton, nemanjai.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97361

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/ComparisonOperatorCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ComparisonOperatorCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-comparison-operator.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator.cpp
@@ -0,0 +1,129 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-comparison-operator %t -- --fix-notes
+
+// member function
+namespace test_member_function {
+struct A {
+  int Var;
+
+  bool operator==(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator==' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator!=(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator!=' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator<(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator<' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator<=(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator<=' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator>(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator>' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator>=(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator>=' should not be member function [cppcoreguidelines-comparison-operator]
+};
+} // namespace test_member_function
+
+// parameters types differ
+namespace test_params_type_differ {
+struct B;
+bool operator==(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator==' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator!=(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator!=' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator<(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator<=(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<=' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator>(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator>' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator>=(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator>=' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+} // namespace test_params_type_differ
+
+// can throw
+namespace test_can_throw {
+struct C;
+bool operator==(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator==' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator==(const C , const C ) noexcept
+
+bool operator!=(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator!=' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator!=(const C , const C ) noexcept;
+
+bool operator<(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator<(const C , const C ) noexcept;
+
+bool operator<=(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<=' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator<=(const C , const C ) noexcept;
+
+bool 

[PATCH] D98692: [clang-tidy] Add cppcoreguidelines-comparison-operator

2021-03-17 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 331170.
nullptr.cpp marked 6 inline comments as done.
nullptr.cpp edited the summary of this revision.
nullptr.cpp added a comment.

Modify according to suggestions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98692

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/ComparisonOperatorCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ComparisonOperatorCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-comparison-operator.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-comparison-operator.cpp
@@ -0,0 +1,140 @@
+// RUN: %check_clang_tidy -std=c++20 %s cppcoreguidelines-comparison-operator %t -- --fix-notes
+
+// member function
+namespace test_member_function {
+struct A {
+  int Var;
+
+  bool operator==(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator==' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator!=(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator!=' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator<(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator<' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator<=(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator<=' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator>(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator>' should not be member function [cppcoreguidelines-comparison-operator]
+
+  bool operator>=(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator>=' should not be member function [cppcoreguidelines-comparison-operator]
+
+  auto operator<=>(const A ) const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'operator<=>' should not be member function [cppcoreguidelines-comparison-operator]
+};
+} // namespace test_member_function
+
+// parameters types differ
+namespace test_params_type_differ {
+struct B;
+bool operator==(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator==' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator!=(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator!=' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator<(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator<=(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<=' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator>(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator>' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator>=(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator>=' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+bool operator<=>(const B , int rh) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<=>' should have 2 parameters of the same type [cppcoreguidelines-comparison-operator]
+
+} // namespace test_params_type_differ
+
+// can throw
+namespace test_can_throw {
+struct C;
+bool operator==(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator==' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator==(const C , const C ) noexcept
+
+bool operator!=(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator!=' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator!=(const C , const C ) noexcept;
+
+bool operator<(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'operator<' should be marked noexcept [cppcoreguidelines-comparison-operator]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: mark 'noexcept'
+// CHECK-FIXES: bool operator<(const C , const C ) noexcept;
+
+bool operator<=(const C , const C );
+// CHECK-MESSAGES: :[[@LINE-1]]:6: 

[PATCH] D97361: [clang-tidy] Add readability-redundant-using check

2021-03-16 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.
Herald added a project: clang-tools-extra.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97361

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


[PATCH] D97361: [clang-tidy] Add readability-redundant-using check

2021-03-06 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 328841.
nullptr.cpp added a comment.

- Restrict to only run on C++ code
- Ignore `using` defined in macro
- Support inline namespace
- Support global namespace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97361

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/RedundantUsingCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantUsingCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-redundant-using.rst
  clang-tools-extra/test/clang-tidy/checkers/readability-redundant-using.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-redundant-using.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-redundant-using.cpp
@@ -0,0 +1,188 @@
+// RUN: %check_clang_tidy %s readability-redundant-using %t
+
+// using directive
+namespace n1 {
+using namespace n1;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n1' is redundant, already in namespace 'n1' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+} // namespace n1
+
+namespace n2 {
+using namespace n1; // ok
+}
+
+namespace n3 {
+namespace n = n3;
+using namespace n;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n' is redundant, already in namespace 'n3' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+} // namespace n3
+
+namespace n4 {
+namespace inner {
+using namespace n4;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n4' is redundant, already in namespace 'n4' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+
+using namespace n4::inner;
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: using directive 'inner' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:21: note: remove the using directive
+// CHECK-FIXES: {{^}}
+
+namespace n = n4::inner;
+using namespace n;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+} // namespace inner
+
+using namespace inner; // ok
+} // namespace n4
+
+namespace n5 {
+namespace inner {
+using namespace n4::inner; // ok
+}
+} // namespace n5
+
+#define USING_DIRECTIVE(n) using namespace n
+
+namespace n6 {
+USING_DIRECTIVE(n6); // skip macro
+}
+
+// using declaration
+namespace m1 {
+void func();
+
+using m1::func;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using declaration 'func' is redundant, already in namespace 'm1' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:11: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+} // namespace m1
+
+namespace m2 {
+using m1::func; // ok
+}
+
+namespace m3 {
+void func();
+
+namespace n = m3;
+using n::func;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using declaration 'func' is redundant, already in namespace 'm3' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:10: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+} // namespace m3
+
+namespace m4 {
+void outerFunc();
+
+namespace inner {
+using m4::outerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using declaration 'outerFunc' is redundant, already in namespace 'm4' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:11: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+
+void innerFunc();
+using inner::innerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: using declaration 'innerFunc' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:14: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+
+using m4::inner::innerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: using declaration 'innerFunc' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:18: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+
+namespace n = m4::inner;
+using n::innerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using declaration 'innerFunc' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:10: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+} // namespace inner
+
+using inner::innerFunc; // ok
+} // namespace m4
+
+namespace m5 {
+namespace inner {
+using m4::inner::innerFunc; // ok
+}
+} // namespace m5
+
+#define 

[PATCH] D97361: [clang-tidy] Add readability-redundant-using check

2021-02-25 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 326320.
nullptr.cpp retitled this revision from "[clang-tidy] Add misc-redundant-using 
check" to "[clang-tidy] Add readability-redundant-using check".
nullptr.cpp added a comment.

Modify according to suggestions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97361

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/RedundantUsingCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantUsingCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-redundant-using.rst
  clang-tools-extra/test/clang-tidy/checkers/readability-redundant-using.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-redundant-using.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-redundant-using.cpp
@@ -0,0 +1,114 @@
+// RUN: %check_clang_tidy %s readability-redundant-using %t
+
+namespace n1 {
+using namespace n1;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n1' is redundant, already in namespace 'n1' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+} // namespace n1
+
+namespace n2 {
+using namespace n1; // ok
+}
+
+namespace n3 {
+namespace n = n3;
+using namespace n;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n' is redundant, already in namespace 'n3' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+} // namespace n3
+
+namespace n4 {
+namespace inner {
+using namespace n4;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n4' is redundant, already in namespace 'n4' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+
+using namespace n4::inner;
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: using directive 'inner' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:21: note: remove the using directive
+// CHECK-FIXES: {{^}}
+
+namespace n = n4::inner;
+using namespace n;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+} // namespace inner
+} // namespace n4
+
+namespace n5 {
+namespace inner {
+using namespace n4::inner; // ok
+}
+} // namespace n5
+
+namespace n6 {
+void func();
+
+using n6::func;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using declaration 'func' is redundant, already in namespace 'n6' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:11: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+} // namespace n6
+
+namespace n7 {
+using n6::func; // ok
+}
+
+namespace n8 {
+void func();
+
+namespace n = n8;
+using n::func;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using declaration 'func' is redundant, already in namespace 'n8' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:10: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+} // namespace n8
+
+namespace n9 {
+void outerFunc();
+
+namespace inner {
+using n9::outerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using declaration 'outerFunc' is redundant, already in namespace 'n9' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:11: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+
+void innerFunc();
+using inner::innerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: using declaration 'innerFunc' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:14: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+
+using n9::inner::innerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: using declaration 'innerFunc' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:18: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+
+namespace n = n9::inner;
+using n::innerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using declaration 'innerFunc' is redundant, already in namespace 'inner' [readability-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:10: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+} // namespace inner
+} // namespace n9
+
+namespace n10 {
+namespace inner {
+using n9::inner::innerFunc; // ok
+}
+} // namespace n10
+
+namespace n11 {
+void func();
+}
+
+namespace n11 {
+using n11::func;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: using declaration 'func' is redundant, already in 

[PATCH] D97364: [docs] Add a release note for the removing of -Wreturn-std-move-in-c++11

2021-02-24 Thread Yang Fan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb950de5c13ef: [docs] Add a release note for the removing of 
-Wreturn-std-move-in-c++11 (authored by nullptr.cpp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97364

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -79,6 +79,10 @@
 - The clang-cl ``/fallback`` flag, which made clang-cl invoke Microsoft Visual
   C++ on files it couldn't compile itself, has been removed.
 
+- ``-Wreturn-std-move-in-c++11``, which checked whether an entity is affected 
by
+  `CWG1579 `_ to become implicitly movable, has been
+  removed.
+
 New Pragmas in Clang
 
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -79,6 +79,10 @@
 - The clang-cl ``/fallback`` flag, which made clang-cl invoke Microsoft Visual
   C++ on files it couldn't compile itself, has been removed.
 
+- ``-Wreturn-std-move-in-c++11``, which checked whether an entity is affected by
+  `CWG1579 `_ to become implicitly movable, has been
+  removed.
+
 New Pragmas in Clang
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97364: [docs] Add a release note for the removing of -Wreturn-std-move-in-c++11

2021-02-24 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

In D97364#2586171 , @aaronpuchert 
wrote:

> I assume you need someone to land this for you?

I can do it by myself, I have the commit access now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97364

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


[PATCH] D88220: [C++20] P1825R0: More implicit moves

2021-02-24 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

In D88220#2583486 , @aaronpuchert 
wrote:

> In D88220#2581538 , @aaron.ballman 
> wrote:
>
>> We usually rely on the release notes to say something, but we didn't do that 
>> here.
>
> Perhaps @nullptr.cpp could add something there? The file is 
> `clang/docs/ReleaseNotes.rst`.

Add by D97364 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

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


[PATCH] D97364: [docs] Add a release note for the removing of -Wreturn-std-move-in-c++11

2021-02-24 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
nullptr.cpp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`-Wreturn-std-move-in-c++11` has been removed in 
fbee4a0c79cc4ee87c34e51342742a5bc6fcf872 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97364

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -79,6 +79,10 @@
 - The clang-cl ``/fallback`` flag, which made clang-cl invoke Microsoft Visual
   C++ on files it couldn't compile itself, has been removed.
 
+- ``-Wreturn-std-move-in-c++11``, which checked whether an entity is affected 
by
+  `CWG1579 `_ to become implicitly movable, has been
+  removed.
+
 New Pragmas in Clang
 
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -79,6 +79,10 @@
 - The clang-cl ``/fallback`` flag, which made clang-cl invoke Microsoft Visual
   C++ on files it couldn't compile itself, has been removed.
 
+- ``-Wreturn-std-move-in-c++11``, which checked whether an entity is affected by
+  `CWG1579 `_ to become implicitly movable, has been
+  removed.
+
 New Pragmas in Clang
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97361: [clang-tidy] Add misc-redundant-using check

2021-02-23 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
nullptr.cpp added reviewers: alexfh, aaron.ballman, njames93, balazske.
Herald added subscribers: xazax.hun, mgorny.
nullptr.cpp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Finds redundant `using` declarations and directives.

Example:

  namespace n {
  void func();
  }
  
  namespace  {
  using n::func; // redundant using declaration, already in namespace 'n'.
  }



  namespace n {
  using namespace n; // redundant using directive, already in namespace 'n'.
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97361

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/RedundantUsingCheck.cpp
  clang-tools-extra/clang-tidy/misc/RedundantUsingCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-redundant-using.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-redundant-using.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-redundant-using.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-redundant-using.cpp
@@ -0,0 +1,114 @@
+// RUN: %check_clang_tidy %s misc-redundant-using %t
+
+namespace n1 {
+using namespace n1;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n1' is redundant, already in namespace 'n1' [misc-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+} // namespace n1
+
+namespace n2 {
+using namespace n1; // ok
+}
+
+namespace n3 {
+namespace n = n3;
+using namespace n;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n' is redundant, already in namespace 'n3' [misc-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+} // namespace n3
+
+namespace n4 {
+namespace inner {
+using namespace n4;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n4' is redundant, already in namespace 'n4' [misc-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+
+using namespace n4::inner;
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: using directive 'inner' is redundant, already in namespace 'inner' [misc-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:21: note: remove the using directive
+// CHECK-FIXES: {{^}}
+
+namespace n = n4::inner;
+using namespace n;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: using directive 'n' is redundant, already in namespace 'inner' [misc-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: remove the using directive
+// CHECK-FIXES: {{^}}
+} // namespace inner
+} // namespace n4
+
+namespace n5 {
+namespace inner {
+using namespace n4::inner; // ok
+}
+} // namespace n5
+
+namespace n6 {
+void func();
+
+using n6::func;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using declaration 'func' is redundant, already in namespace 'n6' [misc-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:11: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+} // namespace n6
+
+namespace n7 {
+using n6::func; // ok
+}
+
+namespace n8 {
+void func();
+
+namespace n = n8;
+using n::func;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using declaration 'func' is redundant, already in namespace 'n8' [misc-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:10: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+} // namespace n8
+
+namespace n9 {
+void outerFunc();
+
+namespace inner {
+using n9::outerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using declaration 'outerFunc' is redundant, already in namespace 'n9' [misc-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:11: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+
+void innerFunc();
+using inner::innerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: using declaration 'innerFunc' is redundant, already in namespace 'inner' [misc-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:14: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+
+using n9::inner::innerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: using declaration 'innerFunc' is redundant, already in namespace 'inner' [misc-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:18: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+
+namespace n = n9::inner;
+using n::innerFunc;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using declaration 'innerFunc' is redundant, already in namespace 'inner' [misc-redundant-using]
+// CHECK-MESSAGES: :[[@LINE-2]]:10: note: remove the using declaration
+// CHECK-FIXES: {{^}}
+} // namespace inner
+} // namespace n9
+
+namespace n10 {
+namespace inner {
+using n9::inner::innerFunc; // ok
+}
+} // namespace n10
+
+namespace n11 {
+void func();
+}
+
+namespace n11 {
+using 

[PATCH] D88220: [C++20] P1825R0: More implicit moves

2021-02-16 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

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


[PATCH] D96478: [clang][cli] Fix gcc warning (NFC)

2021-02-10 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 322896.
nullptr.cpp added a comment.

Fix format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96478

Files:
  clang/lib/Frontend/TestModuleFileExtension.cpp


Index: clang/lib/Frontend/TestModuleFileExtension.cpp
===
--- clang/lib/Frontend/TestModuleFileExtension.cpp
+++ clang/lib/Frontend/TestModuleFileExtension.cpp
@@ -128,9 +128,11 @@
 new 
TestModuleFileExtension::Reader(this, Stream));
 }
 
-llvm::raw_ostream ::operator<<(llvm::raw_ostream ,
- const TestModuleFileExtension ) 
{
+namespace clang {
+llvm::raw_ostream <<(llvm::raw_ostream ,
+  const TestModuleFileExtension ) {
   return OS << Extension.BlockName << ":" << Extension.MajorVersion << ":"
 << Extension.MinorVersion << ":" << Extension.Hashed << ":"
 << Extension.UserInfo;
 }
+} // namespace clang


Index: clang/lib/Frontend/TestModuleFileExtension.cpp
===
--- clang/lib/Frontend/TestModuleFileExtension.cpp
+++ clang/lib/Frontend/TestModuleFileExtension.cpp
@@ -128,9 +128,11 @@
 new TestModuleFileExtension::Reader(this, Stream));
 }
 
-llvm::raw_ostream ::operator<<(llvm::raw_ostream ,
- const TestModuleFileExtension ) {
+namespace clang {
+llvm::raw_ostream <<(llvm::raw_ostream ,
+  const TestModuleFileExtension ) {
   return OS << Extension.BlockName << ":" << Extension.MajorVersion << ":"
 << Extension.MinorVersion << ":" << Extension.Hashed << ":"
 << Extension.UserInfo;
 }
+} // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96478: [clang][cli] Fix gcc warning (NFC)

2021-02-10 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
nullptr.cpp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

GCC warning:

  /llvm-project/clang/lib/Frontend/TestModuleFileExtension.cpp:131:20: warning: 
‘llvm::raw_ostream& clang::operator<<(llvm::raw_ostream&, const 
clang::TestModuleFileExtension&)’ has not been declared within ‘clang’
131 | llvm::raw_ostream ::operator<<(llvm::raw_ostream ,
|^
  In file included from 
/llvm-project/clang/lib/Frontend/TestModuleFileExtension.cpp:8:
  /llvm-project/clang/lib/Frontend/TestModuleFileExtension.h:75:3: note: only 
here as a ‘friend’
 75 |   operator<<(llvm::raw_ostream , const TestModuleFileExtension 
);
|   ^~~~


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96478

Files:
  clang/lib/Frontend/TestModuleFileExtension.cpp


Index: clang/lib/Frontend/TestModuleFileExtension.cpp
===
--- clang/lib/Frontend/TestModuleFileExtension.cpp
+++ clang/lib/Frontend/TestModuleFileExtension.cpp
@@ -128,9 +128,11 @@
 new 
TestModuleFileExtension::Reader(this, Stream));
 }
 
-llvm::raw_ostream ::operator<<(llvm::raw_ostream ,
+namespace clang {
+llvm::raw_ostream <<(llvm::raw_ostream ,
  const TestModuleFileExtension ) 
{
   return OS << Extension.BlockName << ":" << Extension.MajorVersion << ":"
 << Extension.MinorVersion << ":" << Extension.Hashed << ":"
 << Extension.UserInfo;
 }
+} // namespace clang


Index: clang/lib/Frontend/TestModuleFileExtension.cpp
===
--- clang/lib/Frontend/TestModuleFileExtension.cpp
+++ clang/lib/Frontend/TestModuleFileExtension.cpp
@@ -128,9 +128,11 @@
 new TestModuleFileExtension::Reader(this, Stream));
 }
 
-llvm::raw_ostream ::operator<<(llvm::raw_ostream ,
+namespace clang {
+llvm::raw_ostream <<(llvm::raw_ostream ,
  const TestModuleFileExtension ) {
   return OS << Extension.BlockName << ":" << Extension.MajorVersion << ":"
 << Extension.MinorVersion << ":" << Extension.Hashed << ":"
 << Extension.UserInfo;
 }
+} // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88220: [C++20] P1825R0: More implicit moves

2021-02-10 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

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


[PATCH] D88220: [C++20] P1825R0: More implicit moves

2021-02-01 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

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


[PATCH] D88220: [C++20] P1825R0: More implicit moves

2021-01-21 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 318420.
nullptr.cpp added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1203,6 +1203,11 @@
   https://wg21.link/p0593r6;>P0593R6 (DR)
   Clang 11
 
+
+  More implicit moves
+  https://wg21.link/p1825r0;>P1825R0 (DR)
+  Clang 12
+
 
 
 
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,12 +1,17 @@
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++20 -verify=cxx20 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
 
 // definitions for std::move
 namespace std {
 inline namespace foo {
 template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
 
 template  typename remove_reference::type &(T &);
 } // namespace foo
@@ -76,11 +81,8 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
 }
 ConstructFromDerived test3() {
-Derived d3;
-return d3;  // e2-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d3)"
+  Derived d3;
+  return d3; // ok
 }
 ConstructFromBase test4() {
 Derived d4;
@@ -153,10 +155,7 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
 }
 ConstructFromDerived testParam3(Derived d) {
-return d;  // e7-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
+  return d; // ok
 }
 ConstructFromBase testParam4(Derived d) {
 return d;  // e8
@@ -218,8 +217,10 @@
 // But if the return type is a reference type, then moving would be wrong.
 Derived& testRetRef1(Derived&& d) { return d; }
 Base& testRetRef2(Derived&& d) { return d; }
+#if __cplusplus >= 201402L
 auto&& testRetRef3(Derived&& d) { return d; }
 decltype(auto) testRetRef4(Derived&& d) { return (d); }
+#endif
 
 // As long as we're checking parentheses, make sure parentheses don't disable the warning.
 Base testParens1() {
@@ -230,14 +231,10 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)"
 }
 ConstructFromDerived testParens2() {
-Derived d;
-return (d);  // e18-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)"
+  Derived d;
+  return (d); // ok
 }
 
-
 // If the target is a catch-handler parameter, do apply the diagnostic.
 void throw_derived();
 Derived testEParam1() {
@@ -339,7 +336,7 @@
 namespace test_delete {
 struct Base {
   Base();
-  Base(Base &&) = delete;
+  Base(Base &&) = delete; // cxx20-note {{'Base' has been explicitly marked deleted here}}
   Base(Base const &);
 };
 
@@ -347,6 +344,6 @@
 
 Base 

[PATCH] D88220: [C++20] P1825R0: More implicit moves

2021-01-21 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 318406.
nullptr.cpp added a comment.

Add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1203,6 +1203,11 @@
   https://wg21.link/p0593r6;>P0593R6 (DR)
   Clang 11
 
+
+  More implicit moves
+  https://wg21.link/p1825r0;>P1825R0 (DR)
+  Clang 12
+
 
 
 
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,12 +1,17 @@
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++20 -verify=cxx20 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
 
 // definitions for std::move
 namespace std {
 inline namespace foo {
 template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
 
 template  typename remove_reference::type &(T &);
 } // namespace foo
@@ -76,11 +81,8 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
 }
 ConstructFromDerived test3() {
-Derived d3;
-return d3;  // e2-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d3)"
+  Derived d3;
+  return d3; // ok
 }
 ConstructFromBase test4() {
 Derived d4;
@@ -153,10 +155,7 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
 }
 ConstructFromDerived testParam3(Derived d) {
-return d;  // e7-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
+  return d; // ok
 }
 ConstructFromBase testParam4(Derived d) {
 return d;  // e8
@@ -218,8 +217,10 @@
 // But if the return type is a reference type, then moving would be wrong.
 Derived& testRetRef1(Derived&& d) { return d; }
 Base& testRetRef2(Derived&& d) { return d; }
+#if __cplusplus >= 201402L
 auto&& testRetRef3(Derived&& d) { return d; }
 decltype(auto) testRetRef4(Derived&& d) { return (d); }
+#endif
 
 // As long as we're checking parentheses, make sure parentheses don't disable the warning.
 Base testParens1() {
@@ -230,14 +231,10 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)"
 }
 ConstructFromDerived testParens2() {
-Derived d;
-return (d);  // e18-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)"
+  Derived d;
+  return (d); // ok
 }
 
-
 // If the target is a catch-handler parameter, do apply the diagnostic.
 void throw_derived();
 Derived testEParam1() {
@@ -339,7 +336,7 @@
 namespace test_delete {
 struct Base {
   Base();
-  Base(Base &&) = delete;
+  Base(Base &&) = delete; // cxx20-note {{'Base' has been explicitly marked deleted here}}
   Base(Base const &);
 };
 
@@ -347,6 +344,6 @@
 
 Base 

[PATCH] D88220: [C++20] P1825R0: More implicit moves

2021-01-21 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

In D88220#2495071 , @Quuxplusone wrote:

> I notice a lack of any explicitly `co_return`-related tests and/or code in 
> this patch. I'm just going to assume that is fine.

`co_return` related implicit move is implemented by @aaronpuchert in D68845 
. I think it's a good idea to split that from 
this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

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


[PATCH] D88220: [C++20] P1825R0: More implicit moves

2021-01-12 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 316302.
nullptr.cpp added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1203,6 +1203,11 @@
   https://wg21.link/p0593r6;>P0593R6 (DR)
   Clang 11
 
+
+  More implicit moves
+  https://wg21.link/p1825r0;>P1825R0 (DR)
+  Clang 12
+
 
 
 
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,12 +1,17 @@
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++20 -verify=cxx20 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
 
 // definitions for std::move
 namespace std {
 inline namespace foo {
 template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
 
 template  typename remove_reference::type &(T &);
 } // namespace foo
@@ -76,11 +81,8 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
 }
 ConstructFromDerived test3() {
-Derived d3;
-return d3;  // e2-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d3)"
+  Derived d3;
+  return d3; // ok
 }
 ConstructFromBase test4() {
 Derived d4;
@@ -153,10 +155,7 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
 }
 ConstructFromDerived testParam3(Derived d) {
-return d;  // e7-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
+  return d; // ok
 }
 ConstructFromBase testParam4(Derived d) {
 return d;  // e8
@@ -218,8 +217,10 @@
 // But if the return type is a reference type, then moving would be wrong.
 Derived& testRetRef1(Derived&& d) { return d; }
 Base& testRetRef2(Derived&& d) { return d; }
+#if __cplusplus >= 201402L
 auto&& testRetRef3(Derived&& d) { return d; }
 decltype(auto) testRetRef4(Derived&& d) { return (d); }
+#endif
 
 // As long as we're checking parentheses, make sure parentheses don't disable the warning.
 Base testParens1() {
@@ -230,14 +231,10 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)"
 }
 ConstructFromDerived testParens2() {
-Derived d;
-return (d);  // e18-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)"
+  Derived d;
+  return (d); // ok
 }
 
-
 // If the target is a catch-handler parameter, do apply the diagnostic.
 void throw_derived();
 Derived testEParam1() {
@@ -339,7 +336,7 @@
 namespace test_delete {
 struct Base {
   Base();
-  Base(Base &&) = delete;
+  Base(Base &&) = delete; // cxx20-note {{'Base' has been explicitly marked deleted here}}
   Base(Base const &);
 };
 
@@ -347,6 +344,6 @@
 
 Base 

[PATCH] D92936: [Sema] Fix deleted function problem in implicitly movable test

2021-01-05 Thread Yang Fan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG74f93bc373d0: [Sema] Fix deleted function problem in 
implicitly movable test (authored by nullptr.cpp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92936

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp

Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -324,11 +324,29 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:11-[[@LINE-3]]:12}:"std::move(d)"
 }
 
-void ok_throw1() { Derived d; throw d; }
+void ok_throw1() {
+  Derived d;
+  throw d;
+}
 void ok_throw2(Derived d) { throw d; }
-void ok_throw3(Derived& d) { throw d; }
+void ok_throw3(Derived ) { throw d; }
 void ok_throw4(Derived d) { throw std::move(d); }
-void ok_throw5(Derived& d) { throw std::move(d); }
-void ok_throw6(Derived& d) { throw static_cast(d); }
+void ok_throw5(Derived ) { throw std::move(d); }
+void ok_throw6(Derived ) { throw static_cast(d); }
 void ok_throw7(TriviallyCopyable d) { throw d; }
 void ok_throw8(OnlyCopyable d) { throw d; }
+
+namespace test_delete {
+struct Base {
+  Base();
+  Base(Base &&) = delete;
+  Base(Base const &);
+};
+
+struct Derived : public Base {};
+
+Base test_ok() {
+  Derived d;
+  return d;
+}
+} // namespace test_delete
Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=expected %s
+
+namespace test_delete_function {
+struct A1 {
+  A1();
+  A1(const A1 &);
+  A1(A1 &&) = delete; // expected-note {{'A1' has been explicitly marked deleted here}}
+};
+A1 test1() {
+  A1 a;
+  return a; // expected-error {{call to deleted constructor of 'test_delete_function::A1'}}
+}
+
+struct A2 {
+  A2();
+  A2(const A2 &);
+
+private:
+  A2(A2 &&); // expected-note {{declared private here}}
+};
+A2 test2() {
+  A2 a;
+  return a; // expected-error {{calling a private constructor of class 'test_delete_function::A2'}}
+}
+
+struct C {};
+
+struct B1 {
+  B1(C &);
+  B1(C &&) = delete; // expected-note {{'B1' has been explicitly marked deleted here}}
+};
+B1 test3() {
+  C c;
+  return c; // expected-error {{conversion function from 'test_delete_function::C' to 'test_delete_function::B1' invokes a deleted function}}
+}
+
+struct B2 {
+  B2(C &);
+
+private:
+  B2(C &&); // expected-note {{declared private here}}
+};
+B2 test4() {
+  C c;
+  return c; // expected-error {{calling a private constructor of class 'test_delete_function::B2'}}
+}
+} // namespace test_delete_function
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3118,11 +3118,16 @@
 /// If move-initialization is not possible, such that we must fall back to
 /// treating the operand as an lvalue, we will leave Res in its original
 /// invalid state.
-static void TryMoveInitialization(Sema , const InitializedEntity ,
+///
+/// \returns Whether we need to do the second overload resolution. If the first
+/// overload resolution fails, or if the first overload resolution succeeds but
+/// the selected constructor/operator doesn't match the additional criteria, we
+/// need to do the second overload resolution.
+static bool TryMoveInitialization(Sema , const InitializedEntity ,
   const VarDecl *NRVOCandidate,
   QualType ResultType, Expr *,
   bool ConvertingConstructorsOnly,
-  ExprResult ) {
+  bool IsDiagnosticsCheck, ExprResult ) {
   ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(),
 CK_NoOp, Value, VK_XValue, FPOptionsOverride());
 
@@ -3133,8 +3138,11 @@
 
   InitializationSequence Seq(S, Entity, Kind, InitExpr);
 
-  if (!Seq)
-return;
+  bool NeedSecondOverloadResolution = true;
+  if (!Seq &&
+  (IsDiagnosticsCheck || Seq.getFailedOverloadResult() != OR_Deleted)) {
+return NeedSecondOverloadResolution;
+  }
 
   for (const InitializationSequence::Step  : Seq.steps()) {
 if (Step.Kind != InitializationSequence::SK_ConstructorInitialization &&
@@ -3177,6 +3185,7 @@
   

[PATCH] D92936: [Sema] Fix deleted function problem in implicitly movable test

2021-01-04 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 314509.
nullptr.cpp added a comment.

Fix use-of-uninitialized-value and `-Wreturn-std-move` with delete function


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92936

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp

Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -324,11 +324,29 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:11-[[@LINE-3]]:12}:"std::move(d)"
 }
 
-void ok_throw1() { Derived d; throw d; }
+void ok_throw1() {
+  Derived d;
+  throw d;
+}
 void ok_throw2(Derived d) { throw d; }
-void ok_throw3(Derived& d) { throw d; }
+void ok_throw3(Derived ) { throw d; }
 void ok_throw4(Derived d) { throw std::move(d); }
-void ok_throw5(Derived& d) { throw std::move(d); }
-void ok_throw6(Derived& d) { throw static_cast(d); }
+void ok_throw5(Derived ) { throw std::move(d); }
+void ok_throw6(Derived ) { throw static_cast(d); }
 void ok_throw7(TriviallyCopyable d) { throw d; }
 void ok_throw8(OnlyCopyable d) { throw d; }
+
+namespace test_delete {
+struct Base {
+  Base();
+  Base(Base &&) = delete;
+  Base(Base const &);
+};
+
+struct Derived : public Base {};
+
+Base test_ok() {
+  Derived d;
+  return d;
+}
+} // namespace test_delete
Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=expected %s
+
+namespace test_delete_function {
+struct A1 {
+  A1();
+  A1(const A1 &);
+  A1(A1 &&) = delete; // expected-note {{'A1' has been explicitly marked deleted here}}
+};
+A1 test1() {
+  A1 a;
+  return a; // expected-error {{call to deleted constructor of 'test_delete_function::A1'}}
+}
+
+struct A2 {
+  A2();
+  A2(const A2 &);
+
+private:
+  A2(A2 &&); // expected-note {{declared private here}}
+};
+A2 test2() {
+  A2 a;
+  return a; // expected-error {{calling a private constructor of class 'test_delete_function::A2'}}
+}
+
+struct C {};
+
+struct B1 {
+  B1(C &);
+  B1(C &&) = delete; // expected-note {{'B1' has been explicitly marked deleted here}}
+};
+B1 test3() {
+  C c;
+  return c; // expected-error {{conversion function from 'test_delete_function::C' to 'test_delete_function::B1' invokes a deleted function}}
+}
+
+struct B2 {
+  B2(C &);
+
+private:
+  B2(C &&); // expected-note {{declared private here}}
+};
+B2 test4() {
+  C c;
+  return c; // expected-error {{calling a private constructor of class 'test_delete_function::B2'}}
+}
+} // namespace test_delete_function
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3118,11 +3118,16 @@
 /// If move-initialization is not possible, such that we must fall back to
 /// treating the operand as an lvalue, we will leave Res in its original
 /// invalid state.
-static void TryMoveInitialization(Sema , const InitializedEntity ,
+///
+/// \returns Whether we need to do the second overload resolution. If the first
+/// overload resolution fails, or if the first overload resolution succeeds but
+/// the selected constructor/operator doesn't match the additional criteria, we
+/// need to do the second overload resolution.
+static bool TryMoveInitialization(Sema , const InitializedEntity ,
   const VarDecl *NRVOCandidate,
   QualType ResultType, Expr *,
   bool ConvertingConstructorsOnly,
-  ExprResult ) {
+  bool IsDiagnosticsCheck, ExprResult ) {
   ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(),
 CK_NoOp, Value, VK_XValue, FPOptionsOverride());
 
@@ -3133,8 +3138,11 @@
 
   InitializationSequence Seq(S, Entity, Kind, InitExpr);
 
-  if (!Seq)
-return;
+  bool NeedSecondOverloadResolution = true;
+  if (!Seq &&
+  (IsDiagnosticsCheck || Seq.getFailedOverloadResult() != OR_Deleted)) {
+return NeedSecondOverloadResolution;
+  }
 
   for (const InitializationSequence::Step  : Seq.steps()) {
 if (Step.Kind != InitializationSequence::SK_ConstructorInitialization &&
@@ -3177,6 +3185,7 @@
   }
 }
 
+

[PATCH] D94011: [Sema] Fix deleted function problem in implicitly movable test

2021-01-04 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
nullptr.cpp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In implicitly movable test, a two-stage overload resolution is performed.
If the first overload resolution selects a deleted function, Clang directly
performs the second overload resolution, without checking whether the
deleted function matches the additional criteria.

This patch fixes the above problem.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94011

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=expected %s
+
+namespace test_delete_function {
+struct A1 {
+  A1();
+  A1(const A1 &);
+  A1(A1 &&) = delete; // expected-note {{'A1' has been explicitly marked deleted here}}
+};
+A1 test1() {
+  A1 a;
+  return a; // expected-error {{call to deleted constructor of 'test_delete_function::A1'}}
+}
+
+struct A2 {
+  A2();
+  A2(const A2 &);
+
+private:
+  A2(A2 &&); // expected-note {{declared private here}}
+};
+A2 test2() {
+  A2 a;
+  return a; // expected-error {{calling a private constructor of class 'test_delete_function::A2'}}
+}
+
+struct C {};
+
+struct B1 {
+  B1(C &);
+  B1(C &&) = delete; // expected-note {{'B1' has been explicitly marked deleted here}}
+};
+B1 test3() {
+  C c;
+  return c; // expected-error {{conversion function from 'test_delete_function::C' to 'test_delete_function::B1' invokes a deleted function}}
+}
+
+struct B2 {
+  B2(C &);
+
+private:
+  B2(C &&); // expected-note {{declared private here}}
+};
+B2 test4() {
+  C c;
+  return c; // expected-error {{calling a private constructor of class 'test_delete_function::B2'}}
+}
+} // namespace test_delete_function
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3118,7 +3118,12 @@
 /// If move-initialization is not possible, such that we must fall back to
 /// treating the operand as an lvalue, we will leave Res in its original
 /// invalid state.
-static void TryMoveInitialization(Sema , const InitializedEntity ,
+///
+/// \returns Whether we need to do the second overload resolution. If the first
+/// overload resolution fails, or if the first overload resolution succeeds but
+/// the selected constructor/operator doesn't match the additional criteria, we
+/// need to do the second overload resolution.
+static bool TryMoveInitialization(Sema , const InitializedEntity ,
   const VarDecl *NRVOCandidate,
   QualType ResultType, Expr *,
   bool ConvertingConstructorsOnly,
@@ -3133,8 +3138,10 @@
 
   InitializationSequence Seq(S, Entity, Kind, InitExpr);
 
-  if (!Seq)
-return;
+  bool NeedSecondOverloadResolution = true;
+  if (!Seq && Seq.getFailedOverloadResult() != OR_Deleted) {
+return NeedSecondOverloadResolution;
+  }
 
   for (const InitializationSequence::Step  : Seq.steps()) {
 if (Step.Kind != InitializationSequence::SK_ConstructorInitialization &&
@@ -3177,6 +3184,7 @@
   }
 }
 
+NeedSecondOverloadResolution = false;
 // Promote "AsRvalue" to the heap, since we now need this
 // expression node to persist.
 Value =
@@ -3187,6 +3195,8 @@
 // using the constructor we found.
 Res = Seq.Perform(S, Entity, Kind, Value);
   }
+
+  return NeedSecondOverloadResolution;
 }
 
 /// Perform the initialization of a potentially-movable value, which
@@ -3211,6 +3221,7 @@
   // select the constructor for the copy is first performed as if the object
   // were designated by an rvalue.
   ExprResult Res = ExprError();
+  bool NeedSecondOverloadResolution = true;
 
   if (AllowNRVO) {
 bool AffectedByCWG1579 = false;
@@ -3227,11 +3238,11 @@
 }
 
 if (NRVOCandidate) {
-  TryMoveInitialization(*this, Entity, NRVOCandidate, ResultType, Value,
-true, Res);
+  NeedSecondOverloadResolution = TryMoveInitialization(
+  *this, Entity, NRVOCandidate, ResultType, Value, true, Res);
 }
 
-if (!Res.isInvalid() && AffectedByCWG1579) {
+if (!NeedSecondOverloadResolution && AffectedByCWG1579) {
   QualType QT = NRVOCandidate->getType();
   if (QT.getNonReferenceType().getUnqualifiedType().isTriviallyCopyableType(
   Context)) {

[PATCH] D94006: [Sema] Fix use-of-uninitialized-value cause by 89b0972aa2f58f927633c63570b36550a17f4e63

2021-01-03 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
nullptr.cpp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94006

Files:
  clang/lib/Sema/SemaInit.cpp


Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5589,13 +5589,11 @@
   return false;
 }
 
-InitializationSequence::InitializationSequence(Sema ,
-   const InitializedEntity ,
-   const InitializationKind ,
-   MultiExprArg Args,
-   bool TopLevelOfInitList,
-   bool TreatUnavailableAsInvalid)
-: FailedCandidateSet(Kind.getLocation(), OverloadCandidateSet::CSK_Normal) 
{
+InitializationSequence::InitializationSequence(
+Sema , const InitializedEntity , const InitializationKind ,
+MultiExprArg Args, bool TopLevelOfInitList, bool TreatUnavailableAsInvalid)
+: FailedOverloadResult(OR_Success),
+  FailedCandidateSet(Kind.getLocation(), OverloadCandidateSet::CSK_Normal) 
{
   InitializeFrom(S, Entity, Kind, Args, TopLevelOfInitList,
  TreatUnavailableAsInvalid);
 }


Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5589,13 +5589,11 @@
   return false;
 }
 
-InitializationSequence::InitializationSequence(Sema ,
-   const InitializedEntity ,
-   const InitializationKind ,
-   MultiExprArg Args,
-   bool TopLevelOfInitList,
-   bool TreatUnavailableAsInvalid)
-: FailedCandidateSet(Kind.getLocation(), OverloadCandidateSet::CSK_Normal) {
+InitializationSequence::InitializationSequence(
+Sema , const InitializedEntity , const InitializationKind ,
+MultiExprArg Args, bool TopLevelOfInitList, bool TreatUnavailableAsInvalid)
+: FailedOverloadResult(OR_Success),
+  FailedCandidateSet(Kind.getLocation(), OverloadCandidateSet::CSK_Normal) {
   InitializeFrom(S, Entity, Kind, Args, TopLevelOfInitList,
  TreatUnavailableAsInvalid);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93955: [Sema] Add support for reporting multiple errors during initialization

2021-01-01 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 314214.
nullptr.cpp edited the summary of this revision.
nullptr.cpp added a comment.

Separate out D93962 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93955

Files:
  clang/include/clang/Sema/Initialization.h
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/diagnostic-initialization.cpp

Index: clang/test/SemaCXX/diagnostic-initialization.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/diagnostic-initialization.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify=expected %s
+
+namespace std {
+typedef decltype(sizeof(int)) size_t;
+
+template 
+class initializer_list {
+  const _E *__begin_;
+  size_t __size_;
+
+  initializer_list(const _E *__b, size_t __s)
+  : __begin_(__b),
+__size_(__s) {}
+
+public:
+  typedef _E value_type;
+  typedef const _E 
+  typedef const _E _reference;
+  typedef size_t size_type;
+
+  typedef const _E *iterator;
+  typedef const _E *const_iterator;
+
+  initializer_list() : __begin_(nullptr), __size_(0) {}
+
+  size_t size() const { return __size_; }
+  const _E *begin() const { return __begin_; }
+  const _E *end() const { return __begin_ + __size_; }
+};
+} // namespace std
+
+// C++11 [over.match.list]p1:
+//   In copy-list-initialization, if an explicit constructor is chosen, the
+//   initializer is ill-formed.
+struct A {
+  explicit A(std::initializer_list) = delete;
+  // expected-note@-1 {{'A' has been explicitly marked deleted here}}
+  // expected-note@-2 {{explicit constructor declared here}}
+};
+
+A a = {1, 2, 3};
+// expected-error@-1 {{call to deleted constructor of 'A'}}
+// expected-error@-2 {{chosen constructor is explicit in copy-initialization}}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -526,48 +526,52 @@
   // stlport does so too. Look for std::__debug for libstdc++, and for
   // std:: for stlport.  This is effectively a compiler-side implementation of
   // LWG2193.
-  if (!InitSeq && EmptyInitList && InitSeq.getFailureKind() ==
-  InitializationSequence::FK_ExplicitConstructor) {
-OverloadCandidateSet::iterator Best;
-OverloadingResult O =
-InitSeq.getFailedCandidateSet()
-.BestViableFunction(SemaRef, Kind.getLocation(), Best);
-(void)O;
-assert(O == OR_Success && "Inconsistent overload resolution");
-CXXConstructorDecl *CtorDecl = cast(Best->Function);
-CXXRecordDecl *R = CtorDecl->getParent();
-
-if (CtorDecl->getMinRequiredArguments() == 0 &&
-CtorDecl->isExplicit() && R->getDeclName() &&
-SemaRef.SourceMgr.isInSystemHeader(CtorDecl->getLocation())) {
-  bool IsInStd = false;
-  for (NamespaceDecl *ND = dyn_cast(R->getDeclContext());
-   ND && !IsInStd; ND = dyn_cast(ND->getParent())) {
-if (SemaRef.getStdNamespace()->InEnclosingNamespaceSetOf(ND))
-  IsInStd = true;
-  }
+  if (!InitSeq && EmptyInitList) {
+auto Failures = InitSeq.getFailureKind();
+if (Failures.end() !=
+std::find(Failures.begin(), Failures.end(),
+  InitializationSequence::FK_ExplicitConstructor)) {
+  OverloadCandidateSet::iterator Best;
+  OverloadingResult O = InitSeq.getFailedCandidateSet().BestViableFunction(
+  SemaRef, Kind.getLocation(), Best);
+  (void)O;
+  assert(O == OR_Success && "Inconsistent overload resolution");
+  CXXConstructorDecl *CtorDecl = cast(Best->Function);
+  CXXRecordDecl *R = CtorDecl->getParent();
+
+  if (CtorDecl->getMinRequiredArguments() == 0 && CtorDecl->isExplicit() &&
+  R->getDeclName() &&
+  SemaRef.SourceMgr.isInSystemHeader(CtorDecl->getLocation())) {
+bool IsInStd = false;
+for (NamespaceDecl *ND = dyn_cast(R->getDeclContext());
+ ND && !IsInStd; ND = dyn_cast(ND->getParent())) {
+  if (SemaRef.getStdNamespace()->InEnclosingNamespaceSetOf(ND))
+IsInStd = true;
+}
 
-  if (IsInStd && llvm::StringSwitch(R->getName())
-  .Cases("basic_string", "deque", "forward_list", true)
-  .Cases("list", "map", "multimap", "multiset", true)
-  .Cases("priority_queue", "queue", "set", "stack", true)
-  .Cases("unordered_map", "unordered_set", "vector", true)
-  .Default(false)) {
-InitSeq.InitializeFrom(
-SemaRef, Entity,
-InitializationKind::CreateValue(Loc, Loc, Loc, true),
-MultiExprArg(), /*TopLevelOfInitList=*/false,
-TreatUnavailableAsInvalid);
-// Emit a warning for this.  System header warnings aren't shown
-// by default, but people working on 

[PATCH] D93962: [Sema] Fix the program state in reference initialization

2021-01-01 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
nullptr.cpp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

According to [dcl.init.ref]p5:

> A reference to type “cv1 T1” is initialized by an expression of type “cv2 T2”
>  as follows:
>
>   — If the reference is an lvalue reference and the initializer expression
> — is an lvalue (but is not a bit-field), and “cv1 T1” is
>   reference-compatible with “cv2 T2”, or
> — has a class type (i.e., T2 is a class type), where T1 is not
>   reference-related to T2, and can be converted to an lvalue of type
>   “cv3 T3”, where “cv1 T1” is reference-compatible with “cv3 T3” (this
>   conversion is selected by enumerating the applicable conversion 
> functions
>   and choosing the best one through overload resolution),
> then the reference is bound to the initializer expression lvalue in the
> first case and to the lvalue result of the conversion in the second case
> (or, in either case, to the appropriate base class subobject of the 
> object).
>   
>   — Otherwise, [...]

If the overload resolution fails in the second case, the program should continue
to check other conditions and the program is NOT ill-formed at this point. But
the code here sets the program to ill-formed state.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93962

Files:
  clang/lib/Sema/SemaInit.cpp


Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -4811,10 +4811,6 @@
 /*IsLValueRef*/ isLValueRef, Sequence);
 if (ConvOvlResult == OR_Success)
   return;
-if (ConvOvlResult != OR_No_Viable_Function)
-  Sequence.SetOverloadFailure(
-  InitializationSequence::FK_ReferenceInitOverloadFailed,
-  ConvOvlResult);
   } else {
 ConvOvlResult = OR_No_Viable_Function;
   }


Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -4811,10 +4811,6 @@
 /*IsLValueRef*/ isLValueRef, Sequence);
 if (ConvOvlResult == OR_Success)
   return;
-if (ConvOvlResult != OR_No_Viable_Function)
-  Sequence.SetOverloadFailure(
-  InitializationSequence::FK_ReferenceInitOverloadFailed,
-  ConvOvlResult);
   } else {
 ConvOvlResult = OR_No_Viable_Function;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93961: [clang-tidy][NFC] Fix a build warning due to an extra semicolon

2021-01-01 Thread Yang Fan via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd5324c052b21: [clang-tidy][NFC] Fix a build warning due to 
an extra semicolon (authored by nullptr.cpp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93961

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp


Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -392,7 +392,7 @@
 
 static void diagHandlerImpl(const llvm::SMDiagnostic , void *Ctx) {
   (*reinterpret_cast(Ctx))(Diag);
-};
+}
 
 llvm::ErrorOr
 parseConfigurationWithDiags(llvm::MemoryBufferRef Config,


Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -392,7 +392,7 @@
 
 static void diagHandlerImpl(const llvm::SMDiagnostic , void *Ctx) {
   (*reinterpret_cast(Ctx))(Diag);
-};
+}
 
 llvm::ErrorOr
 parseConfigurationWithDiags(llvm::MemoryBufferRef Config,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92936: [Sema] Fix deleted function problem in implicitly movable test

2020-12-31 Thread Yang Fan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG89b0972aa2f5: [Sema] Fix deleted function problem in 
implicitly movable test (authored by nullptr.cpp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92936

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=expected %s
+
+namespace test_delete_function {
+struct A1 {
+  A1();
+  A1(const A1 &);
+  A1(A1 &&) = delete; // expected-note {{'A1' has been explicitly marked deleted here}}
+};
+A1 test1() {
+  A1 a;
+  return a; // expected-error {{call to deleted constructor of 'test_delete_function::A1'}}
+}
+
+struct A2 {
+  A2();
+  A2(const A2 &);
+
+private:
+  A2(A2 &&); // expected-note {{declared private here}}
+};
+A2 test2() {
+  A2 a;
+  return a; // expected-error {{calling a private constructor of class 'test_delete_function::A2'}}
+}
+
+struct C {};
+
+struct B1 {
+  B1(C &);
+  B1(C &&) = delete; // expected-note {{'B1' has been explicitly marked deleted here}}
+};
+B1 test3() {
+  C c;
+  return c; // expected-error {{conversion function from 'test_delete_function::C' to 'test_delete_function::B1' invokes a deleted function}}
+}
+
+struct B2 {
+  B2(C &);
+
+private:
+  B2(C &&); // expected-note {{declared private here}}
+};
+B2 test4() {
+  C c;
+  return c; // expected-error {{calling a private constructor of class 'test_delete_function::B2'}}
+}
+} // namespace test_delete_function
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3118,11 +3118,14 @@
 /// If move-initialization is not possible, such that we must fall back to
 /// treating the operand as an lvalue, we will leave Res in its original
 /// invalid state.
-static void TryMoveInitialization(Sema& S,
-  const InitializedEntity ,
+///
+/// \returns Whether we need to do the second overload resolution. If the first
+/// overload resolution fails, or if the first overload resolution succeeds but
+/// the selected constructor/operator doesn't match the additional criteria, we
+/// need to do the second overload resolution.
+static bool TryMoveInitialization(Sema , const InitializedEntity ,
   const VarDecl *NRVOCandidate,
-  QualType ResultType,
-  Expr *,
+  QualType ResultType, Expr *,
   bool ConvertingConstructorsOnly,
   ExprResult ) {
   ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(),
@@ -3135,8 +3138,10 @@
 
   InitializationSequence Seq(S, Entity, Kind, InitExpr);
 
-  if (!Seq)
-return;
+  bool NeedSecondOverloadResolution = true;
+  if (!Seq && Seq.getFailedOverloadResult() != OR_Deleted) {
+return NeedSecondOverloadResolution;
+  }
 
   for (const InitializationSequence::Step  : Seq.steps()) {
 if (Step.Kind != InitializationSequence::SK_ConstructorInitialization &&
@@ -3179,6 +3184,7 @@
   }
 }
 
+NeedSecondOverloadResolution = false;
 // Promote "AsRvalue" to the heap, since we now need this
 // expression node to persist.
 Value =
@@ -3189,6 +3195,8 @@
 // using the constructor we found.
 Res = Seq.Perform(S, Entity, Kind, Value);
   }
+
+  return NeedSecondOverloadResolution;
 }
 
 /// Perform the initialization of a potentially-movable value, which
@@ -3213,6 +3221,7 @@
   // select the constructor for the copy is first performed as if the object
   // were designated by an rvalue.
   ExprResult Res = ExprError();
+  bool NeedSecondOverloadResolution = true;
 
   if (AllowNRVO) {
 bool AffectedByCWG1579 = false;
@@ -3229,11 +3238,11 @@
 }
 
 if (NRVOCandidate) {
-  TryMoveInitialization(*this, Entity, NRVOCandidate, ResultType, Value,
-true, Res);
+  NeedSecondOverloadResolution = TryMoveInitialization(
+  *this, Entity, NRVOCandidate, ResultType, Value, true, Res);
 }
 
-if (!Res.isInvalid() && AffectedByCWG1579) {
+if (!NeedSecondOverloadResolution && AffectedByCWG1579) {
   QualType QT = NRVOCandidate->getType();
   if (QT.getNonReferenceType()
   

[PATCH] D93961: [clang-tidy][NFC] Fix a build warning due to an extra semicolon

2020-12-31 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
Herald added a subscriber: xazax.hun.
nullptr.cpp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93961

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp


Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -392,7 +392,7 @@
 
 static void diagHandlerImpl(const llvm::SMDiagnostic , void *Ctx) {
   (*reinterpret_cast(Ctx))(Diag);
-};
+}
 
 llvm::ErrorOr
 parseConfigurationWithDiags(llvm::MemoryBufferRef Config,


Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -392,7 +392,7 @@
 
 static void diagHandlerImpl(const llvm::SMDiagnostic , void *Ctx) {
   (*reinterpret_cast(Ctx))(Diag);
-};
+}
 
 llvm::ErrorOr
 parseConfigurationWithDiags(llvm::MemoryBufferRef Config,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92936: [Sema] Fix deleted function problem in implicitly movable test

2020-12-31 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 314208.
nullptr.cpp added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92936

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=expected %s
+
+namespace test_delete_function {
+struct A1 {
+  A1();
+  A1(const A1 &);
+  A1(A1 &&) = delete; // expected-note {{'A1' has been explicitly marked deleted here}}
+};
+A1 test1() {
+  A1 a;
+  return a; // expected-error {{call to deleted constructor of 'test_delete_function::A1'}}
+}
+
+struct A2 {
+  A2();
+  A2(const A2 &);
+
+private:
+  A2(A2 &&); // expected-note {{declared private here}}
+};
+A2 test2() {
+  A2 a;
+  return a; // expected-error {{calling a private constructor of class 'test_delete_function::A2'}}
+}
+
+struct C {};
+
+struct B1 {
+  B1(C &);
+  B1(C &&) = delete; // expected-note {{'B1' has been explicitly marked deleted here}}
+};
+B1 test3() {
+  C c;
+  return c; // expected-error {{conversion function from 'test_delete_function::C' to 'test_delete_function::B1' invokes a deleted function}}
+}
+
+struct B2 {
+  B2(C &);
+
+private:
+  B2(C &&); // expected-note {{declared private here}}
+};
+B2 test4() {
+  C c;
+  return c; // expected-error {{calling a private constructor of class 'test_delete_function::B2'}}
+}
+} // namespace test_delete_function
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3118,11 +3118,14 @@
 /// If move-initialization is not possible, such that we must fall back to
 /// treating the operand as an lvalue, we will leave Res in its original
 /// invalid state.
-static void TryMoveInitialization(Sema& S,
-  const InitializedEntity ,
+///
+/// \returns Whether we need to do the second overload resolution. If the first
+/// overload resolution fails, or if the first overload resolution succeeds but
+/// the selected constructor/operator doesn't match the additional criteria, we
+/// need to do the second overload resolution.
+static bool TryMoveInitialization(Sema , const InitializedEntity ,
   const VarDecl *NRVOCandidate,
-  QualType ResultType,
-  Expr *,
+  QualType ResultType, Expr *,
   bool ConvertingConstructorsOnly,
   ExprResult ) {
   ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(),
@@ -3135,8 +3138,10 @@
 
   InitializationSequence Seq(S, Entity, Kind, InitExpr);
 
-  if (!Seq)
-return;
+  bool NeedSecondOverloadResolution = true;
+  if (!Seq && Seq.getFailedOverloadResult() != OR_Deleted) {
+return NeedSecondOverloadResolution;
+  }
 
   for (const InitializationSequence::Step  : Seq.steps()) {
 if (Step.Kind != InitializationSequence::SK_ConstructorInitialization &&
@@ -3179,6 +3184,7 @@
   }
 }
 
+NeedSecondOverloadResolution = false;
 // Promote "AsRvalue" to the heap, since we now need this
 // expression node to persist.
 Value =
@@ -3189,6 +3195,8 @@
 // using the constructor we found.
 Res = Seq.Perform(S, Entity, Kind, Value);
   }
+
+  return NeedSecondOverloadResolution;
 }
 
 /// Perform the initialization of a potentially-movable value, which
@@ -3213,6 +3221,7 @@
   // select the constructor for the copy is first performed as if the object
   // were designated by an rvalue.
   ExprResult Res = ExprError();
+  bool NeedSecondOverloadResolution = true;
 
   if (AllowNRVO) {
 bool AffectedByCWG1579 = false;
@@ -3229,11 +3238,11 @@
 }
 
 if (NRVOCandidate) {
-  TryMoveInitialization(*this, Entity, NRVOCandidate, ResultType, Value,
-true, Res);
+  NeedSecondOverloadResolution = TryMoveInitialization(
+  *this, Entity, NRVOCandidate, ResultType, Value, true, Res);
 }
 
-if (!Res.isInvalid() && AffectedByCWG1579) {
+if (!NeedSecondOverloadResolution && AffectedByCWG1579) {
   QualType QT = NRVOCandidate->getType();
   if (QT.getNonReferenceType()
  .getUnqualifiedType()
@@ -3256,7 +3265,7 @@
 Diag(Value->getExprLoc(), 

[PATCH] D93955: [Sema] Add support for reporting multiple errors during initialization

2020-12-31 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 314177.
nullptr.cpp edited the summary of this revision.
nullptr.cpp added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93955

Files:
  clang/include/clang/Sema/Initialization.h
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/diagnostic-overload-resolution.cpp

Index: clang/test/SemaCXX/diagnostic-overload-resolution.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/diagnostic-overload-resolution.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify=expected %s
+
+namespace std {
+typedef decltype(sizeof(int)) size_t;
+
+template 
+class initializer_list {
+  const _E *__begin_;
+  size_t __size_;
+
+  initializer_list(const _E *__b, size_t __s)
+  : __begin_(__b),
+__size_(__s) {}
+
+public:
+  typedef _E value_type;
+  typedef const _E 
+  typedef const _E _reference;
+  typedef size_t size_type;
+
+  typedef const _E *iterator;
+  typedef const _E *const_iterator;
+
+  initializer_list() : __begin_(nullptr), __size_(0) {}
+
+  size_t size() const { return __size_; }
+  const _E *begin() const { return __begin_; }
+  const _E *end() const { return __begin_ + __size_; }
+};
+} // namespace std
+
+// C++11 [over.match.list]p1:
+//   In copy-list-initialization, if an explicit constructor is chosen, the
+//   initializer is ill-formed.
+struct A {
+  explicit A(std::initializer_list) = delete;
+  // expected-note@-1 {{'A' has been explicitly marked deleted here}}
+  // expected-note@-2 {{explicit constructor declared here}}
+};
+
+A a = {1, 2, 3};
+// expected-error@-1 {{call to deleted constructor of 'A'}}
+// expected-error@-2 {{chosen constructor is explicit in copy-initialization}}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -526,48 +526,52 @@
   // stlport does so too. Look for std::__debug for libstdc++, and for
   // std:: for stlport.  This is effectively a compiler-side implementation of
   // LWG2193.
-  if (!InitSeq && EmptyInitList && InitSeq.getFailureKind() ==
-  InitializationSequence::FK_ExplicitConstructor) {
-OverloadCandidateSet::iterator Best;
-OverloadingResult O =
-InitSeq.getFailedCandidateSet()
-.BestViableFunction(SemaRef, Kind.getLocation(), Best);
-(void)O;
-assert(O == OR_Success && "Inconsistent overload resolution");
-CXXConstructorDecl *CtorDecl = cast(Best->Function);
-CXXRecordDecl *R = CtorDecl->getParent();
-
-if (CtorDecl->getMinRequiredArguments() == 0 &&
-CtorDecl->isExplicit() && R->getDeclName() &&
-SemaRef.SourceMgr.isInSystemHeader(CtorDecl->getLocation())) {
-  bool IsInStd = false;
-  for (NamespaceDecl *ND = dyn_cast(R->getDeclContext());
-   ND && !IsInStd; ND = dyn_cast(ND->getParent())) {
-if (SemaRef.getStdNamespace()->InEnclosingNamespaceSetOf(ND))
-  IsInStd = true;
-  }
+  if (!InitSeq && EmptyInitList) {
+auto Failures = InitSeq.getFailureKind();
+if (Failures.end() !=
+std::find(Failures.begin(), Failures.end(),
+  InitializationSequence::FK_ExplicitConstructor)) {
+  OverloadCandidateSet::iterator Best;
+  OverloadingResult O = InitSeq.getFailedCandidateSet().BestViableFunction(
+  SemaRef, Kind.getLocation(), Best);
+  (void)O;
+  assert(O == OR_Success && "Inconsistent overload resolution");
+  CXXConstructorDecl *CtorDecl = cast(Best->Function);
+  CXXRecordDecl *R = CtorDecl->getParent();
+
+  if (CtorDecl->getMinRequiredArguments() == 0 && CtorDecl->isExplicit() &&
+  R->getDeclName() &&
+  SemaRef.SourceMgr.isInSystemHeader(CtorDecl->getLocation())) {
+bool IsInStd = false;
+for (NamespaceDecl *ND = dyn_cast(R->getDeclContext());
+ ND && !IsInStd; ND = dyn_cast(ND->getParent())) {
+  if (SemaRef.getStdNamespace()->InEnclosingNamespaceSetOf(ND))
+IsInStd = true;
+}
 
-  if (IsInStd && llvm::StringSwitch(R->getName())
-  .Cases("basic_string", "deque", "forward_list", true)
-  .Cases("list", "map", "multimap", "multiset", true)
-  .Cases("priority_queue", "queue", "set", "stack", true)
-  .Cases("unordered_map", "unordered_set", "vector", true)
-  .Default(false)) {
-InitSeq.InitializeFrom(
-SemaRef, Entity,
-InitializationKind::CreateValue(Loc, Loc, Loc, true),
-MultiExprArg(), /*TopLevelOfInitList=*/false,
-TreatUnavailableAsInvalid);
-// Emit a warning for this.  System header warnings aren't shown
-// by default, but people working on system headers should see it.
-  

[PATCH] D93955: [Sema] Add support for reporting multiple errors during initialization

2020-12-31 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
nullptr.cpp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

During the initialization process, more than one error may be encountered, but
Clang reports only one of them. This patch makes Clang report all errors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93955

Files:
  clang/include/clang/Sema/Initialization.h
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/diagnostic-overload-resolution.cpp

Index: clang/test/SemaCXX/diagnostic-overload-resolution.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/diagnostic-overload-resolution.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify=expected %s
+
+namespace std {
+typedef decltype(sizeof(int)) size_t;
+
+template 
+class initializer_list {
+  const _E *__begin_;
+  size_t __size_;
+
+  initializer_list(const _E *__b, size_t __s)
+  : __begin_(__b),
+__size_(__s) {}
+
+public:
+  typedef _E value_type;
+  typedef const _E 
+  typedef const _E _reference;
+  typedef size_t size_type;
+
+  typedef const _E *iterator;
+  typedef const _E *const_iterator;
+
+  initializer_list() : __begin_(nullptr), __size_(0) {}
+
+  size_t size() const { return __size_; }
+  const _E *begin() const { return __begin_; }
+  const _E *end() const { return __begin_ + __size_; }
+};
+} // namespace std
+
+// C++11 [over.match.list]p1:
+//   In copy-list-initialization, if an explicit constructor is chosen, the
+//   initializer is ill-formed.
+struct A {
+  explicit A(std::initializer_list) = delete;
+  // expected-note@-1 {{'A' has been explicitly marked deleted here}}
+  // expected-note@-2 {{explicit constructor declared here}}
+};
+
+A a = {1, 2, 3};
+// expected-error@-1 {{call to deleted constructor of 'A'}}
+// expected-error@-2 {{chosen constructor is explicit in copy-initialization}}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -526,48 +526,52 @@
   // stlport does so too. Look for std::__debug for libstdc++, and for
   // std:: for stlport.  This is effectively a compiler-side implementation of
   // LWG2193.
-  if (!InitSeq && EmptyInitList && InitSeq.getFailureKind() ==
-  InitializationSequence::FK_ExplicitConstructor) {
-OverloadCandidateSet::iterator Best;
-OverloadingResult O =
-InitSeq.getFailedCandidateSet()
-.BestViableFunction(SemaRef, Kind.getLocation(), Best);
-(void)O;
-assert(O == OR_Success && "Inconsistent overload resolution");
-CXXConstructorDecl *CtorDecl = cast(Best->Function);
-CXXRecordDecl *R = CtorDecl->getParent();
-
-if (CtorDecl->getMinRequiredArguments() == 0 &&
-CtorDecl->isExplicit() && R->getDeclName() &&
-SemaRef.SourceMgr.isInSystemHeader(CtorDecl->getLocation())) {
-  bool IsInStd = false;
-  for (NamespaceDecl *ND = dyn_cast(R->getDeclContext());
-   ND && !IsInStd; ND = dyn_cast(ND->getParent())) {
-if (SemaRef.getStdNamespace()->InEnclosingNamespaceSetOf(ND))
-  IsInStd = true;
-  }
+  if (!InitSeq && EmptyInitList) {
+auto Failures = InitSeq.getFailureKind();
+if (Failures.end() !=
+std::find(Failures.begin(), Failures.end(),
+  InitializationSequence::FK_ExplicitConstructor)) {
+  OverloadCandidateSet::iterator Best;
+  OverloadingResult O = InitSeq.getFailedCandidateSet().BestViableFunction(
+  SemaRef, Kind.getLocation(), Best);
+  (void)O;
+  assert(O == OR_Success && "Inconsistent overload resolution");
+  CXXConstructorDecl *CtorDecl = cast(Best->Function);
+  CXXRecordDecl *R = CtorDecl->getParent();
+
+  if (CtorDecl->getMinRequiredArguments() == 0 && CtorDecl->isExplicit() &&
+  R->getDeclName() &&
+  SemaRef.SourceMgr.isInSystemHeader(CtorDecl->getLocation())) {
+bool IsInStd = false;
+for (NamespaceDecl *ND = dyn_cast(R->getDeclContext());
+ ND && !IsInStd; ND = dyn_cast(ND->getParent())) {
+  if (SemaRef.getStdNamespace()->InEnclosingNamespaceSetOf(ND))
+IsInStd = true;
+}
 
-  if (IsInStd && llvm::StringSwitch(R->getName())
-  .Cases("basic_string", "deque", "forward_list", true)
-  .Cases("list", "map", "multimap", "multiset", true)
-  .Cases("priority_queue", "queue", "set", "stack", true)
-  .Cases("unordered_map", "unordered_set", "vector", true)
-  .Default(false)) {
-InitSeq.InitializeFrom(
-SemaRef, Entity,
-InitializationKind::CreateValue(Loc, Loc, Loc, true),
-MultiExprArg(), /*TopLevelOfInitList=*/false,
-TreatUnavailableAsInvalid);
-// Emit a warning for this.  System header 

[PATCH] D88220: [C++20] P1825R0: More implicit moves

2020-12-29 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

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


[PATCH] D88220: [C++20] P1825R0: More implicit moves

2020-12-28 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 313831.
nullptr.cpp added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1203,6 +1203,11 @@
   https://wg21.link/p0593r6;>P0593R6 (DR)
   Clang 11
 
+
+More implicit moves
+https://wg21.link/p1825r0;>P1825R0 (DR)
+Clang 12
+
 
 
 
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,5 +1,11 @@
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++20 -verify=cxx20 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -verify=cxx11_14_17 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -verify=cxx11_14_17 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -verify=cxx11_14_17 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CXX11_14_17-CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CXX11_14_17-CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CXX11_14_17-CHECK
+// cxx20-no-diagnostics
 
 // definitions for std::move
 namespace std {
@@ -71,37 +77,34 @@
 Base test2() {
 Derived d2;
 return d2;  // e1
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
+// cxx11_14_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_14_17-note@-2{{to avoid copying}}
+// CXX11_14_17-CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
 }
 ConstructFromDerived test3() {
 Derived d3;
-return d3;  // e2-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d3)"
+return d3; // ok
 }
 ConstructFromBase test4() {
 Derived d4;
 return d4;  // e3
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d4)"
+// cxx11_14_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_14_17-note@-2{{to avoid copying}}
+// CXX11_14_17-CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d4)"
 }
 ConvertFromDerived test5() {
 Derived d5;
 return d5;  // e4
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d5)"
+// cxx11_14_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_14_17-note@-2{{to avoid copying}}
+// CXX11_14_17-CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d5)"
 }
 ConvertFromBase test6() {
 Derived d6;
 return d6;  // e5
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d6)"
+// cxx11_14_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_14_17-note@-2{{to avoid copying}}
+// CXX11_14_17-CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d6)"
 }
 
 // These test cases should not produce the warning.
@@ -148,93 +151,89 @@
 Derived 

[PATCH] D92936: [Sema] Fix deleted function problem in implicitly movable test

2020-12-27 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 313828.
nullptr.cpp added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92936

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=expected %s
+
+namespace test_delete_function {
+struct A1 {
+  A1();
+  A1(const A1 &);
+  A1(A1 &&) = delete; // expected-note {{'A1' has been explicitly marked deleted here}}
+};
+A1 test1() {
+  A1 a;
+  return a; // expected-error {{call to deleted constructor of 'test_delete_function::A1'}}
+}
+
+struct A2 {
+  A2();
+  A2(const A2 &);
+
+private:
+  A2(A2 &&); // expected-note {{declared private here}}
+};
+A2 test2() {
+  A2 a;
+  return a; // expected-error {{calling a private constructor of class 'test_delete_function::A2'}}
+}
+
+struct C {};
+
+struct B1 {
+  B1(C &);
+  B1(C &&) = delete; // expected-note {{'B1' has been explicitly marked deleted here}}
+};
+B1 test3() {
+  C c;
+  return c; // expected-error {{conversion function from 'test_delete_function::C' to 'test_delete_function::B1' invokes a deleted function}}
+}
+
+struct B2 {
+  B2(C &);
+
+private:
+  B2(C &&); // expected-note {{declared private here}}
+};
+B2 test4() {
+  C c;
+  return c; // expected-error {{calling a private constructor of class 'test_delete_function::B2'}}
+}
+} // namespace test_delete_function
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3118,11 +3118,14 @@
 /// If move-initialization is not possible, such that we must fall back to
 /// treating the operand as an lvalue, we will leave Res in its original
 /// invalid state.
-static void TryMoveInitialization(Sema& S,
-  const InitializedEntity ,
+///
+/// \returns Whether we need to do the second overload resolution. If the first
+/// overload resolution fails, or if the first overload resolution succeeds but
+/// the selected constructor/operator doesn't match the additional criteria, we
+/// need to do the second overload resolution.
+static bool TryMoveInitialization(Sema , const InitializedEntity ,
   const VarDecl *NRVOCandidate,
-  QualType ResultType,
-  Expr *,
+  QualType ResultType, Expr *,
   bool ConvertingConstructorsOnly,
   ExprResult ) {
   ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(),
@@ -3135,8 +3138,10 @@
 
   InitializationSequence Seq(S, Entity, Kind, InitExpr);
 
-  if (!Seq)
-return;
+  bool NeedSecondOverloadResolution = true;
+  if (!Seq && Seq.getFailedOverloadResult() != OR_Deleted) {
+return NeedSecondOverloadResolution;
+  }
 
   for (const InitializationSequence::Step  : Seq.steps()) {
 if (Step.Kind != InitializationSequence::SK_ConstructorInitialization &&
@@ -3179,6 +3184,7 @@
   }
 }
 
+NeedSecondOverloadResolution = false;
 // Promote "AsRvalue" to the heap, since we now need this
 // expression node to persist.
 Value =
@@ -3189,6 +3195,8 @@
 // using the constructor we found.
 Res = Seq.Perform(S, Entity, Kind, Value);
   }
+
+  return NeedSecondOverloadResolution;
 }
 
 /// Perform the initialization of a potentially-movable value, which
@@ -3213,6 +3221,7 @@
   // select the constructor for the copy is first performed as if the object
   // were designated by an rvalue.
   ExprResult Res = ExprError();
+  bool NeedSecondOverloadResolution = true;
 
   if (AllowNRVO) {
 bool AffectedByCWG1579 = false;
@@ -3229,11 +3238,11 @@
 }
 
 if (NRVOCandidate) {
-  TryMoveInitialization(*this, Entity, NRVOCandidate, ResultType, Value,
-true, Res);
+  NeedSecondOverloadResolution = TryMoveInitialization(
+  *this, Entity, NRVOCandidate, ResultType, Value, true, Res);
 }
 
-if (!Res.isInvalid() && AffectedByCWG1579) {
+if (!NeedSecondOverloadResolution && AffectedByCWG1579) {
   QualType QT = NRVOCandidate->getType();
   if (QT.getNonReferenceType()
  .getUnqualifiedType()
@@ -3256,7 +3265,7 @@
 Diag(Value->getExprLoc(), 

[PATCH] D92936: [Sema] Fix deleted function problem in implicitly movable test

2020-12-23 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92936

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


[PATCH] D88220: [C++20] P1825R0: More implicit moves

2020-12-22 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 313493.
nullptr.cpp added a comment.

Add more tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1203,6 +1203,11 @@
   https://wg21.link/p0593r6;>P0593R6 (DR)
   Clang 11
 
+
+More implicit moves
+https://wg21.link/p1825r0;>P1825R0 (DR)
+Clang 12
+
 
 
 
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,5 +1,11 @@
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++20 -verify=cxx20 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -verify=cxx11_14_17 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -verify=cxx11_14_17 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -verify=cxx11_14_17 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CXX11_14_17-CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CXX11_14_17-CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CXX11_14_17-CHECK
+// cxx20-no-diagnostics
 
 // definitions for std::move
 namespace std {
@@ -71,37 +77,34 @@
 Base test2() {
 Derived d2;
 return d2;  // e1
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
+// cxx11_14_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_14_17-note@-2{{to avoid copying}}
+// CXX11_14_17-CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
 }
 ConstructFromDerived test3() {
 Derived d3;
-return d3;  // e2-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d3)"
+return d3; // ok
 }
 ConstructFromBase test4() {
 Derived d4;
 return d4;  // e3
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d4)"
+// cxx11_14_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_14_17-note@-2{{to avoid copying}}
+// CXX11_14_17-CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d4)"
 }
 ConvertFromDerived test5() {
 Derived d5;
 return d5;  // e4
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d5)"
+// cxx11_14_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_14_17-note@-2{{to avoid copying}}
+// CXX11_14_17-CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d5)"
 }
 ConvertFromBase test6() {
 Derived d6;
 return d6;  // e5
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d6)"
+// cxx11_14_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_14_17-note@-2{{to avoid copying}}
+// CXX11_14_17-CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d6)"
 }
 
 // These test cases should not produce the warning.
@@ -148,93 +151,89 @@
 Derived 

[PATCH] D92936: [Sema] Fix deleted function problem in implicitly movable test

2020-12-11 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

Note: The failed test has nothing to do with this patch.




Comment at: clang/lib/Sema/SemaInit.cpp:4146
   CXXConstructorDecl *CtorDecl = cast(Best->Function);
-  if (Kind.getKind() == InitializationKind::IK_Default &&
-  Entity.getType().isConstQualified()) {
-if (!CtorDecl->getParent()->allowConstDefaultInit()) {
-  if (!maybeRecoverWithZeroInitialization(S, Sequence, Entity))
-Sequence.SetFailed(InitializationSequence::FK_DefaultInitOfConst);
+  if (Result != OR_Deleted) { // TODO: Support for more than one failure.
+// C++11 [dcl.init]p6:

I'll send another patch to make Clang report both deleted function error and 
the following error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92936

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


[PATCH] D92936: [Sema] Fix deleted function problem in implicitly movable test

2020-12-11 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 311158.
nullptr.cpp added a comment.

Fix format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92936

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=expected %s
+
+namespace test_delete_function {
+struct A1 {
+  A1();
+  A1(const A1 &);
+  A1(A1 &&) = delete; // expected-note {{'A1' has been explicitly marked deleted here}}
+};
+A1 test1() {
+  A1 a;
+  return a; // expected-error {{call to deleted constructor of 'test_delete_function::A1'}}
+}
+
+struct A2 {
+  A2();
+  A2(const A2 &);
+
+private:
+  A2(A2 &&); // expected-note {{declared private here}}
+};
+A2 test2() {
+  A2 a;
+  return a; // expected-error {{calling a private constructor of class 'test_delete_function::A2'}}
+}
+
+struct C {};
+
+struct B1 {
+  B1(C &);
+  B1(C &&) = delete; // expected-note {{'B1' has been explicitly marked deleted here}}
+};
+B1 test3() {
+  C c;
+  return c; // expected-error {{conversion function from 'test_delete_function::C' to 'test_delete_function::B1' invokes a deleted function}}
+}
+
+struct B2 {
+  B2(C &);
+
+private:
+  B2(C &&); // expected-note {{declared private here}}
+};
+B2 test4() {
+  C c;
+  return c; // expected-error {{calling a private constructor of class 'test_delete_function::B2'}}
+}
+} // namespace test_delete_function
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3106,11 +3106,14 @@
 /// If move-initialization is not possible, such that we must fall back to
 /// treating the operand as an lvalue, we will leave Res in its original
 /// invalid state.
-static void TryMoveInitialization(Sema& S,
-  const InitializedEntity ,
+///
+/// \returns Whether we need to do the second overload resolution. If the first
+/// overload resolution fails, or if the first overload resolution succeeds but
+/// the selected constructor/operator doesn't match the additional criteria, we
+/// need to do the second overload resolution.
+static bool TryMoveInitialization(Sema , const InitializedEntity ,
   const VarDecl *NRVOCandidate,
-  QualType ResultType,
-  Expr *,
+  QualType ResultType, Expr *,
   bool ConvertingConstructorsOnly,
   ExprResult ) {
   ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(),
@@ -3123,8 +3126,10 @@
 
   InitializationSequence Seq(S, Entity, Kind, InitExpr);
 
-  if (!Seq)
-return;
+  bool NeedSecondOverloadResolution = true;
+  if (!Seq && Seq.getFailedOverloadResult() != OR_Deleted) {
+return NeedSecondOverloadResolution;
+  }
 
   for (const InitializationSequence::Step  : Seq.steps()) {
 if (Step.Kind != InitializationSequence::SK_ConstructorInitialization &&
@@ -3167,6 +3172,7 @@
   }
 }
 
+NeedSecondOverloadResolution = false;
 // Promote "AsRvalue" to the heap, since we now need this
 // expression node to persist.
 Value =
@@ -3177,6 +3183,8 @@
 // using the constructor we found.
 Res = Seq.Perform(S, Entity, Kind, Value);
   }
+
+  return NeedSecondOverloadResolution;
 }
 
 /// Perform the initialization of a potentially-movable value, which
@@ -3201,6 +3209,7 @@
   // select the constructor for the copy is first performed as if the object
   // were designated by an rvalue.
   ExprResult Res = ExprError();
+  bool NeedSecondOverloadResolution = true;
 
   if (AllowNRVO) {
 bool AffectedByCWG1579 = false;
@@ -3217,11 +3226,11 @@
 }
 
 if (NRVOCandidate) {
-  TryMoveInitialization(*this, Entity, NRVOCandidate, ResultType, Value,
-true, Res);
+  NeedSecondOverloadResolution = TryMoveInitialization(
+  *this, Entity, NRVOCandidate, ResultType, Value, true, Res);
 }
 
-if (!Res.isInvalid() && AffectedByCWG1579) {
+if (!NeedSecondOverloadResolution && AffectedByCWG1579) {
   QualType QT = NRVOCandidate->getType();
   if (QT.getNonReferenceType()
  .getUnqualifiedType()
@@ -3244,7 +3253,7 @@
 Diag(Value->getExprLoc(), 

[PATCH] D92936: [Sema] Fix deleted function problem in implicitly movable test

2020-12-11 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 311137.
nullptr.cpp added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92936

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=expected %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=expected %s
+
+namespace test_delete_function {
+struct A1 {
+  A1();
+  A1(const A1 &);
+  A1(A1 &&) = delete; // expected-note {{'A1' has been explicitly marked deleted here}}
+};
+A1 test1() {
+  A1 a;
+  return a; // expected-error {{call to deleted constructor of 'test_delete_function::A1'}}
+}
+
+struct A2 {
+  A2();
+  A2(const A2 &);
+private:
+  A2(A2 &&); // expected-note {{declared private here}}
+};
+A2 test2() {
+  A2 a;
+  return a; // expected-error {{calling a private constructor of class 'test_delete_function::A2'}}
+}
+
+struct C {};
+
+struct B1 {
+  B1(C &);
+  B1(C &&) = delete; // expected-note {{'B1' has been explicitly marked deleted here}}
+};
+B1 test3() {
+  C c;
+  return c; // expected-error {{conversion function from 'test_delete_function::C' to 'test_delete_function::B1' invokes a deleted function}}
+}
+
+struct B2 {
+  B2(C &);
+
+private:
+  B2(C &&); // expected-note {{declared private here}}
+};
+B2 test4() {
+  C c;
+  return c; // expected-error {{calling a private constructor of class 'test_delete_function::B2'}}
+}
+} // namespace test_delete_function
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3106,11 +3106,14 @@
 /// If move-initialization is not possible, such that we must fall back to
 /// treating the operand as an lvalue, we will leave Res in its original
 /// invalid state.
-static void TryMoveInitialization(Sema& S,
-  const InitializedEntity ,
+///
+/// \returns Whether we need to do the second overload resolution. If the first
+/// overload resolution fails, or if the first overload resolution succeeds but
+/// the selected constructor/operator doesn't match the additional criteria, we
+/// need to do the second overload resolution.
+static bool TryMoveInitialization(Sema , const InitializedEntity ,
   const VarDecl *NRVOCandidate,
-  QualType ResultType,
-  Expr *,
+  QualType ResultType, Expr *,
   bool ConvertingConstructorsOnly,
   ExprResult ) {
   ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(),
@@ -3123,8 +3126,10 @@
 
   InitializationSequence Seq(S, Entity, Kind, InitExpr);
 
-  if (!Seq)
-return;
+  bool NeedSecondOverloadResolution = true;
+  if (!Seq && Seq.getFailedOverloadResult() != OR_Deleted) {
+return NeedSecondOverloadResolution;
+  }
 
   for (const InitializationSequence::Step  : Seq.steps()) {
 if (Step.Kind != InitializationSequence::SK_ConstructorInitialization &&
@@ -3167,6 +3172,7 @@
   }
 }
 
+NeedSecondOverloadResolution = false;
 // Promote "AsRvalue" to the heap, since we now need this
 // expression node to persist.
 Value =
@@ -3177,6 +3183,8 @@
 // using the constructor we found.
 Res = Seq.Perform(S, Entity, Kind, Value);
   }
+
+  return NeedSecondOverloadResolution;
 }
 
 /// Perform the initialization of a potentially-movable value, which
@@ -3201,6 +3209,7 @@
   // select the constructor for the copy is first performed as if the object
   // were designated by an rvalue.
   ExprResult Res = ExprError();
+  bool NeedSecondOverloadResolution = true;
 
   if (AllowNRVO) {
 bool AffectedByCWG1579 = false;
@@ -3217,11 +3226,11 @@
 }
 
 if (NRVOCandidate) {
-  TryMoveInitialization(*this, Entity, NRVOCandidate, ResultType, Value,
-true, Res);
+  NeedSecondOverloadResolution = TryMoveInitialization(
+  *this, Entity, NRVOCandidate, ResultType, Value, true, Res);
 }
 
-if (!Res.isInvalid() && AffectedByCWG1579) {
+if (!NeedSecondOverloadResolution && AffectedByCWG1579) {
   QualType QT = NRVOCandidate->getType();
   if (QT.getNonReferenceType()
  .getUnqualifiedType()
@@ -3244,7 +3253,7 @@
 Diag(Value->getExprLoc(), 

[PATCH] D92936: [Sema] Fix deleted function problem in implicitly movable test

2020-12-09 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
nullptr.cpp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92936

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=cxx20 %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=cxx11_14_17 %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=cxx11_14_17 %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=cxx11_14_17 %s
+
+namespace test_delete_function {
+struct A1 {
+  A1();
+  A1(const A1&);
+  A1(A1&&) = delete;
+  // cxx11_14_17-note@-1 {{'A1' has been explicitly marked deleted here}}
+  // cxx20-note@-2 {{'A1' has been explicitly marked deleted here}}
+};
+A1 test1() {
+  A1 a;
+  return a;
+  // cxx11_14_17-error@-1 {{call to deleted constructor of 'test_delete_function::A1'}}
+  // cxx20-error@-2 {{call to deleted constructor of 'test_delete_function::A1'}}
+}
+
+struct A2 {
+  A2();
+  A2(const A2&);
+private:
+  A2(A2&&);
+  // cxx11_14_17-note@-1 {{declared private here}}
+  // cxx20-note@-2 {{declared private here}}
+};
+A2 test2() {
+  A2 a;
+  return a;
+  // cxx11_14_17-error@-1 {{calling a private constructor of class 'test_delete_function::A2'}}
+  // cxx20-error@-2 {{calling a private constructor of class 'test_delete_function::A2'}}
+}
+
+
+struct C {};
+
+struct B1 {
+  B1(C&);
+  B1(C&&) = delete;
+  // cxx11_14_17-note@-1 {{'B1' has been explicitly marked deleted here}}
+  // cxx20-note@-2 {{'B1' has been explicitly marked deleted here}}
+};
+B1 test3() {
+  C c;
+  return c;
+  // cxx11_14_17-error@-1 {{conversion function from 'test_delete_function::C' to 'test_delete_function::B1' invokes a deleted function}}
+  // cxx20-error@-2 {{conversion function from 'test_delete_function::C' to 'test_delete_function::B1' invokes a deleted function}}
+}
+
+struct B2 {
+  B2(C&);
+private:
+  B2(C&&);
+  // cxx11_14_17-note@-1 {{declared private here}}
+  // cxx20-note@-2 {{declared private here}}
+};
+B2 test4() {
+  C c;
+  return c;
+  // cxx11_14_17-error@-1 {{calling a private constructor of class 'test_delete_function::B2'}}
+  // cxx20-error@-2 {{calling a private constructor of class 'test_delete_function::B2'}}
+}
+} // namespace test_delete_function
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3106,11 +3106,14 @@
 /// If move-initialization is not possible, such that we must fall back to
 /// treating the operand as an lvalue, we will leave Res in its original
 /// invalid state.
-static void TryMoveInitialization(Sema& S,
-  const InitializedEntity ,
+///
+/// \returns Whether need to do the second overload resolution. If the first
+/// overload resolution fails, or if the first overload resolution success but
+/// the selected constructor/operator doesn't match the additional criteria, we
+/// need to do the second overload resolution.
+static bool TryMoveInitialization(Sema , const InitializedEntity ,
   const VarDecl *NRVOCandidate,
-  QualType ResultType,
-  Expr *,
+  QualType ResultType, Expr *,
   bool ConvertingConstructorsOnly,
   ExprResult ) {
   ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(),
@@ -3123,8 +3126,10 @@
 
   InitializationSequence Seq(S, Entity, Kind, InitExpr);
 
-  if (!Seq)
-return;
+  bool NeedSecondOverload = true;
+  if (!Seq && Seq.getFailedOverloadResult() != OR_Deleted) {
+return NeedSecondOverload;
+  }
 
   for (const InitializationSequence::Step  : Seq.steps()) {
 if (Step.Kind != InitializationSequence::SK_ConstructorInitialization &&
@@ -3167,6 +3172,7 @@
   }
 }
 
+NeedSecondOverload = false;
 // Promote "AsRvalue" to the heap, since we now need this
 // expression node to persist.
 Value =
@@ -3177,6 +3183,8 @@
 // using the constructor we found.
 Res = Seq.Perform(S, Entity, Kind, Value);
   }
+
+  return NeedSecondOverload;
 }
 
 /// Perform the initialization of a potentially-movable value, which
@@ -3201,6 +3209,7 @@
   // select the constructor for the copy is first performed as if the object
   // were designated by an rvalue.
   ExprResult Res = ExprError();
+  bool NeedSecondOverload = true;
 
   if (AllowNRVO) {
 bool AffectedByCWG1579 = 

[PATCH] D88220: [C++20] P1825R0: More implicit moves

2020-12-07 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:4626
 CES_AllowExceptionVariables = 4,
-CES_FormerDefault = (CES_AllowParameters),
-CES_Default = (CES_AllowParameters | CES_AllowDifferentTypes),
-CES_AsIfByStdMove = (CES_AllowParameters | CES_AllowDifferentTypes |
- CES_AllowExceptionVariables),
+CES_AllowRValueReferenceType = 8,
+CES_ImplicitlyMovableCXX11CXX14CXX17 =

Quuxplusone wrote:
> I believe `RValue` should be spelled `Rvalue`, throughout.
There are already names such as `RValueReferenceType`, so be consistent with 
existing code.



Comment at: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp:28
+private:
+  C(C &&); // cxx20-note {{declared private here}}
+};

[over.match.funcs]p8:
> A defaulted move special member function that is defined as deleted is 
> excluded from the set of candidate functions in all contexts.

So in this case still use private.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

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


[PATCH] D88220: [C++20] P1825R0: More implicit moves

2020-12-07 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 309873.
nullptr.cpp added a comment.
Herald added a subscriber: lxfind.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1203,6 +1203,11 @@
   https://wg21.link/p0593r6;>P0593R6 (DR)
   Clang 11
 
+
+More implicit moves
+https://wg21.link/p1825r0;>P1825R0 (DR)
+Clang 12
+
 
 
 
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,5 +1,11 @@
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++20 -verify=cxx20 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -verify=cxx11_14_17 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -verify=cxx11_14_17 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -verify=cxx11_14_17 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CXX11_14_17-CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CXX11_14_17-CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CXX11_14_17-CHECK
+// cxx20-no-diagnostics
 
 // definitions for std::move
 namespace std {
@@ -71,37 +77,34 @@
 Base test2() {
 Derived d2;
 return d2;  // e1
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
+// cxx11_14_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_14_17-note@-2{{to avoid copying}}
+// CXX11_14_17-CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
 }
 ConstructFromDerived test3() {
 Derived d3;
-return d3;  // e2-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d3)"
+return d3;  // ok
 }
 ConstructFromBase test4() {
 Derived d4;
 return d4;  // e3
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d4)"
+// cxx11_14_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_14_17-note@-2{{to avoid copying}}
+// CXX11_14_17-CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d4)"
 }
 ConvertFromDerived test5() {
 Derived d5;
 return d5;  // e4
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d5)"
+// cxx11_14_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_14_17-note@-2{{to avoid copying}}
+// CXX11_14_17-CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d5)"
 }
 ConvertFromBase test6() {
 Derived d6;
 return d6;  // e5
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d6)"
+// cxx11_14_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_14_17-note@-2{{to avoid copying}}
+// CXX11_14_17-CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d6)"
 }
 
 // These test cases should not produce the warning.
@@ -148,93 +151,89 @@
 Derived testParam1(Derived d) { return d; }
 Base testParam2(Derived d) {
 return d;  // e6
-// 

[PATCH] D88220: [C++20] P1825R0: More implicit moves

2020-11-22 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

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


[PATCH] D88220: [C++20] P1825R0: More implicit moves

2020-11-11 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 304447.
nullptr.cpp added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1202,6 +1202,11 @@
   https://wg21.link/p0593r6;>P0593R6 (DR)
   Clang 11
 
+
+More implicit moves
+https://wg21.link/p1825r0;>P1825R0 (DR)
+Clang 12
+
 
 
 
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 // definitions for std::move
 namespace std {
@@ -77,10 +77,7 @@
 }
 ConstructFromDerived test3() {
 Derived d3;
-return d3;  // e2-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d3)"
+return d3;  // ok
 }
 ConstructFromBase test4() {
 Derived d4;
@@ -153,10 +150,7 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
 }
 ConstructFromDerived testParam3(Derived d) {
-return d;  // e7-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
+return d;  // ok
 }
 ConstructFromBase testParam4(Derived d) {
 return d;  // e8
@@ -231,10 +225,7 @@
 }
 ConstructFromDerived testParens2() {
 Derived d;
-return (d);  // e18-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)"
+return (d);  // ok
 }
 
 
Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -0,0 +1,144 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify %s
+
+// In C++20, implicitly movable entity can be rvalue reference to non-volatile
+// automatic object.
+namespace test_implicitly_movable_rvalue_ref {
+#if __cplusplus >= 202002L
+class C {
+public:
+  C() {}
+  ~C() {}
+  C(C &&);
+
+private:
+  C(const C &);
+};
+
+C test(C &) {
+  return c;
+}
+#else
+class C {
+public:
+  C() {}
+  ~C() {}
+  C(C &&);
+
+private:
+  C(const C &); // expected-note {{declared private here}}
+};
+
+C test(C &) {
+  return c; // expected-error {{calling a private constructor of class 'test_implicitly_movable_rvalue_ref::C'}}
+}
+#endif
+} // namespace test_implicitly_movable_rvalue_ref
+
+// In C++20, operand of throw-expression can be function parameter or
+// catch-clause parameter.
+namespace test_throw_parameter {
+#if __cplusplus >= 202002L
+class C {
+public:
+  C() {}
+  ~C() {}
+  C(const C &);
+
+private:
+  C(C &&); // expected-note {{declared private here}}
+};
+
+void func();
+void test() {
+  try {
+func();
+  } catch (C c_move) {
+throw c_move; // expected-error {{calling a private constructor of class 'test_throw_parameter::C'}}
+  }
+}
+#else
+class C {
+public:
+  C() {}
+  ~C() {}
+  C(const C &);
+
+private:
+  C(C &&);
+};
+
+void func();
+void test() {
+  try {
+func();
+  } catch (C c_copy) {
+throw c_copy;
+  }
+}
+#endif
+} // namespace test_throw_parameter
+
+// In C++20, during the first overload resolution, the first parameter of the
+// selected constructor no need to be rvalue reference to the object's type.
+namespace test_ctor_param_rvalue_ref {

[PATCH] D88295: [Sema] Fix volatile check when test if a return object can be implicitly move

2020-11-10 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

Thanks for all your suggestions!
But I don't have commit access, can anyone help me commit this with "Yang Fan 
" ?
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88295

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


[PATCH] D88220: [C++20] Implement more implicit moves for return statements(Part of P1825R0)

2020-11-03 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 302544.
nullptr.cpp added a comment.

Implement whole P1825R0


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1202,6 +1202,11 @@
   https://wg21.link/p0593r6;>P0593R6 (DR)
   Clang 11
 
+
+More implicit moves
+https://wg21.link/p1825r0;>P1825R0 (DR)
+Clang 12
+
 
 
 
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 // definitions for std::move
 namespace std {
@@ -77,10 +77,7 @@
 }
 ConstructFromDerived test3() {
 Derived d3;
-return d3;  // e2-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d3)"
+return d3;  // ok
 }
 ConstructFromBase test4() {
 Derived d4;
@@ -153,10 +150,7 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
 }
 ConstructFromDerived testParam3(Derived d) {
-return d;  // e7-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
+return d;  // ok
 }
 ConstructFromBase testParam4(Derived d) {
 return d;  // e8
@@ -231,10 +225,7 @@
 }
 ConstructFromDerived testParens2() {
 Derived d;
-return (d);  // e18-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)"
+return (d);  // ok
 }
 
 
Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -0,0 +1,144 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify %s
+
+// In C++20, implicitly movable entity can be rvalue reference to non-volatile
+// automatic object.
+namespace test_implicitly_movable_rvalue_ref {
+#if __cplusplus >= 202002L
+class C {
+public:
+  C() {}
+  ~C() {}
+  C(C &&);
+
+private:
+  C(const C &);
+};
+
+C test(C &) {
+  return c;
+}
+#else
+class C {
+public:
+  C() {}
+  ~C() {}
+  C(C &&);
+
+private:
+  C(const C &); // expected-note {{declared private here}}
+};
+
+C test(C &) {
+  return c; // expected-error {{calling a private constructor of class 'test_implicitly_movable_rvalue_ref::C'}}
+}
+#endif
+} // namespace test_implicitly_movable_rvalue_ref
+
+// In C++20, operand of throw-expression can be function parameter or
+// catch-clause parameter.
+namespace test_throw_parameter {
+#if __cplusplus >= 202002L
+class C {
+public:
+  C() {}
+  ~C() {}
+  C(const C &);
+
+private:
+  C(C &&); // expected-note {{declared private here}}
+};
+
+void func();
+void test() {
+  try {
+func();
+  } catch (C c_move) {
+throw c_move; // expected-error {{calling a private constructor of class 'test_throw_parameter::C'}}
+  }
+}
+#else
+class C {
+public:
+  C() {}
+  ~C() {}
+  C(const C &);
+
+private:
+  C(C &&);
+};
+
+void func();
+void test() {
+  try {
+func();
+  } catch (C c_copy) {
+throw c_copy;
+  }
+}
+#endif
+} // namespace test_throw_parameter
+
+// In C++20, during the first overload resolution, the first parameter of the
+// selected constructor no need to be rvalue reference to the object's type.
+namespace 

[PATCH] D88295: [Sema] Fix volatile check when test if a return object can be implicitly move

2020-10-31 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 302073.
nullptr.cpp added a comment.

move test to `class/class.init/class.copy.elision/p1.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88295

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p1.cpp


Index: clang/test/CXX/class/class.init/class.copy.elision/p1.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p1.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++20 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -std=c++14 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
%s | FileCheck %s
+
+// - volatile object in return statement don't match the rule for using move
+//   operation instead of copy operation. Thus should call the copy constructor
+//   A(const volatile A &).
+//
+// - volatile object in return statement also don't match the rule for copy
+//   elision. Thus the copy constructor A(const volatile A &) cannot be elided.
+namespace test_volatile {
+class A {
+public:
+  A() {}
+  ~A() {}
+  A(const volatile A &);
+  A(volatile A &&);
+};
+
+A test() {
+  volatile A a_copy;
+  // CHECK: call void @_ZN13test_volatile1AC1ERVKS0_
+  return a_copy;
+}
+} // namespace test_volatile
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3059,12 +3059,13 @@
   // variable will no longer be used.
   if (VD->hasAttr()) return false;
 
+  // ...non-volatile...
+  if (VD->getType().isVolatileQualified())
+return false;
+
   if (CESK & CES_AllowDifferentTypes)
 return true;
 
-  // ...non-volatile...
-  if (VD->getType().isVolatileQualified()) return false;
-
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
   if (!VD->getType()->isDependentType() && VD->hasAttr() &&


Index: clang/test/CXX/class/class.init/class.copy.elision/p1.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.init/class.copy.elision/p1.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++20 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++14 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+
+// - volatile object in return statement don't match the rule for using move
+//   operation instead of copy operation. Thus should call the copy constructor
+//   A(const volatile A &).
+//
+// - volatile object in return statement also don't match the rule for copy
+//   elision. Thus the copy constructor A(const volatile A &) cannot be elided.
+namespace test_volatile {
+class A {
+public:
+  A() {}
+  ~A() {}
+  A(const volatile A &);
+  A(volatile A &&);
+};
+
+A test() {
+  volatile A a_copy;
+  // CHECK: call void @_ZN13test_volatile1AC1ERVKS0_
+  return a_copy;
+}
+} // namespace test_volatile
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3059,12 +3059,13 @@
   // variable will no longer be used.
   if (VD->hasAttr()) return false;
 
+  // ...non-volatile...
+  if (VD->getType().isVolatileQualified())
+return false;
+
   if (CESK & CES_AllowDifferentTypes)
 return true;
 
-  // ...non-volatile...
-  if (VD->getType().isVolatileQualified()) return false;
-
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
   if (!VD->getType()->isDependentType() && VD->hasAttr() &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88295: [Sema] Fix volatile check when test if a return object can be implicitly move

2020-10-30 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 301822.
nullptr.cpp added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88295

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/special/class.copy/copy-elision.cpp


Index: clang/test/CXX/special/class.copy/copy-elision.cpp
===
--- /dev/null
+++ clang/test/CXX/special/class.copy/copy-elision.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++20 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -std=c++14 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
%s | FileCheck %s
+
+// - volatile object in return statement don't match the rule for using move
+//   operation instead of copy operation. Thus should call the copy constructor
+//   A(const volatile A &).
+//
+// - volatile object in return statement also don't match the rule for copy
+//   elision. Thus the copy constructor A(const volatile A &) cannot be elided.
+namespace test_volatile {
+class A {
+public:
+  A() {}
+  ~A() {}
+  A(const volatile A &);
+  A(volatile A &&);
+};
+
+A test() {
+  volatile A a_copy;
+  // CHECK: call void @_ZN13test_volatile1AC1ERVKS0_
+  return a_copy;
+}
+} // namespace test_volatile
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3059,12 +3059,13 @@
   // variable will no longer be used.
   if (VD->hasAttr()) return false;
 
+  // ...non-volatile...
+  if (VD->getType().isVolatileQualified())
+return false;
+
   if (CESK & CES_AllowDifferentTypes)
 return true;
 
-  // ...non-volatile...
-  if (VD->getType().isVolatileQualified()) return false;
-
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
   if (!VD->getType()->isDependentType() && VD->hasAttr() &&


Index: clang/test/CXX/special/class.copy/copy-elision.cpp
===
--- /dev/null
+++ clang/test/CXX/special/class.copy/copy-elision.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++20 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++14 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+
+// - volatile object in return statement don't match the rule for using move
+//   operation instead of copy operation. Thus should call the copy constructor
+//   A(const volatile A &).
+//
+// - volatile object in return statement also don't match the rule for copy
+//   elision. Thus the copy constructor A(const volatile A &) cannot be elided.
+namespace test_volatile {
+class A {
+public:
+  A() {}
+  ~A() {}
+  A(const volatile A &);
+  A(volatile A &&);
+};
+
+A test() {
+  volatile A a_copy;
+  // CHECK: call void @_ZN13test_volatile1AC1ERVKS0_
+  return a_copy;
+}
+} // namespace test_volatile
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3059,12 +3059,13 @@
   // variable will no longer be used.
   if (VD->hasAttr()) return false;
 
+  // ...non-volatile...
+  if (VD->getType().isVolatileQualified())
+return false;
+
   if (CESK & CES_AllowDifferentTypes)
 return true;
 
-  // ...non-volatile...
-  if (VD->getType().isVolatileQualified()) return false;
-
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
   if (!VD->getType()->isDependentType() && VD->hasAttr() &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88295: [Sema] Fix volatile check when test if a return object can be implicitly move

2020-10-29 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

In D88295#2358845 , @aaronpuchert 
wrote:

> Could you perhaps integrate this into the existing test 
> `clang/test/CXX/special/class.copy/implicit-move.cpp` instead? 
> Whenever you have something that closely corresponds to the standard, CXX is 
> probably the right place for a test.

`clang/test/CXX/special/class.copy/implicit-move.cpp` and 
`clang/test/CXX/special/class.copy/implicit-move-def.cpp` are tests for 
implicit (non-)declaration of move constructor and assignment, they have 
nothing to do with this patch.
Because `copy/move elision` is defined in section [class.copy.elision] in 
standard, so I put the test in 
`clang/test/CXX/special/class.copy/copy-elision.cpp`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88295

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


[PATCH] D88295: [Sema] Fix volatile check when test if a return object can be implicitly move

2020-10-29 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 301810.
nullptr.cpp added a comment.

make test more clearly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88295

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/special/class.copy/copy-elision.cpp


Index: clang/test/CXX/special/class.copy/copy-elision.cpp
===
--- /dev/null
+++ clang/test/CXX/special/class.copy/copy-elision.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++20 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -std=c++14 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm -triple x86_64-unknown-linux-gnu -o - 
%s | FileCheck %s
+
+// - volatile object in return statement don't match the rule for using move
+//   operation instead of copy operation. Thus should call the copy constructor
+//   A(const volatile A &).
+//
+// - volatile object in return statement also don't match the rule for copy
+//   elision. Thus the copy constructor A(const volatile A &) cannot be elided.
+namespace test_volatile {
+class A {
+public:
+  A() {}
+  ~A() {}
+  A(const volatile A &);
+  A(volatile A &&);
+};
+
+A test() {
+  volatile A a_copy;
+  // CHECK: call void @_ZN13test_volatile1AC1ERVKS0_
+  return a_copy;
+}
+} // namespace test_volatile
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3059,12 +3059,13 @@
   // variable will no longer be used.
   if (VD->hasAttr()) return false;
 
+  // ...non-volatile...
+  if (VD->getType().isVolatileQualified())
+return false;
+
   if (CESK & CES_AllowDifferentTypes)
 return true;
 
-  // ...non-volatile...
-  if (VD->getType().isVolatileQualified()) return false;
-
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
   if (!VD->getType()->isDependentType() && VD->hasAttr() &&


Index: clang/test/CXX/special/class.copy/copy-elision.cpp
===
--- /dev/null
+++ clang/test/CXX/special/class.copy/copy-elision.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++20 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++14 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+
+// - volatile object in return statement don't match the rule for using move
+//   operation instead of copy operation. Thus should call the copy constructor
+//   A(const volatile A &).
+//
+// - volatile object in return statement also don't match the rule for copy
+//   elision. Thus the copy constructor A(const volatile A &) cannot be elided.
+namespace test_volatile {
+class A {
+public:
+  A() {}
+  ~A() {}
+  A(const volatile A &);
+  A(volatile A &&);
+};
+
+A test() {
+  volatile A a_copy;
+  // CHECK: call void @_ZN13test_volatile1AC1ERVKS0_
+  return a_copy;
+}
+} // namespace test_volatile
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3059,12 +3059,13 @@
   // variable will no longer be used.
   if (VD->hasAttr()) return false;
 
+  // ...non-volatile...
+  if (VD->getType().isVolatileQualified())
+return false;
+
   if (CESK & CES_AllowDifferentTypes)
 return true;
 
-  // ...non-volatile...
-  if (VD->getType().isVolatileQualified()) return false;
-
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
   if (!VD->getType()->isDependentType() && VD->hasAttr() &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88295: [Sema] Fix volatile check when test if a return object can be implicitly move

2020-10-28 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

Ping
I don't have commit access, can anyone help me commit this with "Yang Fan 
" ?
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88295

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


[PATCH] D88295: [Sema] Fix volatile check when test if a return object can be implicitly move

2020-10-15 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

Ping!
I don't have commit access, can anyone help me commit this with "Yang Fan 
" ?
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88295

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


[PATCH] D88295: [Sema] Fix volatile check when test if a return object can be implicitly move

2020-09-26 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

- C++11:

> [class.copy]p32:
> When **the criteria for elision of a copy operation **are met or would be met 
> save for the fact that the source object is a function parameter, and the 
> object to be copied is designated by an lvalue, overload resolution to select 
> the constructor for the copy is first performed as if the object were 
> designated by an rvalue.

//Thus should use rules at://

> [class.copy]p31:
> — in a return statement in a function with a class return type, when the 
> expression is the name of a **non-volatile automatic object **...

**Volatile automatic objects** cannot pass this check.

- CWG1579:

> When **the criteria for elision of a copy operation** are met and the object 
> to be copied is designated by an lvalue, **or when **the expression in a 
> return statement is a (possibly parenthesized) id-expression that names **an 
> object with automatic storage duration **declared in the body or 
> parameter-declaration-clause of the innermost enclosing function or 
> lambda-expression, overload resolution

When the expression is the name of a **volatile automatic object**, the first 
condition will fail because the criteria for elision of a copy operation 
require a **non-volatile automatic object **.
So take the  ''**or when ...**'' branch, **volatile automatic objects** can 
pass this check.

- C++14 is same as CWG1579.

- C++17:

> [class. copy. elision]p(3.1):
> — If the expression in a return statement is a (possibly parenthesized) 
> id-expression that names **an object with automatic storage duration** ...

**Volatile automatic objects** can also pass this check.

- C++20:

> [class. copy. elision]p3:
> An implicitly movable entity is a variable of automatic storage duration that 
> is either **a non-volatile object** or an rvalue reference to a non-volatile 
> object type.
> — If the expression in a return or co_return statement is a (possibly 
> parenthesized) id-expression that names an **implicitly movable entity** ...

**Volatile automatic objects** cannot pass this check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88295

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


[PATCH] D88295: [Sema] Fix volatile check when test if a return object can be implicitly move

2020-09-26 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 294485.
nullptr.cpp added a comment.

Add test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88295

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaCXX/implicitly-movable.cpp


Index: clang/test/SemaCXX/implicitly-movable.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/implicitly-movable.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify %s
+// expected-no-diagnostics
+
+class A {
+public:
+  A() {}
+  ~A() {}
+  A(A &&);
+  A(const volatile A &);
+
+private:
+  A(const A &);
+  A(volatile A &&);
+};
+
+A test_volatile() {
+  volatile A a_copy;
+  return a_copy;
+}
+
+A test_normal() {
+  A a_move;
+  return a_move;
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3056,12 +3056,13 @@
   // variable will no longer be used.
   if (VD->hasAttr()) return false;
 
+  // ...non-volatile...
+  if (VD->getType().isVolatileQualified())
+return false;
+
   if (CESK & CES_AllowDifferentTypes)
 return true;
 
-  // ...non-volatile...
-  if (VD->getType().isVolatileQualified()) return false;
-
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
   if (!VD->getType()->isDependentType() && VD->hasAttr() &&


Index: clang/test/SemaCXX/implicitly-movable.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/implicitly-movable.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify %s
+// expected-no-diagnostics
+
+class A {
+public:
+  A() {}
+  ~A() {}
+  A(A &&);
+  A(const volatile A &);
+
+private:
+  A(const A &);
+  A(volatile A &&);
+};
+
+A test_volatile() {
+  volatile A a_copy;
+  return a_copy;
+}
+
+A test_normal() {
+  A a_move;
+  return a_move;
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3056,12 +3056,13 @@
   // variable will no longer be used.
   if (VD->hasAttr()) return false;
 
+  // ...non-volatile...
+  if (VD->getType().isVolatileQualified())
+return false;
+
   if (CESK & CES_AllowDifferentTypes)
 return true;
 
-  // ...non-volatile...
-  if (VD->getType().isVolatileQualified()) return false;
-
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
   if (!VD->getType()->isDependentType() && VD->hasAttr() &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88295: [Sema] Fix volatile check when test if a return object can be implicitly move

2020-09-25 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
nullptr.cpp added reviewers: Quuxplusone, rsmith, erik.pilkington.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.
nullptr.cpp requested review of this revision.

In C++11 standard, to become implicitly movable, the expression in return
statement should be a non-volatile automatic object. CWG1579 changed the rule
to require that the expression only needs to be a automatic object. C++14
standard and C++17 standard kept this rule unchanged. C++20 standard changed
the rule back to require the expression be a non-volatile automatic object.
This should be a typo in standards, and `VD` should be non-volatile.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88295

Files:
  clang/lib/Sema/SemaStmt.cpp


Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3056,12 +3056,13 @@
   // variable will no longer be used.
   if (VD->hasAttr()) return false;
 
+  // ...non-volatile...
+  if (VD->getType().isVolatileQualified())
+return false;
+
   if (CESK & CES_AllowDifferentTypes)
 return true;
 
-  // ...non-volatile...
-  if (VD->getType().isVolatileQualified()) return false;
-
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
   if (!VD->getType()->isDependentType() && VD->hasAttr() &&


Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3056,12 +3056,13 @@
   // variable will no longer be used.
   if (VD->hasAttr()) return false;
 
+  // ...non-volatile...
+  if (VD->getType().isVolatileQualified())
+return false;
+
   if (CESK & CES_AllowDifferentTypes)
 return true;
 
-  // ...non-volatile...
-  if (VD->getType().isVolatileQualified()) return false;
-
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
   if (!VD->getType()->isDependentType() && VD->hasAttr() &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88220: [C++20] Implement more implicit moves for return statements(Part of P1825R0)

2020-09-24 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
nullptr.cpp requested review of this revision.

In P1825R0, the first parameter of overload resolution selected function does
not need to be an rvalue reference to the returned object's type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88220

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaCXX/implicit-move.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1201,6 +1201,11 @@
   https://wg21.link/p0593r6;>P0593R6 (DR)
   Clang 11
 
+
+More implicit moves
+https://wg21.link/p1825r0;>P1825R0 (DR)
+Clang 12 (partial)
+
 
 
 
Index: clang/test/SemaCXX/implicit-move.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/implicit-move.cpp
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -DCXX20 -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -DCXX17 -verify %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -DCXX14 -verify %s
+
+class Error;
+
+class NeedRvalueRef {
+public:
+  NeedRvalueRef() {}
+  ~NeedRvalueRef() {}
+  NeedRvalueRef(const NeedRvalueRef &);
+  NeedRvalueRef(NeedRvalueRef &&);
+  NeedRvalueRef(Error &&);
+};
+
+class NoNeedRvalueRef {
+public:
+  NoNeedRvalueRef() {}
+  ~NoNeedRvalueRef() {}
+  NoNeedRvalueRef(const NoNeedRvalueRef &);
+  NoNeedRvalueRef(NoNeedRvalueRef &&);
+  NoNeedRvalueRef(Error);
+};
+
+#ifdef CXX20
+// expected-no-diagnostics
+class Error {
+public:
+  Error() {}
+  ~Error() {}
+  Error(Error &&);
+
+private:
+  Error(const Error &);
+};
+
+NoNeedRvalueRef test() {
+  Error Err;
+  return Err;
+}
+#endif
+
+#ifdef CXX17
+class Error {
+public:
+  Error() {}
+  ~Error() {}
+  Error(Error &&);
+
+private:
+  Error(const Error &); // expected-note {{declared private here}}
+};
+
+NoNeedRvalueRef test2() {
+  Error Err;
+  return Err; // expected-error {{calling a private constructor of class 'Error'}}
+}
+#endif
+
+#ifdef CXX14
+class Error {
+public:
+  Error() {}
+  ~Error() {}
+  Error(Error &&);
+
+private:
+  Error(const Error &); // expected-note {{declared private here}}
+};
+
+NoNeedRvalueRef test2() {
+  Error Err;
+  return Err; // expected-error {{calling a private constructor of class 'Error'}}
+}
+#endif
+
+NeedRvalueRef test_all_ok() {
+  Error Err;
+  return Err;
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3056,12 +3056,20 @@
   // variable will no longer be used.
   if (VD->hasAttr()) return false;
 
+  // ...non-volatile...
+  if (VD->getType().isVolatileQualified())
+return false;
+
+  // C++20 [class.copy.elision]p3:
+  // ...rvalue reference to a non-volatile...
+  if (VD->getType()->isRValueReferenceType() &&
+  (!(CESK & CES_AllowRValueReferenceType) ||
+   VD->getType().getNonReferenceType().isVolatileQualified()))
+return false;
+
   if (CESK & CES_AllowDifferentTypes)
 return true;
 
-  // ...non-volatile...
-  if (VD->getType().isVolatileQualified()) return false;
-
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
   if (!VD->getType()->isDependentType() && VD->hasAttr() &&
@@ -3074,13 +3082,13 @@
 /// Try to perform the initialization of a potentially-movable value,
 /// which is the operand to a return or throw statement.
 ///
-/// This routine implements C++14 [class.copy]p32, which attempts to treat
-/// returned lvalues as rvalues in certain cases (to prefer move construction),
-/// then falls back to treating them as lvalues if that failed.
+/// This routine implements C++20 [class.copy.elision]p3:, which attempts to
+/// treat returned lvalues as rvalues in certain cases (to prefer move
+/// construction), then falls back to treating them as lvalues if that failed.
 ///
-/// \param ConvertingConstructorsOnly If true, follow [class.copy]p32 and reject
-/// resolutions that find non-constructors, such as derived-to-base conversions
-/// or `operator T()&&` member functions. If false, do consider such
+/// \param ConvertingConstructorsOnly If true, follow [class.copy.elision]p3 and
+/// reject resolutions that find non-constructors, such as derived-to-base
+/// conversions or `operator T()&&` member functions. If false, do consider such
 /// conversion sequences.
 ///
 /// \param Res We will fill this in if move-initialization was possible.
@@ -3114,10 +3122,14 @@
 
 FunctionDecl *FD = Step.Function.Function;
 if (ConvertingConstructorsOnly) {
-  if (isa(FD)) {
+  if (!isa(FD)) {
+continue;
+  }
+  if 

[PATCH] D87347: [NFC] Fix compiler warnings due to integer comparison of different signedness

2020-09-10 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 290944.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87347

Files:
  clang/lib/Lex/Pragma.cpp
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/lib/MC/WasmObjectWriter.cpp
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2037,8 +2037,7 @@
 if (Mask[i] == UndefMaskElem)
   continue;
 uint64_t LSBIndex = IsBigEndian ? (i + 1) * TruncRatio - 1 : i * 
TruncRatio;
-assert(LSBIndex <= std::numeric_limits::max() &&
-   "Overflowed 32-bits");
+assert(LSBIndex <= INT32_MAX && "Overflowed 32-bits");
 if (Mask[i] != (int)LSBIndex)
   return nullptr;
   }
Index: llvm/lib/MC/WasmObjectWriter.cpp
===
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -939,9 +939,8 @@
 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
   encodeULEB128(0, W.OS); // memory index
 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
-  W.OS << char(Segment.Offset > std::numeric_limits().max()
- ? wasm::WASM_OPCODE_I64_CONST
- : wasm::WASM_OPCODE_I32_CONST);
+  W.OS << char(Segment.Offset > INT32_MAX ? wasm::WASM_OPCODE_I64_CONST
+  : wasm::WASM_OPCODE_I32_CONST);
   encodeSLEB128(Segment.Offset, W.OS); // offset
   W.OS << char(wasm::WASM_OPCODE_END);
 }
Index: llvm/lib/Analysis/VectorUtils.cpp
===
--- llvm/lib/Analysis/VectorUtils.cpp
+++ llvm/lib/Analysis/VectorUtils.cpp
@@ -416,8 +416,7 @@
   ScaledMask.clear();
   for (int MaskElt : Mask) {
 if (MaskElt >= 0) {
-  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <=
- std::numeric_limits::max() &&
+  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <= INT32_MAX &&
  "Overflowed 32-bits");
 }
 for (int SliceElt = 0; SliceElt != Scale; ++SliceElt)
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1356,7 +1356,7 @@
 while (Tok.is(tok::numeric_constant)) {
   uint64_t Value;
   if (!PP.parseSimpleIntegerLiteral(Tok, Value) || Value == 0 ||
-  Value > std::numeric_limits::max()) {
+  Value > INT_MAX) {
 PP.Diag(Tok, diag::warn_pragma_warning_expected_number);
 return;
   }


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2037,8 +2037,7 @@
 if (Mask[i] == UndefMaskElem)
   continue;
 uint64_t LSBIndex = IsBigEndian ? (i + 1) * TruncRatio - 1 : i * TruncRatio;
-assert(LSBIndex <= std::numeric_limits::max() &&
-   "Overflowed 32-bits");
+assert(LSBIndex <= INT32_MAX && "Overflowed 32-bits");
 if (Mask[i] != (int)LSBIndex)
   return nullptr;
   }
Index: llvm/lib/MC/WasmObjectWriter.cpp
===
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -939,9 +939,8 @@
 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
   encodeULEB128(0, W.OS); // memory index
 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
-  W.OS << char(Segment.Offset > std::numeric_limits().max()
- ? wasm::WASM_OPCODE_I64_CONST
- : wasm::WASM_OPCODE_I32_CONST);
+  W.OS << char(Segment.Offset > INT32_MAX ? wasm::WASM_OPCODE_I64_CONST
+  : wasm::WASM_OPCODE_I32_CONST);
   encodeSLEB128(Segment.Offset, W.OS); // offset
   W.OS << char(wasm::WASM_OPCODE_END);
 }
Index: llvm/lib/Analysis/VectorUtils.cpp
===
--- llvm/lib/Analysis/VectorUtils.cpp
+++ llvm/lib/Analysis/VectorUtils.cpp
@@ -416,8 +416,7 @@
   ScaledMask.clear();
   for (int MaskElt : Mask) {
 if (MaskElt >= 0) {
-  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <=
- std::numeric_limits::max() &&
+  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <= INT32_MAX &&
  "Overflowed 32-bits");
 }
 for (int SliceElt = 0; SliceElt != Scale; ++SliceElt)
Index: clang/lib/Lex/Pragma.cpp
===
--- 

[PATCH] D87347: [NFC] Fix compiler warnings due to integer comparison of different signedness

2020-09-10 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 290886.
nullptr.cpp added a comment.

[NFC] Fix pessimizing-move warnings due to std::move in return statements

Gcc warning:

  warning: moving a local object in a return statement prevents copy elision 
[-Wpessimizing-move]
 return std::move(Err);
 ^

Fix by removing redundant `std::move` in return statements.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87347

Files:
  clang/lib/Lex/Pragma.cpp
  llvm/include/llvm/ExecutionEngine/Orc/RPC/RPCUtils.h
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/lib/MC/WasmObjectWriter.cpp
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2037,8 +2037,7 @@
 if (Mask[i] == UndefMaskElem)
   continue;
 uint64_t LSBIndex = IsBigEndian ? (i + 1) * TruncRatio - 1 : i * 
TruncRatio;
-assert(LSBIndex <= std::numeric_limits::max() &&
-   "Overflowed 32-bits");
+assert(LSBIndex <= INT32_MAX && "Overflowed 32-bits");
 if (Mask[i] != (int)LSBIndex)
   return nullptr;
   }
Index: llvm/lib/MC/WasmObjectWriter.cpp
===
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -939,9 +939,8 @@
 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
   encodeULEB128(0, W.OS); // memory index
 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
-  W.OS << char(Segment.Offset > std::numeric_limits().max()
- ? wasm::WASM_OPCODE_I64_CONST
- : wasm::WASM_OPCODE_I32_CONST);
+  W.OS << char(Segment.Offset > INT32_MAX ? wasm::WASM_OPCODE_I64_CONST
+  : wasm::WASM_OPCODE_I32_CONST);
   encodeSLEB128(Segment.Offset, W.OS); // offset
   W.OS << char(wasm::WASM_OPCODE_END);
 }
Index: llvm/lib/Analysis/VectorUtils.cpp
===
--- llvm/lib/Analysis/VectorUtils.cpp
+++ llvm/lib/Analysis/VectorUtils.cpp
@@ -416,8 +416,7 @@
   ScaledMask.clear();
   for (int MaskElt : Mask) {
 if (MaskElt >= 0) {
-  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <=
- std::numeric_limits::max() &&
+  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <= INT32_MAX &&
  "Overflowed 32-bits");
 }
 for (int SliceElt = 0; SliceElt != Scale; ++SliceElt)
Index: llvm/include/llvm/ExecutionEngine/Orc/RPC/RPCUtils.h
===
--- llvm/include/llvm/ExecutionEngine/Orc/RPC/RPCUtils.h
+++ llvm/include/llvm/ExecutionEngine/Orc/RPC/RPCUtils.h
@@ -1525,20 +1525,20 @@
 Args...)) {
   detail::ResultTraits::consumeAbandoned(
   std::move(Result));
-  return std::move(Err);
+  return Err;
 }
 
 if (auto Err = this->C.send()) {
   detail::ResultTraits::consumeAbandoned(
   std::move(Result));
-  return std::move(Err);
+  return Err;
 }
 
 while (!ReceivedResponse) {
   if (auto Err = this->handleOne()) {
 detail::ResultTraits::consumeAbandoned(
 std::move(Result));
-return std::move(Err);
+return Err;
   }
 }
 
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1356,7 +1356,7 @@
 while (Tok.is(tok::numeric_constant)) {
   uint64_t Value;
   if (!PP.parseSimpleIntegerLiteral(Tok, Value) || Value == 0 ||
-  Value > std::numeric_limits::max()) {
+  Value > INT_MAX) {
 PP.Diag(Tok, diag::warn_pragma_warning_expected_number);
 return;
   }


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2037,8 +2037,7 @@
 if (Mask[i] == UndefMaskElem)
   continue;
 uint64_t LSBIndex = IsBigEndian ? (i + 1) * TruncRatio - 1 : i * TruncRatio;
-assert(LSBIndex <= std::numeric_limits::max() &&
-   "Overflowed 32-bits");
+assert(LSBIndex <= INT32_MAX && "Overflowed 32-bits");
 if (Mask[i] != (int)LSBIndex)
   return nullptr;
   }
Index: llvm/lib/MC/WasmObjectWriter.cpp
===
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -939,9 +939,8 @@
 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
   

[PATCH] D87347: [NFC] Fix compiler warnings due to integer comparison of different signedness

2020-09-09 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

I don't have commit access, can anyone help me commit this with `"Yang Fan 
"` ?
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87347

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


[PATCH] D87347: [NFC] Fix compiler warnings due to integer comparison of different signedness

2020-09-09 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 290864.
nullptr.cpp added a comment.

Fix by directly using `INT_MAX` and `INT32_MAX`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87347

Files:
  clang/lib/Lex/Pragma.cpp
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/lib/MC/WasmObjectWriter.cpp
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2037,8 +2037,7 @@
 if (Mask[i] == UndefMaskElem)
   continue;
 uint64_t LSBIndex = IsBigEndian ? (i + 1) * TruncRatio - 1 : i * 
TruncRatio;
-assert(LSBIndex <= std::numeric_limits::max() &&
-   "Overflowed 32-bits");
+assert(LSBIndex <= INT32_MAX && "Overflowed 32-bits");
 if (Mask[i] != (int)LSBIndex)
   return nullptr;
   }
Index: llvm/lib/MC/WasmObjectWriter.cpp
===
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -939,9 +939,8 @@
 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
   encodeULEB128(0, W.OS); // memory index
 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
-  W.OS << char(Segment.Offset > std::numeric_limits().max()
- ? wasm::WASM_OPCODE_I64_CONST
- : wasm::WASM_OPCODE_I32_CONST);
+  W.OS << char(Segment.Offset > INT32_MAX ? wasm::WASM_OPCODE_I64_CONST
+  : wasm::WASM_OPCODE_I32_CONST);
   encodeSLEB128(Segment.Offset, W.OS); // offset
   W.OS << char(wasm::WASM_OPCODE_END);
 }
Index: llvm/lib/Analysis/VectorUtils.cpp
===
--- llvm/lib/Analysis/VectorUtils.cpp
+++ llvm/lib/Analysis/VectorUtils.cpp
@@ -416,8 +416,7 @@
   ScaledMask.clear();
   for (int MaskElt : Mask) {
 if (MaskElt >= 0) {
-  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <=
- std::numeric_limits::max() &&
+  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <= INT32_MAX &&
  "Overflowed 32-bits");
 }
 for (int SliceElt = 0; SliceElt != Scale; ++SliceElt)
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1356,7 +1356,7 @@
 while (Tok.is(tok::numeric_constant)) {
   uint64_t Value;
   if (!PP.parseSimpleIntegerLiteral(Tok, Value) || Value == 0 ||
-  Value > std::numeric_limits::max()) {
+  Value > INT_MAX) {
 PP.Diag(Tok, diag::warn_pragma_warning_expected_number);
 return;
   }


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2037,8 +2037,7 @@
 if (Mask[i] == UndefMaskElem)
   continue;
 uint64_t LSBIndex = IsBigEndian ? (i + 1) * TruncRatio - 1 : i * TruncRatio;
-assert(LSBIndex <= std::numeric_limits::max() &&
-   "Overflowed 32-bits");
+assert(LSBIndex <= INT32_MAX && "Overflowed 32-bits");
 if (Mask[i] != (int)LSBIndex)
   return nullptr;
   }
Index: llvm/lib/MC/WasmObjectWriter.cpp
===
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -939,9 +939,8 @@
 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
   encodeULEB128(0, W.OS); // memory index
 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
-  W.OS << char(Segment.Offset > std::numeric_limits().max()
- ? wasm::WASM_OPCODE_I64_CONST
- : wasm::WASM_OPCODE_I32_CONST);
+  W.OS << char(Segment.Offset > INT32_MAX ? wasm::WASM_OPCODE_I64_CONST
+  : wasm::WASM_OPCODE_I32_CONST);
   encodeSLEB128(Segment.Offset, W.OS); // offset
   W.OS << char(wasm::WASM_OPCODE_END);
 }
Index: llvm/lib/Analysis/VectorUtils.cpp
===
--- llvm/lib/Analysis/VectorUtils.cpp
+++ llvm/lib/Analysis/VectorUtils.cpp
@@ -416,8 +416,7 @@
   ScaledMask.clear();
   for (int MaskElt : Mask) {
 if (MaskElt >= 0) {
-  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <=
- std::numeric_limits::max() &&
+  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <= INT32_MAX &&
  "Overflowed 32-bits");
 }
 for (int SliceElt = 0; SliceElt != Scale; ++SliceElt)
Index: clang/lib/Lex/Pragma.cpp

[PATCH] D87347: [NFC] Fix compiler warnings due to integer comparison of different signedness

2020-09-09 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

I don't have commit access, can anyone help commit this and D86997 
?
Yang Fan 
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87347

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


[PATCH] D87347: [NFC] Fix compiler warnings due to integer comparison of different signedness

2020-09-09 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, sbc100.
Herald added projects: clang, LLVM.
nullptr.cpp requested review of this revision.
Herald added a subscriber: aheejin.

Fix by explicitly expressing the conversions that caused by comparison.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87347

Files:
  clang/lib/Lex/Pragma.cpp
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/lib/MC/WasmObjectWriter.cpp
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2037,7 +2037,8 @@
 if (Mask[i] == UndefMaskElem)
   continue;
 uint64_t LSBIndex = IsBigEndian ? (i + 1) * TruncRatio - 1 : i * 
TruncRatio;
-assert(LSBIndex <= std::numeric_limits::max() &&
+assert(LSBIndex <=
+   static_cast(std::numeric_limits::max()) &&
"Overflowed 32-bits");
 if (Mask[i] != (int)LSBIndex)
   return nullptr;
Index: llvm/lib/MC/WasmObjectWriter.cpp
===
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -939,9 +939,10 @@
 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
   encodeULEB128(0, W.OS); // memory index
 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
-  W.OS << char(Segment.Offset > std::numeric_limits().max()
- ? wasm::WASM_OPCODE_I64_CONST
- : wasm::WASM_OPCODE_I32_CONST);
+  W.OS << char(Segment.Offset > static_cast(
+std::numeric_limits().max())
+   ? wasm::WASM_OPCODE_I64_CONST
+   : wasm::WASM_OPCODE_I32_CONST);
   encodeSLEB128(Segment.Offset, W.OS); // offset
   W.OS << char(wasm::WASM_OPCODE_END);
 }
Index: llvm/lib/Analysis/VectorUtils.cpp
===
--- llvm/lib/Analysis/VectorUtils.cpp
+++ llvm/lib/Analysis/VectorUtils.cpp
@@ -417,7 +417,7 @@
   for (int MaskElt : Mask) {
 if (MaskElt >= 0) {
   assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <=
- std::numeric_limits::max() &&
+ static_cast(std::numeric_limits::max()) &&
  "Overflowed 32-bits");
 }
 for (int SliceElt = 0; SliceElt != Scale; ++SliceElt)
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1356,7 +1356,7 @@
 while (Tok.is(tok::numeric_constant)) {
   uint64_t Value;
   if (!PP.parseSimpleIntegerLiteral(Tok, Value) || Value == 0 ||
-  Value > std::numeric_limits::max()) {
+  Value > static_cast(std::numeric_limits::max())) {
 PP.Diag(Tok, diag::warn_pragma_warning_expected_number);
 return;
   }


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2037,7 +2037,8 @@
 if (Mask[i] == UndefMaskElem)
   continue;
 uint64_t LSBIndex = IsBigEndian ? (i + 1) * TruncRatio - 1 : i * TruncRatio;
-assert(LSBIndex <= std::numeric_limits::max() &&
+assert(LSBIndex <=
+   static_cast(std::numeric_limits::max()) &&
"Overflowed 32-bits");
 if (Mask[i] != (int)LSBIndex)
   return nullptr;
Index: llvm/lib/MC/WasmObjectWriter.cpp
===
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -939,9 +939,10 @@
 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
   encodeULEB128(0, W.OS); // memory index
 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
-  W.OS << char(Segment.Offset > std::numeric_limits().max()
- ? wasm::WASM_OPCODE_I64_CONST
- : wasm::WASM_OPCODE_I32_CONST);
+  W.OS << char(Segment.Offset > static_cast(
+std::numeric_limits().max())
+   ? wasm::WASM_OPCODE_I64_CONST
+   : wasm::WASM_OPCODE_I32_CONST);
   encodeSLEB128(Segment.Offset, W.OS); // offset
   W.OS << char(wasm::WASM_OPCODE_END);
 }
Index: llvm/lib/Analysis/VectorUtils.cpp
===
--- llvm/lib/Analysis/VectorUtils.cpp
+++ llvm/lib/Analysis/VectorUtils.cpp
@@ -417,7 +417,7 @@
   for (int MaskElt : Mask) {
 if (MaskElt >= 0) {
   assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <=

[PATCH] D86858: [OpenMP] Fix infinite loop in Sema::isOpenMPGlobalCapturedDecl()

2020-08-31 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

@jdoerfert @ABataev
I don't have commit access, can you help commit this?
Yang Fan 
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86858

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


[PATCH] D86858: [OpenMP] Fix infinite loop in Sema::isOpenMPGlobalCapturedDecl()

2020-08-31 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 289069.
nullptr.cpp added a comment.

trigger rebuild


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86858

Files:
  clang/lib/Sema/SemaOpenMP.cpp


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -2430,7 +2430,7 @@
 DSAStackTy::DSAVarData DVar = DSAStack->getImplicitDSA(D, Level);
 if (DVar.CKind != OMPC_shared)
   return true;
-  } while (Level >= 0);
+  } while (Level > 0);
 }
   }
   return true;


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -2430,7 +2430,7 @@
 DSAStackTy::DSAVarData DVar = DSAStack->getImplicitDSA(D, Level);
 if (DVar.CKind != OMPC_shared)
   return true;
-  } while (Level >= 0);
+  } while (Level > 0);
 }
   }
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86691: [analyzer] Fix wrong parameter name in printFormattedEntry

2020-08-31 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.
Herald added a subscriber: danielkiss.

In D86691#2241886 , @martong wrote:

> In D86691#2241604 , @nullptr.cpp 
> wrote:
>
>> In D86691#2241401 , @Szelethus 
>> wrote:
>>
>>> Nice, thank you! Did you stumble across this, or found it with a tool?
>>
>> I just happened to see these code:-).
>> Maybe we should write a checker to check this situation? I will start doing 
>> this!
>
> Good idea! And thanks for the fix! :)

There already have a clang-tidy checker can check this situation.
See readability-inconsistent-declaration-parameter-name 

 for more information.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86691

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


[PATCH] D86858: [OpenMP] Fix infinite loop in Sema::isOpenMPGlobalCapturedDecl()

2020-08-31 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

In D86858#2246925 , @jdoerfert wrote:

> Can you add the test that exposed this?

Sorry, this was discovered by a static analyzer checker.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86858

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


[PATCH] D86858: [OpenMP] Fix infinite loop in Sema::isOpenMPGlobalCapturedDecl()

2020-08-31 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 288894.
nullptr.cpp added a comment.

Fix by changing the loop condition to `Level > 0`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86858

Files:
  clang/lib/Sema/SemaOpenMP.cpp


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -2430,7 +2430,7 @@
 DSAStackTy::DSAVarData DVar = DSAStack->getImplicitDSA(D, Level);
 if (DVar.CKind != OMPC_shared)
   return true;
-  } while (Level >= 0);
+  } while (Level > 0);
 }
   }
   return true;


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -2430,7 +2430,7 @@
 DSAStackTy::DSAVarData DVar = DSAStack->getImplicitDSA(D, Level);
 if (DVar.CKind != OMPC_shared)
   return true;
-  } while (Level >= 0);
+  } while (Level > 0);
 }
   }
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86858: [OpenMP] Fix infinite loop in Sema::isOpenMPGlobalCapturedDecl()

2020-08-30 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
nullptr.cpp added a reviewer: ABataev.
Herald added subscribers: cfe-commits, danielkiss, guansong, yaxunl.
Herald added a project: clang.
nullptr.cpp requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Function Sema::isOpenMPGlobalCapturedDecl() has a parameter `unsigned Level`,
but use `Level >= 0` as the condition of `while`, thus cause an infinite loop.
Fix by changing the type of `Level` to `int`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86858

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -2410,7 +2410,7 @@
  Regions[CaptureLevel] != OMPD_task;
 }
 
-bool Sema::isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level,
+bool Sema::isOpenMPGlobalCapturedDecl(ValueDecl *D, int Level,
   unsigned CaptureLevel) const {
   assert(LangOpts.OpenMP && "OpenMP is not allowed");
   // Return true if the current level is no longer enclosed in a target region.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10114,7 +10114,7 @@
   /// regions.
   /// \param Level Relative level of nested OpenMP construct for that
   /// the check is performed.
-  bool isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level,
+  bool isOpenMPGlobalCapturedDecl(ValueDecl *D, int Level,
   unsigned CaptureLevel) const;
 
   ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc,


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -2410,7 +2410,7 @@
  Regions[CaptureLevel] != OMPD_task;
 }
 
-bool Sema::isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level,
+bool Sema::isOpenMPGlobalCapturedDecl(ValueDecl *D, int Level,
   unsigned CaptureLevel) const {
   assert(LangOpts.OpenMP && "OpenMP is not allowed");
   // Return true if the current level is no longer enclosed in a target region.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10114,7 +10114,7 @@
   /// regions.
   /// \param Level Relative level of nested OpenMP construct for that
   /// the check is performed.
-  bool isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level,
+  bool isOpenMPGlobalCapturedDecl(ValueDecl *D, int Level,
   unsigned CaptureLevel) const;
 
   ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86691: [analyzer] Fix wrong parameter name in printFormattedEntry

2020-08-27 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

@Szelethus @martong
Sorry to interrupt, I don't have commit access, can you help commit this and 
D86334 ?
Yang Fan 
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86691

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


[PATCH] D86691: [analyzer] Fix wrong parameter name in printFormattedEntry

2020-08-27 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

In D86691#2241401 , @Szelethus wrote:

> Nice, thank you! Did you stumble across this, or found it with a tool?

I just happened to see these code:-).
Maybe we should write a checker to check this situation? I will start doing 
this!

BTW, I don't have commit access, can you help commit this and D86334 
? Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86691

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


[PATCH] D86691: [analyzer] Fix wrong parameter name in printFormattedEntry

2020-08-27 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
nullptr.cpp added reviewers: dcoughlin, NoQ, xazax.hun, Szelethus.
Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, 
dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware.
Herald added a project: clang.
nullptr.cpp requested review of this revision.

Function `printFormattedEntry` has declaration:

  static void printFormattedEntry(
  llvm::raw_ostream ,
  std::pair EntryDescPair,
  size_t EntryWidth, size_t InitialPad, size_t MinLineWidth = 0);

But in its definition:

  void AnalyzerOptions::printFormattedEntry(
  llvm::raw_ostream ,
  std::pair EntryDescPair,
  size_t InitialPad, size_t EntryWidth, size_t MinLineWidth) {

`EntryWidth` and `InitialPad` have different position.

The definition code and all `printFormattedEntry`'s usages use the same
position as the definition, so fix the wrong parameter name in declaration.
Also fix some errors in the comments and make the comments clearer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86691

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp


Index: clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -40,7 +40,7 @@
   const size_t PadForDesc = InitialPad + EntryWidth;
 
   FOut.PadToColumn(InitialPad) << EntryDescPair.first;
-  // If the buffer's length is greater then PadForDesc, print a newline.
+  // If the buffer's length is greater than PadForDesc, print a newline.
   if (FOut.getColumn() > PadForDesc)
 FOut << '\n';
 
Index: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===
--- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -177,23 +177,23 @@
   /// description in a formatted manner. If \p MinLineWidth is set to 0, no 
line
   /// breaks are introduced for the description.
   ///
-  /// Format, depending whether the option name's length is less then
-  /// \p OptionWidth:
+  /// Format, depending whether the option name's length is less than
+  /// \p EntryWidth:
   ///
   ///   EntryNameDescription
   ///   <-padding->Description
   ///   <-padding->Description
   ///
-  ///   VeryVeryLongOptionName
+  ///   VeryVeryLongEntryName
   ///   <-padding->Description
   ///   <-padding->Description
-  ///   ^~~~ InitialPad
-  ///   ^~ EntryWidth
+  ///   ^InitialPad
+  ///^~EntryWidth
   ///   ^~MinLineWidth
-  static void printFormattedEntry(
-  llvm::raw_ostream ,
-  std::pair EntryDescPair,
-  size_t EntryWidth, size_t InitialPad, size_t MinLineWidth = 0);
+  static void printFormattedEntry(llvm::raw_ostream ,
+  std::pair 
EntryDescPair,
+  size_t InitialPad, size_t EntryWidth,
+  size_t MinLineWidth = 0);
 
   /// Pairs of checker/package name and enable/disable.
   std::vector> CheckersAndPackages;


Index: clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -40,7 +40,7 @@
   const size_t PadForDesc = InitialPad + EntryWidth;
 
   FOut.PadToColumn(InitialPad) << EntryDescPair.first;
-  // If the buffer's length is greater then PadForDesc, print a newline.
+  // If the buffer's length is greater than PadForDesc, print a newline.
   if (FOut.getColumn() > PadForDesc)
 FOut << '\n';
 
Index: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===
--- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -177,23 +177,23 @@
   /// description in a formatted manner. If \p MinLineWidth is set to 0, no line
   /// breaks are introduced for the description.
   ///
-  /// Format, depending whether the option name's length is less then
-  /// \p OptionWidth:
+  /// Format, depending whether the option name's length is less than
+  /// \p EntryWidth:
   ///
   ///   EntryNameDescription
   ///   <-padding->Description
   ///   <-padding->Description
   ///
-  ///   VeryVeryLongOptionName
+  ///   VeryVeryLongEntryName
   ///   <-padding->Description
   ///   <-padding->Description
-  ///   ^~~~ InitialPad
-  ///   ^~ EntryWidth
+  ///   ^InitialPad
+  

[PATCH] D86334: [analyzer] Remove redundant output errs

2020-08-21 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

I don't have commit access, can you help commit it?

In D86334#2230032 , @xazax.hun wrote:

> LGTM, thanks!




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86334

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


[PATCH] D86334: [analyzer] Remove redundant output errs

2020-08-21 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp created this revision.
Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a project: clang.
nullptr.cpp requested review of this revision.

No need to output errs if already have NDEBUG defined.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86334

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp


Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3154,8 +3154,9 @@
 #ifndef NDEBUG
   std::string Filename = DumpGraph(trim);
   llvm::DisplayGraph(Filename, false, llvm::GraphProgram::DOT);
-#endif
+#else
   llvm::errs() << "Warning: viewing graph requires assertions" << "\n";
+#endif
 }
 
 
@@ -3163,8 +3164,9 @@
 #ifndef NDEBUG
   std::string Filename = DumpGraph(Nodes);
   llvm::DisplayGraph(Filename, false, llvm::GraphProgram::DOT);
-#endif
+#else
   llvm::errs() << "Warning: viewing graph requires assertions" << "\n";
+#endif
 }
 
 std::string ExprEngine::DumpGraph(bool trim, StringRef Filename) {
@@ -3207,9 +3209,10 @@
 /*Title=*/"Trimmed Exploded Graph",
 /*Filename=*/std::string(Filename));
   }
-#endif
+#else
   llvm::errs() << "Warning: dumping graph requires assertions" << "\n";
   return "";
+#endif
 }
 
 void *ProgramStateTrait::GDMIndex() {


Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3154,8 +3154,9 @@
 #ifndef NDEBUG
   std::string Filename = DumpGraph(trim);
   llvm::DisplayGraph(Filename, false, llvm::GraphProgram::DOT);
-#endif
+#else
   llvm::errs() << "Warning: viewing graph requires assertions" << "\n";
+#endif
 }
 
 
@@ -3163,8 +3164,9 @@
 #ifndef NDEBUG
   std::string Filename = DumpGraph(Nodes);
   llvm::DisplayGraph(Filename, false, llvm::GraphProgram::DOT);
-#endif
+#else
   llvm::errs() << "Warning: viewing graph requires assertions" << "\n";
+#endif
 }
 
 std::string ExprEngine::DumpGraph(bool trim, StringRef Filename) {
@@ -3207,9 +3209,10 @@
 /*Title=*/"Trimmed Exploded Graph",
 /*Filename=*/std::string(Filename));
   }
-#endif
+#else
   llvm::errs() << "Warning: dumping graph requires assertions" << "\n";
   return "";
+#endif
 }
 
 void *ProgramStateTrait::GDMIndex() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits