]> granicus.if.org Git - clang/commitdiff
PR9908: Fix the broken fix for PR9902 to get the template argument lists in the right...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 14 May 2011 15:04:18 +0000 (15:04 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 14 May 2011 15:04:18 +0000 (15:04 +0000)
Also, don't reject alias templates in all ElaboratedTypes: some ElaboratedTypes do not correspond to elaborated-type-specifiers.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131342 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplate.cpp
lib/Sema/TreeTransform.h
test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp
test/SemaCXX/PR9908.cpp [new file with mode: 0644]
test/SemaTemplate/alias-templates.cpp [new file with mode: 0644]

index 58c12d4c754b542f04449d2dbf0a47888ebd461e..c31ed017377ccd43dcf4c66f826c73ea389ac220 100644 (file)
@@ -1859,10 +1859,10 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 
     // Only substitute for the innermost template argument list.
     MultiLevelTemplateArgumentList TemplateArgLists;
+    TemplateArgLists.addOuterTemplateArguments(&TemplateArgs);
     unsigned Depth = AliasTemplate->getTemplateParameters()->getDepth();
     for (unsigned I = 0; I < Depth; ++I)
       TemplateArgLists.addOuterTemplateArguments(0, 0);
-    TemplateArgLists.addOuterTemplateArguments(&TemplateArgs);
 
     InstantiatingTemplate Inst(*this, TemplateLoc, Template);
     CanonType = SubstType(Pattern->getUnderlyingType(),
index c45d02a56c6d3c00772164b46370cba29d9933e6..e007f062356a0b223f03286523a4525d830507f9 100644 (file)
@@ -4504,14 +4504,16 @@ TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
   //   If the identifier resolves to a typedef-name or the simple-template-id
   //   resolves to an alias template specialization, the
   //   elaborated-type-specifier is ill-formed.
-  if (const TemplateSpecializationType *TST =
-        NamedT->getAs<TemplateSpecializationType>()) {
-    TemplateName Template = TST->getTemplateName();
-    if (TypeAliasTemplateDecl *TAT =
-        dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
-      SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
-                   diag::err_tag_reference_non_tag) << 4;
-      SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
+  if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
+    if (const TemplateSpecializationType *TST =
+          NamedT->getAs<TemplateSpecializationType>()) {
+      TemplateName Template = TST->getTemplateName();
+      if (TypeAliasTemplateDecl *TAT =
+          dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
+        SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
+                     diag::err_tag_reference_non_tag) << 4;
+        SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
+      }
     }
   }
 
index 5fc0fe0411cf84fc1ff3cd70f2dd248515c77cc7..81204d89a697fca97dff6392b07d601b4b994b96 100644 (file)
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
 
-struct A { };
+struct A { typedef int type; };
 template<typename T> using X = A; // expected-note {{declared here}}
 struct X<int>* p2; // expected-error {{elaborated type refers to a type alias template}}
 
@@ -9,5 +9,11 @@ template<typename T> using Id = T; // expected-note {{declared here}}
 template<template<typename> class F>
 struct Y {
   struct F<int> i; // expected-error {{elaborated type refers to a type alias template}}
+  typename F<A>::type j; // ok
+
+  // FIXME: don't produce the diagnostic both for the definition and the instantiation.
+  template<typename T> using U = F<char>; // expected-note 2{{declared here}}
+  struct Y<F>::template U<char> k; // expected-error 2{{elaborated type refers to a type alias template}}
+  typename Y<F>::template U<char> l; // ok
 };
 template struct Y<Id>; // expected-note {{requested here}}
diff --git a/test/SemaCXX/PR9908.cpp b/test/SemaCXX/PR9908.cpp
new file mode 100644 (file)
index 0000000..3b98b72
--- /dev/null
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s
+
+template <class _Tp, class _Up>
+struct __allocator_traits_rebind
+{
+    typedef typename _Tp::template rebind<_Up>::other type;
+};
+
+template <class Alloc>
+struct allocator_traits
+{
+    typedef Alloc allocator_type;
+    template <class T> using rebind_alloc = typename
+__allocator_traits_rebind<allocator_type, T>::type;
+    template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
+};
+
+template <class T>
+struct ReboundA {};
+
+template <class T>
+struct A
+{
+    typedef T value_type;
+
+    template <class U> struct rebind {typedef ReboundA<U> other;};
+};
+
+int main()
+{
+    allocator_traits<A<char> >::rebind_traits<double> a;
+}
diff --git a/test/SemaTemplate/alias-templates.cpp b/test/SemaTemplate/alias-templates.cpp
new file mode 100644 (file)
index 0000000..f4c917c
--- /dev/null
@@ -0,0 +1,70 @@
+// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
+
+template<typename S>
+struct A {
+  typedef S B;
+  template<typename T> using C = typename T::B;
+  template<typename T> struct D {
+    template<typename U> using E = typename A<U>::template C<A<T>>;
+    template<typename U> using F = A<E<U>>;
+    template<typename U> using G = C<F<U>>;
+    G<T> g;
+  };
+  typedef decltype(D<B>().g) H;
+  D<H> h;
+  template<typename T> using I = A<decltype(h.g)>;
+  template<typename T> using J = typename A<decltype(h.g)>::template C<I<T>>;
+};
+
+A<int> a;
+A<char>::D<double> b;
+
+template<typename T> T make();
+
+namespace X {
+  template<typename T> struct traits {
+    typedef T thing;
+    typedef decltype(val(make<thing>())) inner_ptr;
+
+    template<typename U> using rebind_thing = typename thing::template rebind<U>;
+    template<typename U> using rebind = traits<rebind_thing<U>>;
+
+    inner_ptr &&alloc();
+    void free(inner_ptr&&);
+  };
+
+  template<typename T> struct ptr_traits {
+    typedef T *type;
+  };
+  template<typename T> using ptr = typename ptr_traits<T>::type;
+
+  template<typename T> struct thing {
+    typedef T inner;
+    typedef ptr<inner> inner_ptr;
+    typedef traits<thing<inner>> traits_type;
+
+    template<typename U> using rebind = thing<U>;
+
+    thing(traits_type &traits) : traits(traits), val(traits.alloc()) {}
+    ~thing() { traits.free(static_cast<inner_ptr&&>(val)); }
+
+    traits_type &traits;
+    inner_ptr val;
+
+    friend inner_ptr val(const thing &t) { return t.val; }
+  };
+
+  template<> struct ptr_traits<bool> {
+    typedef bool &type;
+  };
+  template<> bool &traits<thing<bool>>::alloc() { static bool b; return b; }
+  template<> void traits<thing<bool>>::free(bool&) {}
+}
+
+typedef X::traits<X::thing<int>> itt;
+
+itt::thing::traits_type itr;
+itt::thing ith(itr);
+
+itt::rebind<bool> btr;
+itt::rebind_thing<bool> btt(btr);