From: David Blaikie Date: Fri, 19 Apr 2019 23:04:05 +0000 (+0000) Subject: Modules: Adopt template parameters for variable templates to set their decl context... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ea610150278dfee115dd86b3aafe24c5ce9c2042;p=clang Modules: Adopt template parameters for variable templates to set their decl context correctly Exposed by a related bug about visibility of default arguments of nested templates - without the correct decl context, default template parameters of variable templates nested in classes would have incorrect visibility computed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358796 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index 2055c799e7..592258d3ff 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -956,6 +956,7 @@ VarTemplateDecl *VarTemplateDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, VarDecl *Decl) { + AdoptTemplateParameterList(Params, DC); return new (C, DC) VarTemplateDecl(C, DC, L, Name, Params, Decl); } diff --git a/test/Modules/nested-template-default-arg-redecl.cpp b/test/Modules/nested-template-default-arg-redecl.cpp index 3baa202262..55568f8711 100644 --- a/test/Modules/nested-template-default-arg-redecl.cpp +++ b/test/Modules/nested-template-default-arg-redecl.cpp @@ -1,18 +1,16 @@ // RUN: rm -rf %t // RUN: %clang_cc1 -x c++ -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \ // RUN: -I %S/Inputs/nested-template-default-arg-redecl -std=c++14 \ -// RUN: -fmodules-local-submodule-visibility -verify %s +// RUN: -fmodules-local-submodule-visibility -w -verify %s + +// expected-no-diagnostics + #include "alias2.h" #include "var2.h" #include "strct2.h" #include "func2.h" -// FIXME: Variable templates lexical decl context appears to be the translation -// unit, which is incorrect. Fixing this will hopefully address the following -// error/bug: - -// expected-note@Inputs/nested-template-default-arg-redecl/var.h:4 {{default argument declared here}} -auto var = &var_outer::var<>; // expected-error {{default argument of 'var' must be imported from module 'VAR1' before it is required}} +auto var = &var_outer::var<>; auto func = &func_outer::func<>; strct_outer::strct<> *strct; alias_outer::alias<> *alias;