Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/llvm/llvm-project/issues/80510>`).
- Clang now ignores top-level cv-qualifiers on function parameters in template partial orderings.
(`#75404 <https://github.com/llvm/llvm-project/issues/75404>`_)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
7 changes: 5 additions & 2 deletions clang/lib/Sema/SemaTemplateDeduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@ namespace non_template
static_assert(is_same_v<decltype(baz<int>()), int>); // expected-error {{call to 'baz' is ambiguous}}
static_assert(is_same_v<decltype(bar<int>()), 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<typename T>
constexpr int goo(int a) requires AtLeast2<int> && true { // expected-note {{candidate function}}
constexpr int goo(T a) requires AtLeast2<T> && true {
return 1;
}

template<typename T>
constexpr int goo(const int b) requires AtLeast2<int> { // expected-note {{candidate function}}
constexpr int goo(const T b) requires AtLeast2<T> {
return 2;
}

Expand All @@ -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<int>(1) == 1); // expected-error {{call to 'goo' is ambiguous}}
static_assert(goo<int>(1) == 1);
static_assert(doo<int>(2) == 1);
}