Author: mattd Date: Mon Nov 5 09:25:26 2018 New Revision: 346146 URL: http://llvm.org/viewvc/llvm-project?rev=346146&view=rev Log: [AST] Get aliased type info from an aliased TemplateSpecialization.
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 Modified: cfe/trunk/include/clang/AST/Type.h cfe/trunk/test/SemaCXX/alignof.cpp Modified: cfe/trunk/include/clang/AST/Type.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=346146&r1=346145&r2=346146&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/Type.h (original) +++ cfe/trunk/include/clang/AST/Type.h Mon Nov 5 09:25:26 2018 @@ -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); Modified: cfe/trunk/test/SemaCXX/alignof.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/alignof.cpp?rev=346146&r1=346145&r2=346146&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/alignof.cpp (original) +++ cfe/trunk/test/SemaCXX/alignof.cpp Mon Nov 5 09:25:26 2018 @@ -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" ); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits