Files
clang-p2996/clang/test/SemaTemplate/qualified-id.cpp
Krystian Stasiowski a0d266d705 [Clang][Sema] Allow elaborated-type-specifiers that declare member class template explict specializations (#78720)
According to [[dcl.type.elab]
p2](http://eel.is/c++draft/dcl.type.elab#2):
> If an
[elaborated-type-specifier](http://eel.is/c++draft/dcl.type.elab#nt:elaborated-type-specifier)
is the sole constituent of a declaration, the declaration is ill-formed
unless it is an explicit specialization, an explicit instantiation or it
has one of the following forms [...]

Consider the following:
```cpp
template<typename T>
struct A 
{
    template<typename U>
    struct B;
};

template<>
template<typename U>
struct A<int>::B; // #1
```
The _elaborated-type-specifier_ at `#1` declares an explicit
specialization (which is itself a template). We currently (incorrectly)
reject this, and this PR fixes that.

I moved the point at which _elaborated-type-specifiers_ with
_nested-name-specifiers_ are diagnosed from `ParsedFreeStandingDeclSpec`
to `ActOnTag` for two reasons: `ActOnTag` isn't called for explicit
instantiations and partial/explicit specializations, and because it's
where we determine if a member specialization is being declared.

With respect to diagnostics, I am currently issuing the diagnostic
without marking the declaration as invalid or returning early, which
results in more diagnostics that I think is necessary. I would like
feedback regarding what the "correct" behavior should be here.
2024-01-30 08:28:13 -05:00

58 lines
1.1 KiB
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
// PR5061
namespace a {
template <typename T> class C {};
}
namespace b {
template<typename T> void f0(a::C<T> &a0) { }
}
namespace test1 {
int a = 0;
template <class T> class Base { };
template <class T> class Derived : public Base<T> {
int foo() {
return test1::a;
}
};
}
namespace test2 {
class Impl {
public:
int foo();
};
template <class T> class Magic : public Impl {
int foo() {
return Impl::foo();
}
};
}
namespace PR6063 {
template <typename T> void f(T, T);
namespace detail
{
using PR6063::f;
}
template <typename T>
void g(T a, T b)
{
detail::f(a, b);
}
}
namespace PR12291 {
template <typename T>
class Outer2 {
template <typename V>
template <typename W>
class Outer2<V>::Inner; // expected-error{{nested name specifier 'Outer2<V>::' for declaration does not refer into a class, class template or class template partial specialization}}
// expected-error@-1{{forward declaration of class cannot have a nested name specifier}}
};
}