[cfe-commits] r120299 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/friend.cpp

Nicolas Weber nicolasweber at gmx.de
Mon Nov 29 20:22:24 PST 2010


> On Nov 29, 2010, at 10:19 AM, Nico Weber wrote:
> 
> > Author: nico
> > Date: Mon Nov 29 12:19:25 2010
> > New Revision: 120299
> > 
> > URL: http://llvm.org/viewvc/llvm-project?rev=120299&view=rev
> > Log:
> > Always use a function's decl context when building default arguments.
> Fixes http://http://llvm.org/pr8479.
> > 
> > Modified:
> >    cfe/trunk/lib/Sema/SemaExpr.cpp
> >    cfe/trunk/test/SemaCXX/friend.cpp
> > 
> > Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=120299&r1=120298&r2=120299&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Nov 29 12:19:25 2010
> > @@ -3839,8 +3839,8 @@
> > }
> > 
> > ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc,
> > -                                                    FunctionDecl *FD,
> > -                                                    ParmVarDecl *Param)
> {
> > +                                        FunctionDecl *FD,
> > +                                        ParmVarDecl *Param) {
> >   if (Param->hasUnparsedDefaultArg()) {
> >     Diag(CallLoc,
> >           diag::err_use_of_default_argument_to_function_declared_later)
> <<
> > @@ -3857,12 +3857,20 @@
> >     MultiLevelTemplateArgumentList ArgList
> >       = getTemplateInstantiationArgs(FD, 0, /*RelativeToPrimary=*/true);
> > 
> > -    std::pair<const TemplateArgument *, unsigned> Innermost 
> > +    std::pair<const TemplateArgument *, unsigned> Innermost
> >       = ArgList.getInnermost();
> >     InstantiatingTemplate Inst(*this, CallLoc, Param, Innermost.first,
> >                                Innermost.second);
> > 
> > -    ExprResult Result = SubstExpr(UninstExpr, ArgList);
> > +    ExprResult Result;
> > +    {
> > +      // C++ [dcl.fct.default]p5:
> > +      //   The names in the [default argument] expression are bound,
> and
> > +      //   the semantic constraints are checked, at the point where the
> > +      //   default argument expression appears.
> > +      ContextRAII SavedContext(*this, FD->getDeclContext());
> > +      Result = SubstExpr(UninstExpr, ArgList);
> > +    }
> >     if (Result.isInvalid())
> >       return ExprError();
> 
> I know I just approved this, but... don't you want to use "FD" as the
> DeclContext, rather than the context in which FD is declared? It would matter
> if the function itself was friended but the class was not, for example.
> 
> Sorry I missed this in my earlier review.

I tried to write a test that catches this and found http://llvm.org/pr8705

Nico
-- 
GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit 
gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl



More information about the cfe-commits mailing list