Skip to content

Commit b56b3d7

Browse files
authored
[Clang][Sema] Don't consider top-level cv-qualifiers in template partial orderings (#81449)
This fixes a regression since 340eac0, 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 #75404.
1 parent bc8910d commit b56b3d7

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ Bug Fixes to C++ Support
228228
or non-constant more accurately. Previously, only a subset of the initializer
229229
elements were considered, misclassifying some initializers as constant. Fixes
230230
some of (`#80510 <https://github.com/llvm/llvm-project/issues/80510>`).
231+
- Clang now ignores top-level cv-qualifiers on function parameters in template partial orderings.
232+
(`#75404 <https://github.com/llvm/llvm-project/issues/75404>`_)
231233

232234
Bug Fixes to AST Handling
233235
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5642,9 +5642,12 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
56425642
Sema::TPL_TemplateParamsEquivalent))
56435643
return nullptr;
56445644

5645+
// [dcl.fct]p5:
5646+
// Any top-level cv-qualifiers modifying a parameter type are deleted when
5647+
// forming the function type.
56455648
for (unsigned i = 0; i < NumParams1; ++i)
5646-
if (!Context.hasSameType(FD1->getParamDecl(i)->getType(),
5647-
FD2->getParamDecl(i)->getType()))
5649+
if (!Context.hasSameUnqualifiedType(FD1->getParamDecl(i)->getType(),
5650+
FD2->getParamDecl(i)->getType()))
56485651
return nullptr;
56495652

56505653
// C++20 [temp.func.order]p6.3:

clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,16 @@ namespace non_template
9797
static_assert(is_same_v<decltype(baz<int>()), int>); // expected-error {{call to 'baz' is ambiguous}}
9898
static_assert(is_same_v<decltype(bar<int>()), void>); // expected-error {{call to 'bar' is ambiguous}}
9999

100+
// Top-level cv-qualifiers are ignored in template partial ordering per [dcl.fct]/p5.
101+
// After producing the list of parameter types, any top-level cv-qualifiers modifying
102+
// a parameter type are deleted when forming the function type.
100103
template<typename T>
101-
constexpr int goo(int a) requires AtLeast2<int> && true { // expected-note {{candidate function}}
104+
constexpr int goo(T a) requires AtLeast2<T> && true {
102105
return 1;
103106
}
104107

105108
template<typename T>
106-
constexpr int goo(const int b) requires AtLeast2<int> { // expected-note {{candidate function}}
109+
constexpr int goo(const T b) requires AtLeast2<T> {
107110
return 2;
108111
}
109112

@@ -122,7 +125,6 @@ namespace non_template
122125
return 2;
123126
}
124127

125-
// By temp.func.order-6.2.2, this is ambiguous because parameter a and b have different types.
126-
static_assert(goo<int>(1) == 1); // expected-error {{call to 'goo' is ambiguous}}
128+
static_assert(goo<int>(1) == 1);
127129
static_assert(doo<int>(2) == 1);
128130
}

0 commit comments

Comments
 (0)