From: Tim Shen Date: Thu, 3 Aug 2017 00:18:11 +0000 (+0000) Subject: [Sema] Add a comment on an identified bug on default arguments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=11184d0faac01041125f03b215ecaf527c1088b6;p=clang [Sema] Add a comment on an identified bug on default arguments. Summary: The mis-compile is triggered by internal code, but I haven't reduced it to a small piece of code. Add a FIXME here, since a decent fix doesn't seem to be trivial. The decent fix can be changing Decl::Init to PointerUnion, and make setUninstantiatedDefaultArg take a ParamVarDecl *, which contains the Expr * as the default argument. This way, getTemplateInstantiationArgs can take that ParamVarDecl and do the right thing. Reviewers: rsmith Subscribers: sanjoy, cfe-commits Differential Revision: https://reviews.llvm.org/D36253 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309908 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index d3d7d8b67c..28b9419111 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4477,6 +4477,22 @@ bool Sema::CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, *this, ExpressionEvaluationContext::PotentiallyEvaluated, Param); // Instantiate the expression. + // + // FIXME: Pass in a correct Pattern argument, otherwise + // getTemplateInstantiationArgs uses the lexical context of FD, e.g. + // + // template + // struct A { + // static int FooImpl(); + // + // template + // // bug: default argument A::FooImpl() is evaluated with 2-level + // // template argument list [[T], [Tp]], should be [[Tp]]. + // friend A Foo(int a); + // }; + // + // template + // A Foo(int a = A::FooImpl()); MultiLevelTemplateArgumentList MutiLevelArgList = getTemplateInstantiationArgs(FD, nullptr, /*RelativeToPrimary=*/true);