From: Richard Smith Date: Wed, 10 Jun 2015 20:36:34 +0000 (+0000) Subject: [modules] Don't allow use of non-visible (inherited) default template arguments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8e0f18d53b80631ecd2369991866700ce912c998;p=clang [modules] Don't allow use of non-visible (inherited) default template arguments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239487 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 6bb4be1d18..9a15411122 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -3299,7 +3299,7 @@ Sema::SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, HasDefaultArg = false; if (TemplateTypeParmDecl *TypeParm = dyn_cast(Param)) { - if (!TypeParm->hasDefaultArgument()) + if (!hasVisibleDefaultArgument(TypeParm)) return TemplateArgumentLoc(); HasDefaultArg = true; @@ -3316,7 +3316,7 @@ Sema::SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, if (NonTypeTemplateParmDecl *NonTypeParm = dyn_cast(Param)) { - if (!NonTypeParm->hasDefaultArgument()) + if (!hasVisibleDefaultArgument(NonTypeParm)) return TemplateArgumentLoc(); HasDefaultArg = true; @@ -3334,7 +3334,7 @@ Sema::SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, TemplateTemplateParmDecl *TempTempParm = cast(Param); - if (!TempTempParm->hasDefaultArgument()) + if (!hasVisibleDefaultArgument(TempTempParm)) return TemplateArgumentLoc(); HasDefaultArg = true; @@ -3799,7 +3799,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, // (when the template parameter was part of a nested template) into // the default argument. if (TemplateTypeParmDecl *TTP = dyn_cast(*Param)) { - if (!TTP->hasDefaultArgument()) + if (!hasVisibleDefaultArgument(TTP)) return diagnoseArityMismatch(*this, Template, TemplateLoc, NewArgs); TypeSourceInfo *ArgType = SubstDefaultTemplateArgument(*this, @@ -3815,7 +3815,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, ArgType); } else if (NonTypeTemplateParmDecl *NTTP = dyn_cast(*Param)) { - if (!NTTP->hasDefaultArgument()) + if (!hasVisibleDefaultArgument(NTTP)) return diagnoseArityMismatch(*this, Template, TemplateLoc, NewArgs); ExprResult E = SubstDefaultTemplateArgument(*this, Template, @@ -3832,7 +3832,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, TemplateTemplateParmDecl *TempParm = cast(*Param); - if (!TempParm->hasDefaultArgument()) + if (!hasVisibleDefaultArgument(TempParm)) return diagnoseArityMismatch(*this, Template, TemplateLoc, NewArgs); NestedNameSpecifierLoc QualifierLoc; diff --git a/test/Modules/Inputs/template-default-args/a.h b/test/Modules/Inputs/template-default-args/a.h index 3e41535824..be760fe6f1 100644 --- a/test/Modules/Inputs/template-default-args/a.h +++ b/test/Modules/Inputs/template-default-args/a.h @@ -3,3 +3,5 @@ template struct B {}; template struct C; template struct D; template struct E; +template struct G; +template struct H; diff --git a/test/Modules/template-default-args.cpp b/test/Modules/template-default-args.cpp index 97569f0aa3..99f5c6f059 100644 --- a/test/Modules/template-default-args.cpp +++ b/test/Modules/template-default-args.cpp @@ -1,13 +1,12 @@ // RUN: rm -rf %t // RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs/template-default-args -std=c++11 %s -// -// expected-no-diagnostics template struct A; template struct B; template struct C; template struct D; template struct E {}; +template struct H {}; // expected-note {{here}} #include "b.h" @@ -17,6 +16,7 @@ template struct B; template struct C; template struct D {}; template struct F {}; +template struct G {}; // expected-note {{here}} #include "c.h" @@ -26,3 +26,5 @@ extern C<> c; D<> d; E<> e; F<> f; +G<> g; // expected-error {{too few}} +H<> h; // expected-error {{too few}}