From: David Majnemer Date: Sun, 28 Dec 2014 22:51:45 +0000 (+0000) Subject: Sema: Variable templates cannot be static bitfield members X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e55333eafbdf7ad54c78ae3910b3fd7e3929e8f;p=clang Sema: Variable templates cannot be static bitfield members We correctly forbid variables but not variable templates. Diagnose this case instead of crashing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224905 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 5737901ec6..a57a9206fb 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2164,7 +2164,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, if (BitWidth) { if (Member->isInvalidDecl()) { // don't emit another diagnostic. - } else if (isa(Member)) { + } else if (isa(Member) || isa(Member)) { // C++ 9.6p3: A bit-field shall not be a static member. // "static member 'A' cannot be a bit-field" Diag(Loc, diag::err_static_not_bitfield) diff --git a/test/SemaCXX/cxx1y-variable-templates_in_class.cpp b/test/SemaCXX/cxx1y-variable-templates_in_class.cpp index f6f77f0100..93a2095c9b 100644 --- a/test/SemaCXX/cxx1y-variable-templates_in_class.cpp +++ b/test/SemaCXX/cxx1y-variable-templates_in_class.cpp @@ -321,3 +321,9 @@ namespace in_nested_classes { // TODO: } +namespace bitfield { +struct S { + template + static int f : I; // expected-error {{static member 'f' cannot be a bit-field}} +}; +}