2009-03-24 10:24:46 +08:00
|
|
|
// RUN: clang-cc -fsyntax-only -verify %s
|
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.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
|
|
|
|
namespace N {
|
|
|
|
namespace M {
|
|
|
|
template<typename T> struct Promote; // expected-note{{previous definition is here}}
|
|
|
|
|
|
|
|
template<> struct Promote<short> {
|
|
|
|
typedef int type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct Promote<int> {
|
|
|
|
typedef int type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct Promote<float> {
|
|
|
|
typedef double type;
|
|
|
|
};
|
|
|
|
|
|
|
|
Promote<short>::type *ret_intptr(int* ip) { return ip; }
|
|
|
|
Promote<int>::type *ret_intptr2(int* ip) { return ip; }
|
|
|
|
}
|
|
|
|
|
|
|
|
M::Promote<int>::type *ret_intptr3(int* ip) { return ip; }
|
|
|
|
M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; }
|
|
|
|
}
|
|
|
|
|
|
|
|
N::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; }
|
|
|
|
::N::M::Promote<int>::type *ret_intptr6(int* ip) { return ip; }
|
|
|
|
|
|
|
|
|
|
|
|
N::M::template; // expected-error{{expected template name after 'template' keyword in nested name specifier}} \
|
|
|
|
// expected-error{{expected unqualified-id}}
|
|
|
|
|
|
|
|
N::M::template Promote; // expected-error{{expected '<' after 'template Promote' in nested name specifier}} \
|
|
|
|
// expected-error{{C++ requires a type specifier for all declarations}} \
|
2009-03-12 07:52:16 +08:00
|
|
|
// expected-error{{redefinition of 'Promote' as different kind of symbol}}
|
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.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
|
|
|
|
namespace N {
|
|
|
|
template<typename T> struct A;
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct A<int> {
|
|
|
|
struct X;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ::N::A<int>::X {
|
|
|
|
int foo;
|
|
|
|
};
|