[clang] f6af446 - Revert "[Concepts] Fix overload resolution bug with constrained candidates"

2022-04-23 Thread Nick Kreeger via cfe-commits

Author: Nick Kreeger
Date: 2022-04-23T19:35:41-05:00
New Revision: f6af446b6625657b1b9046273f5b33bc1173a97c

URL: 
https://github.com/llvm/llvm-project/commit/f6af446b6625657b1b9046273f5b33bc1173a97c
DIFF: 
https://github.com/llvm/llvm-project/commit/f6af446b6625657b1b9046273f5b33bc1173a97c.diff

LOG: Revert "[Concepts] Fix overload resolution bug with constrained candidates"

This reverts commit 807e418413a0958ad1ea862093fb262673b2afa1.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e78167bad589e..3f1c86cdc3aca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,11 +123,6 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
-- Overload resolution for constrained function templates could use the partial
-  order of constraints to select an overload, even if the parameter types of
-  the functions were 
diff erent. It now diagnoses this case correctly as an
-  ambiguous call and an error. Fixes
-  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 114725498c982..9093bb39e9e86 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,8 +3580,7 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr,
-  bool Reversed = false);
+  unsigned *ArgPos = nullptr);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8750,8 +8749,7 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false,
-  bool AllowOrderingByConstraints = true);
+  unsigned NumCallArguments2, bool Reversed = false);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6e45fdfbeb089..1add971a81a02 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,30 +2945,24 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their parameter types. Caller has already checked that
-/// they have same number of parameters.  If the parameters are 
diff erent,
+/// for equality of their argument types. Caller has already checked that
+/// they have same number of arguments.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
-/// If `Reversed` is true, the parameters of `NewType` will be compared in
-/// reverse order. That's useful if one of the functions is being used as a 
C++20
-/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos, bool Reversed) {
-  assert(OldType->getNumParams() == NewType->getNumParams() &&
- "Can't compare parameters of functions with 
diff erent number of "
- "parameters!");
-  for (size_t I = 0; I < OldType->getNumParams(); I++) {
-// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
-size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
-
+  unsigned *ArgPos) {
+  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
+  N = NewType->param_type_begin(),
+  E = OldType->param_type_end();
+   O && (O != E); ++O, ++N) {
 // Ignore address spaces in pointee type. This is to disallow overloading
 // on __ptr32/__ptr64 address spaces

[clang] a0636b5 - Revert "Revert "[Concepts] Fix overload resolution bug with constrained candidates""

2022-04-23 Thread Nick Kreeger via cfe-commits

Author: Nick Kreeger
Date: 2022-04-23T19:35:50-05:00
New Revision: a0636b5855f5ba1f7033670dc32c956d63baaa51

URL: 
https://github.com/llvm/llvm-project/commit/a0636b5855f5ba1f7033670dc32c956d63baaa51
DIFF: 
https://github.com/llvm/llvm-project/commit/a0636b5855f5ba1f7033670dc32c956d63baaa51.diff

LOG: Revert "Revert "[Concepts] Fix overload resolution bug with constrained 
candidates""

This reverts commit f6af446b6625657b1b9046273f5b33bc1173a97c.

Added: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f1c86cdc3aca..e78167bad589e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,6 +123,11 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
+- Overload resolution for constrained function templates could use the partial
+  order of constraints to select an overload, even if the parameter types of
+  the functions were 
diff erent. It now diagnoses this case correctly as an
+  ambiguous call and an error. Fixes
+  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9093bb39e9e86..114725498c982 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,7 +3580,8 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr);
+  unsigned *ArgPos = nullptr,
+  bool Reversed = false);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8749,7 +8750,8 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false);
+  unsigned NumCallArguments2, bool Reversed = false,
+  bool AllowOrderingByConstraints = true);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1add971a81a02..6e45fdfbeb089 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,24 +2945,30 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their argument types. Caller has already checked that
-/// they have same number of arguments.  If the parameters are 
diff erent,
+/// for equality of their parameter types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
+/// If `Reversed` is true, the parameters of `NewType` will be compared in
+/// reverse order. That's useful if one of the functions is being used as a 
C++20
+/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos) {
-  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
-  N = NewType->param_type_begin(),
-  E = OldType->param_type_end();
-   O && (O != E); ++O, ++N) {
+  unsigned *ArgPos, bool Reversed) {
+  assert(OldType->getNumParams() == NewType->getNumParams() &&
+ "Can't compare parameters of functions with 
diff erent number of "
+ "parameters!");
+  for (size_t I = 0; I < OldType->getNumParams(); I++) {
+// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
+size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
+
 // Ignore address spaces in pointee type. This is to disallow overloading
 // on __ptr32/__ptr64 addr

[clang] cfc2c59 - Revert "Revert "Revert "[Concepts] Fix overload resolution bug with constrained candidates"""

2022-04-23 Thread Nick Kreeger via cfe-commits

Author: Nick Kreeger
Date: 2022-04-23T19:36:51-05:00
New Revision: cfc2c5905ec11a501cdfc9502f503ab494c200b6

URL: 
https://github.com/llvm/llvm-project/commit/cfc2c5905ec11a501cdfc9502f503ab494c200b6
DIFF: 
https://github.com/llvm/llvm-project/commit/cfc2c5905ec11a501cdfc9502f503ab494c200b6.diff

LOG: Revert "Revert "Revert "[Concepts] Fix overload resolution bug with 
constrained candidates"""

This reverts commit a0636b5855f5ba1f7033670dc32c956d63baaa51.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e78167bad589e..3f1c86cdc3aca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,11 +123,6 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
-- Overload resolution for constrained function templates could use the partial
-  order of constraints to select an overload, even if the parameter types of
-  the functions were 
diff erent. It now diagnoses this case correctly as an
-  ambiguous call and an error. Fixes
-  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 114725498c982..9093bb39e9e86 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,8 +3580,7 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr,
-  bool Reversed = false);
+  unsigned *ArgPos = nullptr);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8750,8 +8749,7 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false,
-  bool AllowOrderingByConstraints = true);
+  unsigned NumCallArguments2, bool Reversed = false);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6e45fdfbeb089..1add971a81a02 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,30 +2945,24 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their parameter types. Caller has already checked that
-/// they have same number of parameters.  If the parameters are 
diff erent,
+/// for equality of their argument types. Caller has already checked that
+/// they have same number of arguments.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
-/// If `Reversed` is true, the parameters of `NewType` will be compared in
-/// reverse order. That's useful if one of the functions is being used as a 
C++20
-/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos, bool Reversed) {
-  assert(OldType->getNumParams() == NewType->getNumParams() &&
- "Can't compare parameters of functions with 
diff erent number of "
- "parameters!");
-  for (size_t I = 0; I < OldType->getNumParams(); I++) {
-// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
-size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
-
+  unsigned *ArgPos) {
+  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
+  N = NewType->param_type_begin(),
+  E = OldType->param_type_end();
+   O && (O != E); ++O, ++N) {
 // Ignore address spaces in pointee type. This is to disallow overloading
 // on __ptr32/__p

[clang] d1b73f3 - Reverting accidental git-revert commits.

2022-04-23 Thread Nick Kreeger via cfe-commits

Author: Nick Kreeger
Date: 2022-04-23T20:11:27-05:00
New Revision: d1b73f3412b389e2e515ee5ce9ec87c127ebcb01

URL: 
https://github.com/llvm/llvm-project/commit/d1b73f3412b389e2e515ee5ce9ec87c127ebcb01
DIFF: 
https://github.com/llvm/llvm-project/commit/d1b73f3412b389e2e515ee5ce9ec87c127ebcb01.diff

LOG: Reverting accidental git-revert commits.

Revert "Revert "[Concepts] Fix overload resolution bug with constrained 
candidates""

This reverts commit f6af446b6625657b1b9046273f5b33bc1173a97c.

Added: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f1c86cdc3aca..e78167bad589e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,6 +123,11 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
+- Overload resolution for constrained function templates could use the partial
+  order of constraints to select an overload, even if the parameter types of
+  the functions were 
diff erent. It now diagnoses this case correctly as an
+  ambiguous call and an error. Fixes
+  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9093bb39e9e86..114725498c982 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,7 +3580,8 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr);
+  unsigned *ArgPos = nullptr,
+  bool Reversed = false);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8749,7 +8750,8 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false);
+  unsigned NumCallArguments2, bool Reversed = false,
+  bool AllowOrderingByConstraints = true);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1add971a81a02..6e45fdfbeb089 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,24 +2945,30 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their argument types. Caller has already checked that
-/// they have same number of arguments.  If the parameters are 
diff erent,
+/// for equality of their parameter types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
+/// If `Reversed` is true, the parameters of `NewType` will be compared in
+/// reverse order. That's useful if one of the functions is being used as a 
C++20
+/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos) {
-  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
-  N = NewType->param_type_begin(),
-  E = OldType->param_type_end();
-   O && (O != E); ++O, ++N) {
+  unsigned *ArgPos, bool Reversed) {
+  assert(OldType->getNumParams() == NewType->getNumParams() &&
+ "Can't compare parameters of functions with 
diff erent number of "
+ "parameters!");
+  for (size_t I = 0; I < OldType->getNumParams(); I++) {
+// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
+size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
+
 // Ignore address spaces in pointee type. This is to disallow o

[clang] 2d80889 - Reverting accidental git-revert commits.

2022-04-23 Thread Nick Kreeger via cfe-commits

Author: Nick Kreeger
Date: 2022-04-23T20:11:58-05:00
New Revision: 2d80889b2a9ea693355e4d3e617287591a7f573c

URL: 
https://github.com/llvm/llvm-project/commit/2d80889b2a9ea693355e4d3e617287591a7f573c
DIFF: 
https://github.com/llvm/llvm-project/commit/2d80889b2a9ea693355e4d3e617287591a7f573c.diff

LOG: Reverting accidental git-revert commits.

Revert "Revert "Revert "[Concepts] Fix overload resolution bug with constrained 
candidates"""

This reverts commit a0636b5855f5ba1f7033670dc32c956d63baaa51.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e78167bad589e..3f1c86cdc3aca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,11 +123,6 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
-- Overload resolution for constrained function templates could use the partial
-  order of constraints to select an overload, even if the parameter types of
-  the functions were 
diff erent. It now diagnoses this case correctly as an
-  ambiguous call and an error. Fixes
-  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 114725498c982..9093bb39e9e86 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,8 +3580,7 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr,
-  bool Reversed = false);
+  unsigned *ArgPos = nullptr);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8750,8 +8749,7 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false,
-  bool AllowOrderingByConstraints = true);
+  unsigned NumCallArguments2, bool Reversed = false);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6e45fdfbeb089..1add971a81a02 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,30 +2945,24 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their parameter types. Caller has already checked that
-/// they have same number of parameters.  If the parameters are 
diff erent,
+/// for equality of their argument types. Caller has already checked that
+/// they have same number of arguments.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
-/// If `Reversed` is true, the parameters of `NewType` will be compared in
-/// reverse order. That's useful if one of the functions is being used as a 
C++20
-/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos, bool Reversed) {
-  assert(OldType->getNumParams() == NewType->getNumParams() &&
- "Can't compare parameters of functions with 
diff erent number of "
- "parameters!");
-  for (size_t I = 0; I < OldType->getNumParams(); I++) {
-// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
-size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
-
+  unsigned *ArgPos) {
+  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
+  N = NewType->param_type_begin(),
+  E = OldType->param_type_end();
+   O && (O != E); ++O, ++N) {
 // Ignore address spaces in pointee type. This is to d

[clang] afa20af - Reverting accidental git-revert commits.

2022-04-23 Thread Nick Kreeger via cfe-commits

Author: Nick Kreeger
Date: 2022-04-23T20:12:15-05:00
New Revision: afa20aff6ef009889f9b75a2412fea09940eaf61

URL: 
https://github.com/llvm/llvm-project/commit/afa20aff6ef009889f9b75a2412fea09940eaf61
DIFF: 
https://github.com/llvm/llvm-project/commit/afa20aff6ef009889f9b75a2412fea09940eaf61.diff

LOG: Reverting accidental git-revert commits.

Revert "Revert "Revert "Revert "[Concepts] Fix overload resolution bug with 
constrained candidates

This reverts commit cfc2c5905ec11a501cdfc9502f503ab494c200b6.

Added: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f1c86cdc3aca..e78167bad589e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,6 +123,11 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
+- Overload resolution for constrained function templates could use the partial
+  order of constraints to select an overload, even if the parameter types of
+  the functions were 
diff erent. It now diagnoses this case correctly as an
+  ambiguous call and an error. Fixes
+  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9093bb39e9e86..114725498c982 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,7 +3580,8 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr);
+  unsigned *ArgPos = nullptr,
+  bool Reversed = false);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8749,7 +8750,8 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false);
+  unsigned NumCallArguments2, bool Reversed = false,
+  bool AllowOrderingByConstraints = true);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1add971a81a02..6e45fdfbeb089 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,24 +2945,30 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their argument types. Caller has already checked that
-/// they have same number of arguments.  If the parameters are 
diff erent,
+/// for equality of their parameter types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
+/// If `Reversed` is true, the parameters of `NewType` will be compared in
+/// reverse order. That's useful if one of the functions is being used as a 
C++20
+/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos) {
-  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
-  N = NewType->param_type_begin(),
-  E = OldType->param_type_end();
-   O && (O != E); ++O, ++N) {
+  unsigned *ArgPos, bool Reversed) {
+  assert(OldType->getNumParams() == NewType->getNumParams() &&
+ "Can't compare parameters of functions with 
diff erent number of "
+ "parameters!");
+  for (size_t I = 0; I < OldType->getNumParams(); I++) {
+// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
+size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
+
 // Ignore address spaces in pointee type. Thi