From: Richard Smith Date: Mon, 25 Nov 2013 21:30:29 +0000 (+0000) Subject: PR18044: Reject declarations of enumtype::X early to avoid an assertion in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7ca1ee4db7b48b86f96307f663fd8f13b022bd5;p=clang PR18044: Reject declarations of enumtype::X early to avoid an assertion in downstream code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195687 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 6d5e0f0126..8229a6224a 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4224,7 +4224,7 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D, bool EnteringContext = !D.getDeclSpec().isFriendSpecified(); DC = computeDeclContext(D.getCXXScopeSpec(), EnteringContext); - if (!DC) { + if (!DC || isa(DC)) { // If we could not compute the declaration context, it's because the // declaration context is dependent but does not refer to a class, // class template, or class template partial specialization. Complain diff --git a/test/SemaCXX/enum-scoped.cpp b/test/SemaCXX/enum-scoped.cpp index c6869449ca..b4aad18b17 100644 --- a/test/SemaCXX/enum-scoped.cpp +++ b/test/SemaCXX/enum-scoped.cpp @@ -282,3 +282,17 @@ namespace rdar15124329 { static_assert(T2 == B::T, ""); } +namespace PR18044 { + enum class E { a }; + + int E::e = 0; // expected-error {{does not refer into a class}} + void E::f() {} // expected-error {{does not refer into a class}} + struct E::S {}; // expected-error {{no struct named 'S'}} + struct T : E::S {}; // expected-error {{expected class name}} + enum E::E {}; // expected-error {{no enum named 'E'}} + int E::*p; // expected-error {{does not point into a class}} + using E::f; // expected-error {{no member named 'f'}} + + using E::a; // ok! + E b = a; +}