r239487 - [modules] Don't allow use of non-visible (inherited) default template arguments.
Richard Smith
richard-llvm at metafoo.co.uk
Wed Jun 10 13:36:35 PDT 2015
Author: rsmith
Date: Wed Jun 10 15:36:34 2015
New Revision: 239487
URL: http://llvm.org/viewvc/llvm-project?rev=239487&view=rev
Log:
[modules] Don't allow use of non-visible (inherited) default template arguments.
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/Modules/Inputs/template-default-args/a.h
cfe/trunk/test/Modules/template-default-args.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=239487&r1=239486&r2=239487&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Jun 10 15:36:34 2015
@@ -3299,7 +3299,7 @@ Sema::SubstDefaultTemplateArgumentIfAvai
HasDefaultArg = false;
if (TemplateTypeParmDecl *TypeParm = dyn_cast<TemplateTypeParmDecl>(Param)) {
- if (!TypeParm->hasDefaultArgument())
+ if (!hasVisibleDefaultArgument(TypeParm))
return TemplateArgumentLoc();
HasDefaultArg = true;
@@ -3316,7 +3316,7 @@ Sema::SubstDefaultTemplateArgumentIfAvai
if (NonTypeTemplateParmDecl *NonTypeParm
= dyn_cast<NonTypeTemplateParmDecl>(Param)) {
- if (!NonTypeParm->hasDefaultArgument())
+ if (!hasVisibleDefaultArgument(NonTypeParm))
return TemplateArgumentLoc();
HasDefaultArg = true;
@@ -3334,7 +3334,7 @@ Sema::SubstDefaultTemplateArgumentIfAvai
TemplateTemplateParmDecl *TempTempParm
= cast<TemplateTemplateParmDecl>(Param);
- if (!TempTempParm->hasDefaultArgument())
+ if (!hasVisibleDefaultArgument(TempTempParm))
return TemplateArgumentLoc();
HasDefaultArg = true;
@@ -3799,7 +3799,7 @@ bool Sema::CheckTemplateArgumentList(Tem
// (when the template parameter was part of a nested template) into
// the default argument.
if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
- if (!TTP->hasDefaultArgument())
+ if (!hasVisibleDefaultArgument(TTP))
return diagnoseArityMismatch(*this, Template, TemplateLoc, NewArgs);
TypeSourceInfo *ArgType = SubstDefaultTemplateArgument(*this,
@@ -3815,7 +3815,7 @@ bool Sema::CheckTemplateArgumentList(Tem
ArgType);
} else if (NonTypeTemplateParmDecl *NTTP
= dyn_cast<NonTypeTemplateParmDecl>(*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(Tem
TemplateTemplateParmDecl *TempParm
= cast<TemplateTemplateParmDecl>(*Param);
- if (!TempParm->hasDefaultArgument())
+ if (!hasVisibleDefaultArgument(TempParm))
return diagnoseArityMismatch(*this, Template, TemplateLoc, NewArgs);
NestedNameSpecifierLoc QualifierLoc;
Modified: cfe/trunk/test/Modules/Inputs/template-default-args/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/template-default-args/a.h?rev=239487&r1=239486&r2=239487&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/template-default-args/a.h (original)
+++ cfe/trunk/test/Modules/Inputs/template-default-args/a.h Wed Jun 10 15:36:34 2015
@@ -3,3 +3,5 @@ template<typename T> struct B {};
template<typename T> struct C;
template<typename T> struct D;
template<typename T> struct E;
+template<typename T = int> struct G;
+template<typename T = int> struct H;
Modified: cfe/trunk/test/Modules/template-default-args.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/template-default-args.cpp?rev=239487&r1=239486&r2=239487&view=diff
==============================================================================
--- cfe/trunk/test/Modules/template-default-args.cpp (original)
+++ cfe/trunk/test/Modules/template-default-args.cpp Wed Jun 10 15:36:34 2015
@@ -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<typename T> struct A;
template<typename T> struct B;
template<typename T> struct C;
template<typename T = int> struct D;
template<typename T = int> struct E {};
+template<typename T> struct H {}; // expected-note {{here}}
#include "b.h"
@@ -17,6 +16,7 @@ template<typename T = int> struct B;
template<typename T = int> struct C;
template<typename T> struct D {};
template<typename T> struct F {};
+template<typename T> 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}}
More information about the cfe-commits
mailing list