Skip to content

Commit 0ebdcec

Browse files
author
huqizhi
committed
[clang] visit constraint of NTTP
1 parent 5bde801 commit 0ebdcec

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ Bug Fixes to C++ Support
707707
initialized, rather than evaluating them as a part of the larger manifestly constant evaluated
708708
expression.
709709
- Fix a bug in access control checking due to dealyed checking of friend declaration. Fixes (#GH12361).
710+
- Fix a bug on template class partial specialization due to traverse of constraint of NTTP. Fixes (#GH77377).
710711

711712
Bug Fixes to AST Handling
712713
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/StmtProfile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,10 @@ void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
22572257
const SubstNonTypeTemplateParmExpr *E) {
22582258
// Profile exactly as the replacement expression.
22592259
Visit(E->getReplacement());
2260+
if (auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(E->getParameter());
2261+
NTTP && NTTP->getPlaceholderTypeConstraint()) {
2262+
Visit(NTTP->getPlaceholderTypeConstraint());
2263+
}
22602264
}
22612265

22622266
void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ template<C T, int I> struct Y2<T*, I, I+1+1> {}; // expected-note {{partial
7979
template<C T, C auto I, int W, A S, template<typename, auto, int, A, typename...> class U, typename... Z>
8080
struct Y3 { Y3()=delete; };
8181
template<C T, D auto I, int W, A S, template<typename, auto, int, A, typename...> class U, typename... Z>
82-
struct Y3<T, I, W, S, U, Z...> { Y3()=delete; };
82+
struct Y3<T, I, W, S, U, Z...> { Y3()=delete; }; // expected-note {{partial specialization matches [with T = int, I = 1, W = 1, S = A{}, U = S, Z = <int>]}}
8383
template<C T, E auto I, int W, A S, template<typename, auto, int, A, typename...> class U, typename... Z>
84-
struct Y3<T, I, W, S, U, Z...> {};
84+
struct Y3<T, I, W, S, U, Z...> {}; // expected-note {{partial specialization matches [with T = int, I = 1, W = 1, S = A{}, U = S, Z = <int>]}}
8585

8686
void f() {
8787
Y1<int, 2> a;
8888
Y2<char*, 1, 3> b; // expected-error {{ambiguous partial specializations}}
89-
Y3<int, 1, 1, A{}, S, int> c;
89+
Y3<int, 1, 1, A{}, S, int> c; // expected-error {{ambiguous partial specializations of 'Y3<int, 1, 1, A{}, S, int>'}}
9090
}
9191

9292
// Per [temp.func.order]p6.2.2, specifically "if the function parameters that

clang/test/SemaCXX/PR77377.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
2+
// expected-no-diagnostics
3+
4+
template<typename T, typename U>
5+
constexpr bool is_same_v = false;
6+
7+
template<typename T>
8+
constexpr bool is_same_v<T, T> = true;
9+
10+
template<typename T, typename U>
11+
concept same_as = is_same_v<T, U>;
12+
13+
template <auto>
14+
struct A {};
15+
16+
template <same_as<int> auto p>
17+
struct A<p> {};
18+
19+
A<0> a;

0 commit comments

Comments
 (0)