[cfe-commits] r131342 - in /cfe/trunk: 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 test/SemaTemplate/alias-templates.cpp

Richard Smith richard-llvm at metafoo.co.uk
Sat May 14 08:04:19 PDT 2011


Author: rsmith
Date: Sat May 14 10:04:18 2011
New Revision: 131342

URL: http://llvm.org/viewvc/llvm-project?rev=131342&view=rev
Log:
PR9908: Fix the broken fix for PR9902 to get the template argument lists in the right order.
Also, don't reject alias templates in all ElaboratedTypes: some ElaboratedTypes do not correspond to elaborated-type-specifiers.


Added:
    cfe/trunk/test/SemaCXX/PR9908.cpp
    cfe/trunk/test/SemaTemplate/alias-templates.cpp
Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=131342&r1=131341&r2=131342&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Sat May 14 10:04:18 2011
@@ -1859,10 +1859,10 @@
 
     // 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(),

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=131342&r1=131341&r2=131342&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Sat May 14 10:04:18 2011
@@ -4504,14 +4504,16 @@
   //   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);
+      }
     }
   }
 

Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp?rev=131342&r1=131341&r2=131342&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp Sat May 14 10:04:18 2011
@@ -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<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}}

Added: cfe/trunk/test/SemaCXX/PR9908.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR9908.cpp?rev=131342&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/PR9908.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR9908.cpp Sat May 14 10:04:18 2011
@@ -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;
+}

Added: cfe/trunk/test/SemaTemplate/alias-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/alias-templates.cpp?rev=131342&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/alias-templates.cpp (added)
+++ cfe/trunk/test/SemaTemplate/alias-templates.cpp Sat May 14 10:04:18 2011
@@ -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);





More information about the cfe-commits mailing list