[clang] [Clang][Sema] Don't consider top-level cv-qualifiers in template partial orderings (PR #81449)

2024-02-12 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/81449

This fixes a regression since 
https://github.com/llvm/llvm-project/commit/340eac01f7dad6c24cee35dd35f2484098dd6b1a,
 from which we compared function parameter types with cv-qualifiers taken into 
account. However, as per [dcl.fct]/p5:

> After producing the list of parameter types, any top-level cv-qualifiers 
> modifying
> a parameter type are deleted when forming the function type.

Thus, I think we should use `hasSameUnqualifiedType` for type comparison.

This fixes https://github.com/llvm/llvm-project/issues/75404.

>From f4fb72075b8b3242656c10618eb5baa6a4204907 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 12 Feb 2024 15:47:59 +0800
Subject: [PATCH] [Clang][Sema] Don't consider top-level cv-qualifiers in
 template partial orderings

This fixes a regression since
https://github.com/llvm/llvm-project/commit/340eac01f7dad6c24cee35dd35f2484098dd6b1a,
from which we compared function parameter types with cv-qualifiers
taken into account. However, as per [dcl.fct]/p5:

> After producing the list of parameter types, any top-level cv-qualifiers 
> modifying
> a parameter type are deleted when forming the function type.

Thus I think we should use hasSameUnqualifiedType for type comparison.

This fixes https://github.com/llvm/llvm-project/issues/75404.
---
 clang/docs/ReleaseNotes.rst  | 2 ++
 clang/lib/Sema/SemaTemplateDeduction.cpp | 7 +--
 clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp | 7 +++
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ece6013f672621..88006b4fb782e9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@ Bug Fixes to C++ Support
   or non-constant more accurately. Previously, only a subset of the initializer
   elements were considered, misclassifying some initializers as constant. Fixes
   some of (`#80510 `).
