-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Clang][Sema] Correctly look up primary template for variable templat…
…e specializations (#80359) Consider the following: ``` namespace N0 { namespace N1 { template<typename T> int x1 = 0; } using namespace N1; } template<> int N0::x1<int>; ``` According to [dcl.meaning.general] p3.3: > - If the _declarator_ declares an explicit instantiation or a partial or explicit specialization, the _declarator_ does not bind a name. If it declares a class member, the terminal name of the _declarator-id_ is not looked up; otherwise, **only those lookup results that are nominable in `S` are considered when identifying any function template specialization being declared**. In particular, the requirement for lookup results to be nominal in the lookup context of the terminal name of the _declarator-id_ only applies to function template specializations -- not variable template specializations. We currently reject the above declaration, but we do (correctly) accept it if the using-directive is replaced with a `using` declaration naming `N0::N1::x1`. This patch makes it so the above specialization is (correctly) accepted.
- Loading branch information
1 parent
7b08b43
commit 7ecfb66
Showing
5 changed files
with
130 additions
and
19 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
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
112 changes: 112 additions & 0 deletions
112
clang/test/CXX/dcl.decl/dcl.meaning/dcl.meaning.general/p3.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,112 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify %s | ||
|
||
namespace N0 { | ||
template<typename T> | ||
void f0(); | ||
|
||
template<typename T> | ||
int x0 = 0; | ||
|
||
template<typename T> | ||
class C0; | ||
} | ||
using namespace N0; | ||
|
||
template<> | ||
void f0<int>(); // expected-error {{no function template matches}} | ||
|
||
template<> | ||
int x0<int>; | ||
|
||
template<> | ||
class C0<int>; | ||
|
||
namespace N1 { | ||
namespace N2 { | ||
template<typename T> | ||
void f2(); | ||
|
||
template<typename T> | ||
int x2 = 0; | ||
|
||
template<typename T> | ||
class C2; | ||
} | ||
using namespace N2; | ||
} | ||
|
||
template<> | ||
void N1::f2<int>(); // expected-error {{no function template matches}} | ||
|
||
template<> | ||
int N1::x2<int>; | ||
|
||
template<> | ||
class N1::C2<int>; | ||
|
||
namespace N3 { | ||
namespace N4 { | ||
template<typename T> | ||
void f4(); | ||
|
||
template<typename T> | ||
int x4 = 0; | ||
|
||
template<typename T> | ||
class C4; | ||
} | ||
using N4::f4; | ||
using N4::x4; | ||
using N4::C4; | ||
} | ||
|
||
template<> | ||
void N3::f4<int>(); // expected-error {{no function template matches}} | ||
|
||
template<> | ||
int N3::x4<int>; | ||
|
||
template<> | ||
class N3::C4<int>; | ||
|
||
inline namespace N5 { | ||
template<typename T> | ||
void f5(); | ||
|
||
template<typename T> | ||
int x5 = 0; | ||
|
||
template<typename T> | ||
class C5; | ||
} | ||
|
||
template<> | ||
void f5<int>(); | ||
|
||
template<> | ||
int x5<int>; | ||
|
||
template<> | ||
class C5<int>; | ||
|
||
namespace N6 { | ||
inline namespace N7 { | ||
template<typename T> | ||
void f7(); | ||
|
||
template<typename T> | ||
int x7 = 0; | ||
|
||
template<typename T> | ||
class C7; | ||
} | ||
} | ||
|
||
template<> | ||
void N6::f7<int>(); | ||
|
||
template<> | ||
int N6::x7<int>; | ||
|
||
template<> | ||
class N6::C7<int>; |