-
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] Implement proposed resolution for CWG2847 (#80899)
Per the approved resolution for CWG2847, [temp.expl.spec] p8 will state: > An explicit specialization shall not have a trailing _requires-clause_ unless it declares a function template. We already implement this _partially_ insofar that a diagnostic is issued upon instantiation of `A<int>` in the following example: ``` template<typename> struct A { template<typename> void f(); template<> void f<int>() requires true; // error: non-templated function cannot have a requires clause }; template struct A<int>; // note: in instantiation of template class 'A<int>' requested here ``` This patch adds a bespoke diagnostic for such declarations, and moves the point of diagnosis for non-templated functions with trailing requires-clauses from `CheckFunctionDeclaration` to `ActOnFunctionDeclarator` (there is no point in diagnosing this during instantiation since we already have all the necessary information when parsing the declaration).
- Loading branch information
1 parent
3a05e01
commit 51a3019
Showing
3 changed files
with
117 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// RUN: %clang_cc1 -std=c++98 -verify=expected %s | ||
// RUN: %clang_cc1 -std=c++11 -verify=expected %s | ||
// RUN: %clang_cc1 -std=c++14 -verify=expected %s | ||
// RUN: %clang_cc1 -std=c++17 -verify=expected %s | ||
// RUN: %clang_cc1 -std=c++20 -verify=expected,since-cxx20 %s | ||
// RUN: %clang_cc1 -std=c++23 -verify=expected,since-cxx20,since-cxx23 %s | ||
// RUN: %clang_cc1 -std=c++2c -verify=expected,since-cxx20,since-cxx23,since-cxx26 %s | ||
|
||
#if __cplusplus < 202002L | ||
// expected-no-diagnostics | ||
#endif | ||
|
||
namespace dr2847 { // dr2847: 19 | ||
|
||
#if __cplusplus >= 202002L | ||
|
||
template<typename> | ||
void i(); | ||
|
||
struct A { | ||
template<typename> | ||
void f() requires true; | ||
|
||
template<> | ||
void f<int>() requires true; | ||
// since-cxx20-error@-1 {{explicit specialization cannot have a trailing requires clause unless it declares a function template}} | ||
|
||
friend void i<int>() requires true; | ||
// since-cxx20-error@-1 {{friend specialization cannot have a trailing requires clause unless it declares a function template}} | ||
}; | ||
|
||
template<typename> | ||
struct B { | ||
void f() requires true; | ||
|
||
template<typename> | ||
void g() requires true; | ||
|
||
template<typename> | ||
void h() requires true; | ||
|
||
template<> | ||
void h<int>() requires true; | ||
// since-cxx20-error@-1 {{explicit specialization cannot have a trailing requires clause unless it declares a function template}} | ||
|
||
friend void i<int>() requires true; | ||
// since-cxx20-error@-1 {{friend specialization cannot have a trailing requires clause unless it declares a function template}} | ||
}; | ||
|
||
template<> | ||
void B<int>::f() requires true; | ||
// since-cxx20-error@-1 {{explicit specialization cannot have a trailing requires clause unless it declares a function template}} | ||
|
||
template<> | ||
template<typename T> | ||
void B<int>::g() requires true; | ||
|
||
#endif | ||
|
||
} // namespace dr2847 |