+- Clang now ignores top-level cv-qualifiers on function parameters in template 
partial orderings.
+  (`#75404 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index a54ad27975890a..69c35db2945eb7 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5599,9 +5599,12 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
   Sema::TPL_TemplateParamsEquivalent))
 return nullptr;
 
+  // [dcl.fct]p5:
+  // Any top-level cv-qualifiers modifying a parameter type are deleted when
+  // forming the function type.
   for (unsigned i = 0; i < NumParams1; ++i)
-if (!Context.hasSameType(FD1->getParamDecl(i)->getType(),
- FD2->getParamDecl(i)->getType()))
+if (!Context.hasSameUnqualifiedType(FD1->getParamDecl(i)->getType(),
+FD2->getParamDecl(i)->getType()))
   return nullptr;
 
   // C++20 [temp.func.order]p6.3:
diff --git a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
index dae1ba760cc203..cec487575d8093 100644
--- a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -98,12 +98,12 @@ namespace non_template
   static_assert(is_same_v()), void>); // expected-error 
{{call to 'bar' is ambiguous}}
 
   template
-  constexpr int goo(int a) requires AtLeast2 && true { // expected-note 
{{candidate function}}
+  constexpr int goo(T a) requires AtLeast2 && true {
 return 1;
   }
 
   template
-  constexpr int goo(const int b) requires AtLeast2 { // expected-note 
{{candidate function}}
+  constexpr int goo(const T b) requires AtLeast2 {
 return 2;
   }
 
@@ -122,7 +122,6 @@ namespace non_template
 return 2;
   }
 
-  // By temp.func.order-6.2.2, this is ambiguous because parameter a and b 
have different types.
-  static_assert(goo(1) == 1); // expected-error {{call to 'goo' is 
ambiguous}}
+  static_assert(goo(1) == 1);
   static_assert(doo(2) == 1);
 }

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


[clang] [Clang][Sema] Don't consider top-level cv-qualifiers in template partial orderings (PR #81449)

2024-02-12 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/81449

>From f4fb72075b8b3242656c10618eb5baa6a4204907 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 12 Feb 2024 15:47:59 +0800
Subject: [PATCH 1/2] [Clang][Sema] Don't consider top-level cv-qualifiers in
 template partial orderings

This fixes a regression since
https://github.com/llvm/llvm-project/commit/340eac01f7dad6c24cee35dd35f2484098dd6b1a,
from which we compared function parameter types with cv-qualifiers
taken into account. However, as per [dcl.fct]/p5:

> After producing the list of parameter types, any top-level cv-qualifiers 
> modifying
> a parameter type are deleted when forming the function type.

Thus I think we should use hasSameUnqualifiedType for type comparison.

This fixes https://github.com/llvm/llvm-project/issues/75404.
---
 clang/docs/ReleaseNotes.rst  | 2 ++
 clang/lib/Sema/SemaTemplateDeduction.cpp | 7 +--
 clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp | 7 +++
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ece6013f672621..88006b4fb782e9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@ Bug Fixes to C++ Support
   or non-constant more accurately. Previously, only a subset of the initializer
   elements were considered, misclassifying some initializers as constant. Fixes
   some of (`#80510 `).
+- Clang now ignores top-level cv-qualifiers on function parameters in template 
partial orderings.
+  (`#75404 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index a54ad27975890a..69c35db2945eb7 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5599,9 +5599,12 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
   Sema::TPL_TemplateParamsEquivalent))
 return nullptr;
 
+  // [dcl.fct]p5:
+  // Any top-level cv-qualifiers modifying a parameter type are deleted when
+  // forming the function type.
   for (unsigned i = 0; i < NumParams1; ++i)
-if (!Context.hasSameType(FD1->getParamDecl(i)->getType(),
- FD2->getParamDecl(i)->getType()))
+if (!Context.hasSameUnqualifiedType(FD1->getParamDecl(i)->getType(),
+FD2->getParamDecl(i)->getType()))
   return nullptr;
 
   // C++20 [temp.func.order]p6.3:
diff --git a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
index dae1ba760cc203..cec487575d8093 100644
--- a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -98,12 +98,12 @@ namespace non_template
   static_assert(is_same_v()), void>); // expected-error 
{{call to 'bar' is ambiguous}}
 
   template
-  constexpr int goo(int a) requires AtLeast2 && true { // expected-note 
{{candidate function}}
+  constexpr int goo(T a) requires AtLeast2 && true {
 return 1;
   }
 
   template
-  constexpr int goo(const int b) requires AtLeast2 { // expected-note 
{{candidate function}}
+  constexpr int goo(const T b) requires AtLeast2 {
 return 2;
   }
 
@@ -122,7 +122,6 @@ namespace non_template
 return 2;
   }
 
-  // By temp.func.order-6.2.2, this is ambiguous because parameter a and b 
have different types.
-  static_assert(goo(1) == 1); // expected-error {{call to 'goo' is 
ambiguous}}
+  static_assert(goo(1) == 1);
   static_assert(doo(2) == 1);
 }

>From 1f66c477b8236bc798bd9823d8cd5b0f26888a1c Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 12 Feb 2024 16:18:44 +0800
Subject: [PATCH 2/2] comment

---
 clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
index cec487575d8093..db3e3e3bc85966 100644
--- a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -97,6 +97,9 @@ namespace non_template
   static_assert(is_same_v()), int>); // expected-error 
{{call to 'baz' is ambiguous}}
   static_assert(is_same_v()), void>); // expected-error 
{{call to 'bar' is ambiguous}}
 
+  // Top-level cv-qualifiers are ignored in template partial ordering per 
[dcl.fct]/p5.
+  //   After producing the list of parameter types, any top-level 
cv-qualifiers modifying
+  //   a parameter type are deleted when forming the function type.
   template
   constexpr int goo(T a) requires AtLeast2 && true {
 return 1;

___
cfe-com

[clang] [Clang][Sema] Don't consider top-level cv-qualifiers in template partial orderings (PR #81449)

2024-02-12 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/81449

>From f4fb72075b8b3242656c10618eb5baa6a4204907 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 12 Feb 2024 15:47:59 +0800
Subject: [PATCH 1/2] [Clang][Sema] Don't consider top-level cv-qualifiers in
 template partial orderings

This fixes a regression since
https://github.com/llvm/llvm-project/commit/340eac01f7dad6c24cee35dd35f2484098dd6b1a,
from which we compared function parameter types with cv-qualifiers
taken into account. However, as per [dcl.fct]/p5:

> After producing the list of parameter types, any top-level cv-qualifiers 
> modifying
> a parameter type are deleted when forming the function type.

Thus I think we should use hasSameUnqualifiedType for type comparison.

This fixes https://github.com/llvm/llvm-project/issues/75404.
---
 clang/docs/ReleaseNotes.rst  | 2 ++
 clang/lib/Sema/SemaTemplateDeduction.cpp | 7 +--
 clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp | 7 +++
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ece6013f672621..88006b4fb782e9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@ Bug Fixes to C++ Support
   or non-constant more accurately. Previously, only a subset of the initializer
   elements were considered, misclassifying some initializers as constant. Fixes
   some of (`#80510 `).
+- Clang now ignores top-level cv-qualifiers on function parameters in template 
partial orderings.
+  (`#75404 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index a54ad27975890a..69c35db2945eb7 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5599,9 +5599,12 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
   Sema::TPL_TemplateParamsEquivalent))
 return nullptr;
 
+  // [dcl.fct]p5:
+  // Any top-level cv-qualifiers modifying a parameter type are deleted when
+  // forming the function type.
   for (unsigned i = 0; i < NumParams1; ++i)
-if (!Context.hasSameType(FD1->getParamDecl(i)->getType(),
- FD2->getParamDecl(i)->getType()))
+if (!Context.hasSameUnqualifiedType(FD1->getParamDecl(i)->getType(),
+FD2->getParamDecl(i)->getType()))
   return nullptr;
 
   // C++20 [temp.func.order]p6.3:
diff --git a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
index dae1ba760cc203..cec487575d8093 100644
--- a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -98,12 +98,12 @@ namespace non_template
   static_assert(is_same_v()), void>); // expected-error 
{{call to 'bar' is ambiguous}}
 
   template
-  constexpr int goo(int a) requires AtLeast2 && true { // expected-note 
{{candidate function}}
+  constexpr int goo(T a) requires AtLeast2 && true {
 return 1;
   }
 
   template
-  constexpr int goo(const int b) requires AtLeast2 { // expected-note 
{{candidate function}}
+  constexpr int goo(const T b) requires AtLeast2 {
 return 2;
   }
 
@@ -122,7 +122,6 @@ namespace non_template
 return 2;
   }
 
-  // By temp.func.order-6.2.2, this is ambiguous because parameter a and b 
have different types.
-  static_assert(goo(1) == 1); // expected-error {{call to 'goo' is 
ambiguous}}
+  static_assert(goo(1) == 1);
   static_assert(doo(2) == 1);
 }

>From 1f66c477b8236bc798bd9823d8cd5b0f26888a1c Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 12 Feb 2024 16:18:44 +0800
Subject: [PATCH 2/2] comment

---
 clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
index cec487575d8093..db3e3e3bc85966 100644
--- a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -97,6 +97,9 @@ namespace non_template
   static_assert(is_same_v()), int>); // expected-error 
{{call to 'baz' is ambiguous}}
   static_assert(is_same_v()), void>); // expected-error 
{{call to 'bar' is ambiguous}}
 
+  // Top-level cv-qualifiers are ignored in template partial ordering per 
[dcl.fct]/p5.
+  //   After producing the list of parameter types, any top-level 
cv-qualifiers modifying
+  //   a parameter type are deleted when forming the function type.
   template
   constexpr int goo(T a) requires AtLeast2 && true {
 return 1;

___
cfe-com

[clang] [Clang][Sema] Don't consider top-level cv-qualifiers in template partial orderings (PR #81449)

2024-02-12 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

The Windows CI is still not working; I ran the libc++ tests locally and they 
are green.

https://github.com/llvm/llvm-project/pull/81449
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Don't consider top-level cv-qualifiers in template partial orderings (PR #81449)

2024-02-12 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 ready_for_review 
https://github.com/llvm/llvm-project/pull/81449
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Don't consider top-level cv-qualifiers in template partial orderings (PR #81449)

2024-02-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

This fixes a regression since 
https://github.com/llvm/llvm-project/commit/340eac01f7dad6c24cee35dd35f2484098dd6b1a,
 from which we compared function parameter types with cv-qualifiers taken into 
account. However, as per [dcl.fct]/p5:

> After producing the list of parameter types, any top-level cv-qualifiers 
modifying
> a parameter type are deleted when forming the function type.

Thus, I think we should use `hasSameUnqualifiedType` for type comparison.

This fixes https://github.com/llvm/llvm-project/issues/75404.

---
Full diff: https://github.com/llvm/llvm-project/pull/81449.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+5-2) 
- (modified) clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp (+6-4) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ece6013f672621..88006b4fb782e9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@ Bug Fixes to C++ Support
   or non-constant more accurately. Previously, only a subset of the initializer
   elements were considered, misclassifying some initializers as constant. Fixes
   some of (`#80510 `).
+- Clang now ignores top-level cv-qualifiers on function parameters in template 
partial orderings.
+  (`#75404 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index a54ad27975890a..69c35db2945eb7 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5599,9 +5599,12 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
   Sema::TPL_TemplateParamsEquivalent))
 return nullptr;
 
+  // [dcl.fct]p5:
+  // Any top-level cv-qualifiers modifying a parameter type are deleted when
+  // forming the function type.
   for (unsigned i = 0; i < NumParams1; ++i)
-if (!Context.hasSameType(FD1->getParamDecl(i)->getType(),
- FD2->getParamDecl(i)->getType()))
+if (!Context.hasSameUnqualifiedType(FD1->getParamDecl(i)->getType(),
+FD2->getParamDecl(i)->getType()))
   return nullptr;
 
   // C++20 [temp.func.order]p6.3:
diff --git a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
index dae1ba760cc203..db3e3e3bc85966 100644
--- a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -97,13 +97,16 @@ namespace non_template
   static_assert(is_same_v()), int>); // expected-error 
{{call to 'baz' is ambiguous}}
   static_assert(is_same_v()), void>); // expected-error 
{{call to 'bar' is ambiguous}}
 
+  // Top-level cv-qualifiers are ignored in template partial ordering per 
[dcl.fct]/p5.
+  //   After producing the list of parameter types, any top-level 
cv-qualifiers modifying
+  //   a parameter type are deleted when forming the function type.
   template
-  constexpr int goo(int a) requires AtLeast2 && true { // expected-note 
{{candidate function}}
+  constexpr int goo(T a) requires AtLeast2 && true {
 return 1;
   }
 
   template
-  constexpr int goo(const int b) requires AtLeast2 { // expected-note 
{{candidate function}}
+  constexpr int goo(const T b) requires AtLeast2 {
 return 2;
   }
 
@@ -122,7 +125,6 @@ namespace non_template
 return 2;
   }
 
-  // By temp.func.order-6.2.2, this is ambiguous because parameter a and b 
have different types.
-  static_assert(goo(1) == 1); // expected-error {{call to 'goo' is 
ambiguous}}
+  static_assert(goo(1) == 1);
   static_assert(doo(2) == 1);
 }

``




https://github.com/llvm/llvm-project/pull/81449
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Don't consider top-level cv-qualifiers in template partial orderings (PR #81449)

2024-02-12 Thread Erich Keane via cfe-commits

https://github.com/erichkeane approved this pull request.


https://github.com/llvm/llvm-project/pull/81449
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Don't consider top-level cv-qualifiers in template partial orderings (PR #81449)

2024-02-12 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 closed 
https://github.com/llvm/llvm-project/pull/81449
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits