forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Clang][Sema] Ignore previous partial specializations of member templ…
…ates explicitly specialized for an implicitly instantiated class template specialization (llvm#113464) Consider the following: ``` template<typename T> struct A { template<typename U> struct B { static constexpr int x = 0; // #1 }; template<typename U> struct B<U*> { static constexpr int x = 1; // llvm#2 }; }; template<> template<typename U> struct A<long>::B { static constexpr int x = 2; // llvm#3 }; static_assert(A<short>::B<int>::y == 0); // uses #1 static_assert(A<short>::B<int*>::y == 1); // uses llvm#2 static_assert(A<long>::B<int>::y == 2); // uses llvm#3 static_assert(A<long>::B<int*>::y == 2); // uses llvm#3 ``` According to [temp.spec.partial.member] p2: > If the primary member template is explicitly specialized for a given (implicit) specialization of the enclosing class template, the partial specializations of the member template are ignored for this specialization of the enclosing class template. If a partial specialization of the member template is explicitly specialized for a given (implicit) specialization of the enclosing class template, the primary member template and its other partial specializations are still considered for this specialization of the enclosing class template. The example above fails to compile because we currently don't implement [temp.spec.partial.member] p2. This patch implements the wording, fixing llvm#51051.
- Loading branch information
1 parent
e989e31
commit 7d1e283
Showing
4 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
clang/test/CXX/temp/temp.decls/temp.spec.partial/temp.spec.partial.member/p2.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s | ||
// expected-no-diagnostics | ||
|
||
template<typename T> | ||
struct A { | ||
template<typename U> | ||
struct B { | ||
static constexpr int y = 0; | ||
}; | ||
|
||
template<typename U> | ||
struct B<U*> { | ||
static constexpr int y = 1; | ||
}; | ||
|
||
template<typename U> | ||
static constexpr int x = 0; | ||
|
||
template<typename U> | ||
static constexpr int x<U*> = 1; | ||
}; | ||
|
||
template<typename T> | ||
template<typename U> | ||
struct A<T>::B<U[]> { | ||
static constexpr int y = 2; | ||
}; | ||
|
||
template<typename T> | ||
template<typename U> | ||
constexpr int A<T>::x<U[]> = 2; | ||
|
||
static_assert(A<short>::B<int>::y == 0); | ||
static_assert(A<short>::B<int*>::y == 1); | ||
static_assert(A<short>::B<int[]>::y == 2); | ||
static_assert(A<short>::x<int> == 0); | ||
static_assert(A<short>::x<int*> == 1); | ||
static_assert(A<short>::x<int[]> == 2); | ||
|
||
template<> | ||
template<typename U> | ||
struct A<int>::B { | ||
static constexpr int y = 3; | ||
}; | ||
|
||
template<> | ||
template<typename U> | ||
struct A<int>::B<U&> { | ||
static constexpr int y = 4; | ||
}; | ||
|
||
template<> | ||
template<typename U> | ||
struct A<long>::B<U&> { | ||
static constexpr int y = 5; | ||
}; | ||
|
||
template<> | ||
template<typename U> | ||
constexpr int A<int>::x = 3; | ||
|
||
template<> | ||
template<typename U> | ||
constexpr int A<int>::x<U&> = 4; | ||
|
||
template<> | ||
template<typename U> | ||
constexpr int A<long>::x<U&> = 5; | ||
|
||
static_assert(A<int>::B<int>::y == 3); | ||
static_assert(A<int>::B<int*>::y == 3); | ||
static_assert(A<int>::B<int[]>::y == 3); | ||
static_assert(A<int>::B<int&>::y == 4); | ||
static_assert(A<int>::x<int> == 3); | ||
static_assert(A<int>::x<int*> == 3); | ||
static_assert(A<int>::x<int[]> == 3); | ||
static_assert(A<int>::x<int&> == 4); | ||
static_assert(A<long>::B<int>::y == 0); | ||
static_assert(A<long>::B<int*>::y == 1); | ||
static_assert(A<long>::B<int[]>::y == 2); | ||
static_assert(A<long>::B<int&>::y == 5); | ||
static_assert(A<long>::x<int> == 0); | ||
static_assert(A<long>::x<int*> == 1); | ||
static_assert(A<long>::x<int[]> == 2); | ||
static_assert(A<long>::x<int&> == 5); |