2009-03-24 10:24:46 +08:00
|
|
|
// RUN: clang-cc -fsyntax-only %s
|
Introduce a new expression type, UnresolvedDeclRefExpr, that describes
dependent qualified-ids such as
Fibonacci<N - 1>::value
where N is a template parameter. These references are "unresolved"
because the name is dependent and, therefore, cannot be resolved to a
declaration node (as we would do for a DeclRefExpr or
QualifiedDeclRefExpr). UnresolvedDeclRefExprs instantiate to
DeclRefExprs, QualifiedDeclRefExprs, etc.
Also, be a bit more careful about keeping only a single set of
specializations for a class template, and instantiating from the
definition of that template rather than a previous declaration. In
general, we need a better solution for this for all TagDecls, because
it's too easy to accidentally look at a declaration that isn't the
definition.
We can now process a simple Fibonacci computation described as a
template metaprogram.
llvm-svn: 67308
2009-03-20 01:26:29 +08:00
|
|
|
|
|
|
|
// FIXME: The Fibonacci/FibonacciEval dance is here to work around our
|
|
|
|
// inability to parse injected-class-name<template-argument-list>.
|
|
|
|
template<unsigned I>
|
|
|
|
struct FibonacciEval;
|
|
|
|
|
|
|
|
template<unsigned I>
|
|
|
|
struct Fibonacci {
|
|
|
|
enum { value = FibonacciEval<I-1>::value + FibonacciEval<I-2>::value };
|
|
|
|
};
|
|
|
|
|
|
|
|
template<unsigned I>
|
|
|
|
struct FibonacciEval {
|
|
|
|
enum { value = Fibonacci<I>::value };
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct Fibonacci<0> {
|
|
|
|
enum { value = 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct Fibonacci<1> {
|
|
|
|
enum { value = 1 };
|
|
|
|
};
|
|
|
|
|
|
|
|
int array5[Fibonacci<5>::value == 5? 1 : -1];
|
|
|
|
int array10[Fibonacci<10>::value == 55? 1 : -1];
|