diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-03-04 17:52:15 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-03-04 17:52:15 +0000 |
commit | fd7c225530b0c42e95bf5f9c22314a4479748cf9 (patch) | |
tree | c00bf5a0af33a4ec5080cbe28203308df0ef2eb4 /clang/test/SemaTemplate/issue150.cpp | |
parent | ed874eff9377c85ad8686fcbc4f9b2303cc646ee (diff) | |
download | bcm5719-llvm-fd7c225530b0c42e95bf5f9c22314a4479748cf9.tar.gz bcm5719-llvm-fd7c225530b0c42e95bf5f9c22314a4479748cf9.zip |
Make sure to put template parameters into their owning template's
DeclContext once we've created it. This mirrors what we do for
function parameters, where the parameters start out with
translation-unit context and then are adopted by the appropriate
DeclContext when it is created. Also give template parameters public
access and make sure that they don't show up for the purposes of name
lookup.
Fixes PR9400, a regression introduced by r126920, which implemented
substitution of default template arguments provided in template
template parameters (C++ core issue 150).
How on earth could the DeclContext of a template parameter affect the
handling of default template arguments?
I'm so glad you asked! The link is
Sema::getTemplateInstantiationArgs(), which determines the outer
template argument lists that correspond to a given declaration. When
we're instantiating a default template argument for a template
template parameter within the body of a template definition (not it's
instantiation, per core issue 150), we weren't getting any outer
template arguments because the context of the template template
parameter was the translation unit. Now that the context of the
template template parameter is its owning template, we get the
template arguments from the injected-class-name of the owning
template, so substitution works as it should.
llvm-svn: 127004
Diffstat (limited to 'clang/test/SemaTemplate/issue150.cpp')
-rw-r--r-- | clang/test/SemaTemplate/issue150.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/clang/test/SemaTemplate/issue150.cpp b/clang/test/SemaTemplate/issue150.cpp index 647df2cc0b7..0d7930723fc 100644 --- a/clang/test/SemaTemplate/issue150.cpp +++ b/clang/test/SemaTemplate/issue150.cpp @@ -2,6 +2,16 @@ // Core issue 150: Template template parameters and default arguments +template<typename T, typename U> +struct is_same { + static const bool value = false; +}; + +template<typename T> +struct is_same<T, T> { + static const bool value = true; +}; + namespace PR9353 { template<class _T, class Traits> class IM; @@ -11,3 +21,51 @@ namespace PR9353 { void f(IM<int, int>* m) { foo(m); } } + +namespace PR9400 { + template<template <typename T, typename = T > class U> struct A + { + template<int> U<int> foo(); + }; + + template <typename T, typename = T> + struct s { + }; + + void f() { + A<s> x; + x.foo<2>(); + } +} + +namespace MultiReplace { + template<typename Z, + template<typename T, typename U = T *, typename V = U const> class TT> + struct X { + typedef TT<Z> type; + }; + + template<typename T, typename = int, typename = float> + struct Y { }; + + int check0[is_same<X<int, Y>::type, Y<int, int*, int* const> >::value? 1 : -1]; +} + +namespace MultiReplacePartial { + template<typename First, typename Z, + template<typename T, typename U = T *, typename V = U const> class TT> + struct X { + typedef TT<Z> type; + }; + + template<typename Z, + template<typename T, typename U = T *, typename V = U const> class TT> + struct X<int, Z, TT> { + typedef TT<Z> type; + }; + + template<typename T, typename = int, typename = float> + struct Y { }; + + int check0[is_same<X<int, int, Y>::type, Y<int, int*, int* const> >::value? 1 : -1]; +} |