Tighten up the semantics of default template arguments, per C++0x
[temp.param]p9 and C++ DR226. Fixes PR8747.
llvm-svn: 124856
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9c4fdc9..88c3a77 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3967,8 +3967,14 @@
FunctionTemplateDecl *PrevTemplate = FunctionTemplate->getPreviousDeclaration();
CheckTemplateParameterList(FunctionTemplate->getTemplateParameters(),
PrevTemplate? PrevTemplate->getTemplateParameters() : 0,
- D.getDeclSpec().isFriendSpecified()? TPC_FriendFunctionTemplate
- : TPC_FunctionTemplate);
+ D.getDeclSpec().isFriendSpecified()
+ ? (IsFunctionDefinition
+ ? TPC_FriendFunctionTemplateDefinition
+ : TPC_FriendFunctionTemplate)
+ : (D.getCXXScopeSpec().isSet() &&
+ DC && DC->isRecord())
+ ? TPC_ClassTemplateMember
+ : TPC_FunctionTemplate);
}
if (NewFD->isInvalidDecl()) {
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index f7060f0..e867354 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -946,7 +946,10 @@
// template declaration.
if (CheckTemplateParameterList(TemplateParams,
PrevClassTemplate? PrevClassTemplate->getTemplateParameters() : 0,
- TPC_ClassTemplate))
+ (SS.isSet() && SemanticContext &&
+ SemanticContext->isRecord())
+ ? TPC_ClassTemplateMember
+ : TPC_ClassTemplate))
Invalid = true;
if (SS.isSet()) {
@@ -1045,11 +1048,15 @@
return false;
case Sema::TPC_FunctionTemplate:
+ case Sema::TPC_FriendFunctionTemplateDefinition:
// C++ [temp.param]p9:
// A default template-argument shall not be specified in a
// function template declaration or a function template
// definition [...]
- // (This sentence is not in C++0x, per DR226).
+ // If a friend function template declaration specifies a default
+ // template-argument, that declaration shall be a definition and shall be
+ // the only declaration of the function template in the translation unit.
+ // (C++98/03 doesn't have this wording; see DR226).
if (!S.getLangOptions().CPlusPlus0x)
S.Diag(ParamLoc,
diag::ext_template_parameter_default_in_function_template)