Consider the following:
```
struct A {
static constexpr bool x = true;
};
template<typename T, typename U>
void f(T, U) noexcept(T::y); // #1, error: no member named 'y' in 'A'
template<typename T, typename U>
void f(T, U*) noexcept(T::x); // #2
template<>
void f(A, int*) noexcept; // explicit specialization of #2
```
We currently instantiate the exception specification of all candidate
function template specializations when deducting template arguments for
an explicit specialization, which results in a error despite `#1` not
being selected by partial ordering as the most specialized template.
According to [except.spec] p13:
> An exception specification is considered to be needed when:
> - [...]
> - the exception specification is compared to that of another
declaration (e.g., an explicit specialization or an overriding virtual
function);
Assuming that "comparing declarations" means "determining whether the
declarations correspond and declare the same entity" (per [basic.scope.scope] p4 and
[basic.link] p11.1, respectively), the exception specification does _not_ need to be
instantiated until _after_ partial ordering, at which point we determine
whether the implicitly instantiated specialization and the explicit
specialization declare the same entity (the determination of whether two
functions/function templates correspond does not consider the exception
specifications).
This patch defers the instantiation of the exception specification until
a single function template specialization is selected via partial
ordering, matching the behavior of GCC, EDG, and
MSVC: see https://godbolt.org/z/Ebb6GTcWE.
21 lines
465 B
C++
21 lines
465 B
C++
// RUN: %clang_cc1 -verify %s
|
|
// RUN: %clang_cc1 -std=c++11 -verify %s
|
|
// RUN: %clang_cc1 -std=c++17 -verify %s
|
|
// RUN: %clang_cc1 -std=c++1z -verify %s
|
|
|
|
class A {
|
|
public:
|
|
static const char X;
|
|
};
|
|
const char A::X = 0;
|
|
|
|
template<typename U> void func() noexcept(U::X);
|
|
|
|
template<class... B, char x>
|
|
void foo(void(B...) noexcept(x)) {} // expected-note{{candidate template ignored}}
|
|
|
|
void bar()
|
|
{
|
|
foo(func<A>); // expected-error{{no matching function for call}}
|
|
}
|