From: Peter Collingbourne Date: Sun, 23 Oct 2011 17:07:16 +0000 (+0000) Subject: Attach class template attributes to the templated CXXRecordDecl, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0661bd0ccae381613c5967cdf2514255e1f92636;p=clang Attach class template attributes to the templated CXXRecordDecl, instead of silently discarding them. As a side effect, this improves diagnostics for constexpr class templates slightly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142755 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 289ec1a6f6..2241024ba4 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2312,7 +2312,10 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, // Note that the above type specs guarantee that the // type rep is a Decl, whereas in many of the others // it's a Type. - Tag = dyn_cast(TagD); + if (isa(TagD)) + Tag = cast(TagD); + else if (ClassTemplateDecl *CTD = dyn_cast(TagD)) + Tag = CTD->getTemplatedDecl(); } if (Tag) diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp index ed98c1e9c5..bd7a5f33fd 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp @@ -35,6 +35,9 @@ constexpr class C1 {}; // expected-error {{class cannot be marked constexpr}} constexpr struct S1 {}; // expected-error {{struct cannot be marked constexpr}} constexpr union U1 {}; // expected-error {{union cannot be marked constexpr}} constexpr enum E1 {}; // expected-error {{enum cannot be marked constexpr}} +template constexpr class TC1 {}; // expected-error {{class cannot be marked constexpr}} +template constexpr struct TS1 {}; // expected-error {{struct cannot be marked constexpr}} +template constexpr union TU1 {}; // expected-error {{union cannot be marked constexpr}} class C2 {} constexpr; // expected-error {{class cannot be marked constexpr}} struct S2 {} constexpr; // expected-error {{struct cannot be marked constexpr}} union U2 {} constexpr; // expected-error {{union cannot be marked constexpr}} diff --git a/test/SemaCXX/attr-cxx0x.cpp b/test/SemaCXX/attr-cxx0x.cpp index de9d7d1c2a..5d02cfca34 100644 --- a/test/SemaCXX/attr-cxx0x.cpp +++ b/test/SemaCXX/attr-cxx0x.cpp @@ -9,6 +9,8 @@ struct align_member { int member alignas(8); }; +template alignas(A) struct align_class_template {}; + typedef char align_typedef alignas(8); template using align_alias_template = align_typedef; @@ -18,4 +20,6 @@ static_assert(alignof(align_multiple) == 8, "l's alignment is wrong"); static_assert(alignof(align_member) == 8, "quuux's alignment is wrong"); static_assert(sizeof(align_member) == 8, "quuux's size is wrong"); static_assert(alignof(align_typedef) == 8, "typedef's alignment is wrong"); +static_assert(alignof(align_class_template<8>) == 8, "template's alignment is wrong"); +static_assert(alignof(align_class_template<16>) == 16, "template's alignment is wrong"); static_assert(alignof(align_alias_template) == 8, "alias template's alignment is wrong");