[cfe-commits] r89303 - in /cfe/trunk: lib/Sema/TreeTransform.h test/SemaTemplate/instantiate-case.cpp

Douglas Gregor dgregor at apple.com
Wed Nov 18 21:10:25 PST 2009


On Nov 18, 2009, at 7:14 PM, Eli Friedman wrote:

> Author: efriedma
> Date: Wed Nov 18 21:14:00 2009
> New Revision: 89303
>
> URL: http://llvm.org/viewvc/llvm-project?rev=89303&view=rev
> Log:
> The sub-statement of a case statement is not an unevaluated context!

Good catch, Eli! Thanks.

	- Doug

>
> Added:
>    cfe/trunk/test/SemaTemplate/instantiate-case.cpp
> Modified:
>    cfe/trunk/lib/Sema/TreeTransform.h
>
> Modified: cfe/trunk/lib/Sema/TreeTransform.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=89303&r1=89302&r2=89303&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/TreeTransform.h (original)
> +++ cfe/trunk/lib/Sema/TreeTransform.h Wed Nov 18 21:14:00 2009
> @@ -3037,18 +3037,21 @@
> template<typename Derived>
> Sema::OwningStmtResult
> TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
> -  // The case value expressions are not potentially evaluated.
> -  EnterExpressionEvaluationContext Unevaluated(SemaRef,  
> Action::Unevaluated);
> +  OwningExprResult LHS(SemaRef), RHS(SemaRef);
> +  {
> +    // The case value expressions are not potentially evaluated.
> +    EnterExpressionEvaluationContext Unevaluated(SemaRef,  
> Action::Unevaluated);
>
> -  // Transform the left-hand case value.
> -  OwningExprResult LHS = getDerived().TransformExpr(S->getLHS());
> -  if (LHS.isInvalid())
> -    return SemaRef.StmtError();
> +    // Transform the left-hand case value.
> +    LHS = getDerived().TransformExpr(S->getLHS());
> +    if (LHS.isInvalid())
> +      return SemaRef.StmtError();
>
> -  // Transform the right-hand case value (for the GNU case-range  
> extension).
> -  OwningExprResult RHS = getDerived().TransformExpr(S->getRHS());
> -  if (RHS.isInvalid())
> -    return SemaRef.StmtError();
> +    // Transform the right-hand case value (for the GNU case-range  
> extension).
> +    RHS = getDerived().TransformExpr(S->getRHS());
> +    if (RHS.isInvalid())
> +      return SemaRef.StmtError();
> +  }
>
>   // Build the case statement.
>   // Case statements are always rebuilt so that they will attached  
> to their
>
> Added: cfe/trunk/test/SemaTemplate/instantiate-case.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-case.cpp?rev=89303&view=auto
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/test/SemaTemplate/instantiate-case.cpp (added)
> +++ cfe/trunk/test/SemaTemplate/instantiate-case.cpp Wed Nov 18  
> 21:14:00 2009
> @@ -0,0 +1,21 @@
> +// RUN: clang-cc -fsyntax-only -verify %s
> +
> +template<class T>
> +static int alpha(T c)
> +{
> +    return *c; // expected-error{{indirection requires pointer  
> operand}}
> +}
> +
> +template<class T>
> +static void
> +_shexp_match()
> +{
> +  switch(1) {
> +  case 1:
> +    alpha(1); // expected-note{{instantiation of function template}}
> +  }
> +}
> +int main() {
> +  _shexp_match<char>(); // expected-note{{instantiation of function  
> template}}
> +  return 0;
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list