]> granicus.if.org Git - clang/commitdiff
[AST] Get aliased type info from an aliased TemplateSpecialization.
authorMatt Davis <Matthew.Davis@sony.com>
Mon, 5 Nov 2018 17:25:26 +0000 (17:25 +0000)
committerMatt Davis <Matthew.Davis@sony.com>
Mon, 5 Nov 2018 17:25:26 +0000 (17:25 +0000)
Summary:
Previously the TemplateSpecialization instance for 'template_alias', in the example below, returned the type info of the  canonical type (int).  This ignored the type alias if the template type happen to be aliased.

Before this patch, the assert would trigger with an  alignment of 4:
```
typedef int __attribute__(( aligned( 16 ) )) aligned_int;
template < typename >
using template_alias = aligned_int;
static_assert( alignof( template_alias<void>) == 16, "" );
```

This patch checks if the TemplateSpecialization type has an alias, and if so will return the type information for the aliased type, else the canonical type's info is returned (original behavior).  I believe that this is the desired behavior.

Reviewers: aaron.ballman, rjmccall

Reviewed By: rjmccall

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D54048

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

include/clang/AST/Type.h
test/SemaCXX/alignof.cpp

index cbcce8832e71eb97b3825ef7dc2afbb45c957ad5..f69e1172ace19f835ae56ec187123a256ee5bf22 100644 (file)
@@ -4901,7 +4901,9 @@ public:
     return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
   }
 
-  QualType desugar() const { return getCanonicalTypeInternal(); }
+  QualType desugar() const {
+    return isTypeAlias() ? getAliasedType() : getCanonicalTypeInternal();
+  }
 
   void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
     Profile(ID, Template, template_arguments(), Ctx);
index 2895cb9d46c7643d071e0f3a0218355a7ff72f1c..f2854024da1acfaccc7b1588db342ad74be91327 100644 (file)
@@ -97,3 +97,8 @@ struct S {
   typedef __attribute__((aligned(N))) int Field[sizeof(N)]; // expected-error {{requested alignment is dependent but declaration is not dependent}}
 };
 }
+
+typedef int __attribute__((aligned(16))) aligned_int;
+template <typename>
+using template_alias = aligned_int;
+static_assert(alignof(template_alias<void>) == 16, "Expected alignment of 16" );