2009-02-18 02:15:12 +03:00
|
|
|
// RUN: clang -fsyntax-only -verify %s
|
|
|
|
template<typename T, typename U = int> class A;
|
|
|
|
|
|
|
|
template<> class A<double, double>; // expected-note{{forward declaration}}
|
|
|
|
|
|
|
|
template<> class A<float, float> { // expected-note{{previous definition}}
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> class A<float> { // expected-note{{previous definition}}
|
|
|
|
int y;
|
|
|
|
};
|
|
|
|
|
|
|
|
int test_specs(A<float, float> *a1, A<float, int> *a2) {
|
|
|
|
return a1->x + a2->y;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_incomplete_specs(A<double, double> *a1,
|
|
|
|
A<double> *a2) // FIXME: expected-note{{forward declaration}}
|
|
|
|
{
|
|
|
|
(void)a1->x; // expected-error{{incomplete definition of type 'A<double, double>'}}
|
|
|
|
(void)a2->x; // expected-error{{incomplete definition of type 'A<double>'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef float FLOAT;
|
|
|
|
|
|
|
|
template<> class A<float, FLOAT>;
|
|
|
|
|
|
|
|
template<> class A<FLOAT, float> { }; // expected-error{{redefinition}}
|
|
|
|
|
|
|
|
template<> class A<float, int> { }; // expected-error{{redefinition}}
|
2009-02-19 03:52:42 +03:00
|
|
|
|
|
|
|
template<typename T, typename U = int> class X;
|
|
|
|
|
|
|
|
template <> class X<int, int> { int foo(); }; // #1
|
|
|
|
template <> class X<float> { int bar(); }; // #2
|
|
|
|
|
|
|
|
typedef int int_type;
|
|
|
|
void testme(X<int_type> *x1, X<float, int> *x2) {
|
|
|
|
x1->foo(); // okay: refers to #1
|
|
|
|
x2->bar(); // okay: refers to #2
|
|
|
|
}
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65467 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-25 22:37:18 +03:00
|
|
|
|
2009-02-25 22:48:02 +03:00
|
|
|
// Diagnose specializations in a different namespace
|
|
|
|
class A<double> { };
|