[cfe-commits] r73193 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp test/SemaTemplate/default-arguments.cpp
Douglas Gregor
dgregor at apple.com
Thu Jun 11 09:17:20 PDT 2009
On Jun 11, 2009, at 9:06 AM, Anders Carlsson wrote:
> Author: andersca
> Date: Thu Jun 11 11:06:49 2009
> New Revision: 73193
>
> URL: http://llvm.org/viewvc/llvm-project?rev=73193&view=rev
> Log:
> Add a null check that fixes the crash in PR4362, and make sure to
> instantiate non-type template arguments.
>
> Modified:
> cfe/trunk/lib/Sema/SemaTemplate.cpp
> cfe/trunk/test/SemaTemplate/default-arguments.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=73193&r1=73192&r2=73193&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Jun 11 11:06:49 2009
> @@ -1024,8 +1024,21 @@
> if (!NTTP->hasDefaultArgument())
> break;
>
> - // FIXME: Instantiate default argument
> - Arg = TemplateArgument(NTTP->getDefaultArgument());
> + InstantiatingTemplate Inst(*this, TemplateLoc,
> + Template,
> Converted.getFlatArgumentList(),
> + Converted.flatSize(),
> + SourceRange(TemplateLoc,
> RAngleLoc));
> +
> + TemplateArgumentList TemplateArgs(Context, Converted,
> + /*CopyArgs=*/false,
> + /*FlattenArgs=*/false);
> +
> + Sema::OwningExprResult E = InstantiateExpr(NTTP-
> >getDefaultArgument(),
> + TemplateArgs);
> + if (E.isInvalid())
> + return true;
> +
> + Arg = TemplateArgument(E.takeAs<Expr>());
> } else {
> TemplateTemplateParmDecl *TempParm
> = cast<TemplateTemplateParmDecl>(*Param);
> @@ -1400,7 +1413,8 @@
> // FIXME: Add template argument to Converted!
> if (InstantiatedParamType->isDependentType() || Arg-
> >isTypeDependent()) {
> // FIXME: Produce a cloned, canonical expression?
> - Converted->push_back(TemplateArgument(Arg));
> + if (Converted)
> + Converted->push_back(TemplateArgument(Arg));
> return false;
> }
Looks great, thanks!
- Doug
More information about the cfe-commits
mailing list