[cfe-commits] r67226 - /cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
Douglas Gregor
dgregor at apple.com
Wed Mar 18 13:37:04 PDT 2009
On Mar 18, 2009, at 1:12 PM, Gabor Greif wrote:
> Author: ggreif
> Date: Wed Mar 18 15:12:58 2009
> New Revision: 67226
>
> URL: http://llvm.org/viewvc/llvm-project?rev=67226&view=rev
> Log:
> incorporate review comment (about the optimization when we have a
> non-typedependent expression)
>
> Modified:
> cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=67226&r1=67225&r2=67226&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Wed Mar 18
> 15:12:58 2009
> @@ -839,8 +839,24 @@
> if (False.isInvalid())
> return SemaRef.ExprError();
>
> - return SemaRef.ActOnConditionalOp(E->getCond()->getLocEnd(),
> - E->getFalseExpr()->getLocStart(),
> + if (!E->isTypeDependent()) {
> + // Since our original expression was not type-dependent, we do
> not
> + // perform lookup again at instantiation time (C++ [temp.dep]p1).
> + // Instead, we just build the new conditional operator call
> expression.
> + Cond.release();
> + True.release();
> + False.release();
> + // FIXME: Don't reuse the parts here. We need to instantiate
> them.
> + return SemaRef.Owned(new (SemaRef.Context) ConditionalOperator(
> + E-
> >getCond(),
> + E-
> >getTrueExpr(),
> + E-
> >getFalseExpr(),
> + E-
> >getType()));
> + }
Getting closer. This will do the wrong thing when E->getCond() is type-
dependent but E->getTrueExpr() and E->getFalseExpr() are not type-
dependent. In this case, E is not type-dependent, even though we still
need to check that the instantiated Cond is convertible to bool.
Example:
sizeof(T() + U()? sizeof(T) : sizeof(U))
Here, the ? : expression is not type-dependent (it's type is known to
be size_t), but after instantiation we still need to perform the
contextual conversion of the instantiated T() + U() to bool.
Also, when creating the ConditionalOperation, you'll need to pass it
the instantiated values Cond.release(), True.release(), and
False.release() rather than the uninstantiated E->getCond(), E-
>getTrueExpr(), and E->getFalseExpr().
- Doug
More information about the cfe-commits
mailing list