[PATCH] -fdelayed-template-parsing: handle cases where a late-parsed function is not a direct member of a template, but rather nested inside a class that's a member of a template (PR19613)

Nico Weber thakis at chromium.org
Tue Apr 29 20:05:16 PDT 2014


On Tue, Apr 29, 2014 at 6:05 PM, Hans Wennborg <hans at chromium.org> wrote:
> Hi rnk, majnemer,
>
> This patch seems to fix the problem. Please take a look.
>
> http://reviews.llvm.org/D3555
>
> Files:
>   lib/Parse/ParseTemplate.cpp
>   test/Parser/DelayedTemplateParsing.cpp
>
> Index: lib/Parse/ParseTemplate.cpp
> ===================================================================
> --- lib/Parse/ParseTemplate.cpp
> +++ lib/Parse/ParseTemplate.cpp
> @@ -1255,15 +1255,23 @@
>            new ParseScope(this, Scope::TemplateParamScope));
>        Actions.ActOnReenterTemplateScope(getCurScope(), MD);
>        ++CurTemplateDepthTracker;
> -    } else if (CXXRecordDecl *MD = dyn_cast_or_null<CXXRecordDecl>(*II)) {
> -      bool IsClassTemplate = MD->getDescribedClassTemplate() != 0;
> +    } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(*II)) {
> +      ClassTemplateDecl *CTD = RD->getDescribedClassTemplate();
> +
> +      if (!CTD) {
> +        if (CXXRecordDecl *Parent = dyn_cast<CXXRecordDecl>(RD->getParent()))

Is a single if enough here? Could there be more than one nesting level?

> +          CTD = Parent->getDescribedClassTemplate();
> +      }
> +
> +      bool IsClassTemplate = CTD != 0;
>        TemplateParamScopeStack.push_back(
>            new ParseScope(this, Scope::TemplateParamScope,
> -                        /*ManageScope*/IsClassTemplate));
> -      Actions.ActOnReenterTemplateScope(getCurScope(),
> -                                        MD->getDescribedClassTemplate());
> -      if (IsClassTemplate)
> +                        /*EnteredScope*/IsClassTemplate));
> +
> +      if (IsClassTemplate) {
> +        Actions.ActOnReenterTemplateScope(getCurScope(), CTD);
>          ++CurTemplateDepthTracker;
> +      }
>      }
>      TemplateParamScopeStack.push_back(new ParseScope(this, Scope::DeclScope));
>      Actions.PushDeclContext(Actions.getCurScope(), *II);
> Index: test/Parser/DelayedTemplateParsing.cpp
> ===================================================================
> --- test/Parser/DelayedTemplateParsing.cpp
> +++ test/Parser/DelayedTemplateParsing.cpp
> @@ -123,3 +123,31 @@
>
>  template <typename T>
>  auto invalidTrailingRetType() -> Bogus {} // expected-error {{unknown type name 'Bogus'}}
> +
> +namespace PR19613 {
> +
> +struct HeapTypeConfig {
> +  static void from_bitset();
> +};
> +
> +template <class Config>
> +struct TypeImpl  {
> +  struct BitsetType;
> +
> +  static void Any() {
> +    BitsetType::New();
> +  }
> +};
> +
> +template<class Config>
> +struct TypeImpl<Config>::BitsetType {
> +  static void New() {
> +    Config::from_bitset();
> +  }
> +};
> +
> +static void f() {
> +  TypeImpl<HeapTypeConfig>::Any();
> +}
> +
> +}
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list