]> granicus.if.org Git - clang/commitdiff
Attach class template attributes to the templated CXXRecordDecl,
authorPeter Collingbourne <peter@pcc.me.uk>
Sun, 23 Oct 2011 17:07:16 +0000 (17:07 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Sun, 23 Oct 2011 17:07:16 +0000 (17:07 +0000)
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

lib/Sema/SemaDecl.cpp
test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp
test/SemaCXX/attr-cxx0x.cpp

index 289ec1a6f6fb22725402e137d59fd3d8ea353825..2241024ba4dbed6219404087504895a37ebf65da 100644 (file)
@@ -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<TagDecl>(TagD);
+    if (isa<TagDecl>(TagD))
+      Tag = cast<TagDecl>(TagD);
+    else if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(TagD))
+      Tag = CTD->getTemplatedDecl();
   }
 
   if (Tag)
index ed98c1e9c56d3a56aba27408904603bc89dcb59d..bd7a5f33fd38c6caa8ab07dc716b1de82a40d492 100644 (file)
@@ -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 <typename T> constexpr class TC1 {}; // expected-error {{class cannot be marked constexpr}}
+template <typename T> constexpr struct TS1 {}; // expected-error {{struct cannot be marked constexpr}}
+template <typename T> 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}}
index de9d7d1c2a6e9538c9c641820afa332b7e1c4565..5d02cfca343307af46c0ff324bbc401115d9f884 100644 (file)
@@ -9,6 +9,8 @@ struct align_member {
   int member alignas(8);
 };
 
+template <unsigned A> alignas(A) struct align_class_template {};
+
 typedef char align_typedef alignas(8);
 template<typename T> 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<int>) == 8, "alias template's alignment is wrong");