2009-10-27 22:31:53 +08:00
|
|
|
// RUN: clang-cc -fsyntax-only -verify -fms-extensions=0 %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 {
|
2009-04-15 06:17:06 +08:00
|
|
|
template<typename T> struct Promote;
|
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
|
|
|
|
|
|
|
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}} \
|
2009-04-15 06:17:06 +08:00
|
|
|
// expected-error{{C++ requires a type specifier for all declarations}}
|
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;
|
|
|
|
};
|
2009-03-31 08:43:58 +08:00
|
|
|
|
|
|
|
struct B;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
struct ::N::A<int>::X {
|
|
|
|
int foo;
|
|
|
|
};
|
2009-03-31 08:43:58 +08:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
// FIXME: the following crashes the parser, because Sema has no way to
|
2009-04-02 05:51:26 +08:00
|
|
|
// communicate that the "dependent" template-name N::template B doesn't
|
2009-03-31 08:43:58 +08:00
|
|
|
// actually refer to a template.
|
|
|
|
template<typename T>
|
|
|
|
struct TestA {
|
|
|
|
typedef typename N::template B<T>::type type; // xpected-error{{'B' following the 'template' keyword does not refer to a template}}
|
|
|
|
// FIXME: should show what B *does* refer to.
|
|
|
|
};
|
|
|
|
#endif
|