[cfe-commits] r86460 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-decl-init.cpp

Douglas Gregor dgregor at apple.com
Mon Nov 9 08:37:35 PST 2009


On Nov 8, 2009, at 2:16 AM, Sebastian Redl wrote:

> Author: cornedbee
> Date: Sun Nov  8 04:16:43 2009
> New Revision: 86460
>
> URL: http://llvm.org/viewvc/llvm-project?rev=86460&view=rev
> Log:
> Don't reprocess non-dependent initializers of non-dependent  
> VarDecls. Fixes PR5426.
>
> Added:
>    cfe/trunk/test/SemaTemplate/instantiate-decl-init.cpp
> Modified:
>    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=86460&r1=86459&r2=86460&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Sun Nov  8  
> 04:16:43 2009
> @@ -186,6 +186,15 @@
>       = SemaRef.SubstExpr(D->getInit(), TemplateArgs);
>     if (Init.isInvalid())
>       Var->setInvalidDecl();
> +    else if (!D->getType()->isDependentType() &&
> +             !D->getInit()->isTypeDependent() &&
> +             !D->getInit()->isValueDependent()) {
> +      // If neither the declaration's type nor its initializer are  
> dependent,
> +      // we don't want to redo all the checking, especially since the
> +      // initializer might have been wrapped by a CXXConstructExpr  
> since we did
> +      // it the first time.
> +      Var->setInit(SemaRef.Context, Init.takeAs<Expr>());
> +    }
>     else if (ParenListExpr *PLE = dyn_cast<ParenListExpr>((Expr *) 
> Init.get())) {
>       // FIXME: We're faking all of the comma locations, which is  
> suboptimal.
>       // Do we even need these comma locations?


Huh, interesting. This works because we don't even try to type-check  
value-dependent (but not type-dependent) initializers, even though  
such checking *could* happen (and I'd like to do that checking at some  
point). That said, this patch is fine; if we decide to tighten up  
checking of value-dependent initializers at some later point, we'll  
revisit this.

Thanks, Sebastian!

	- Doug



More information about the cfe-commits mailing list