From: Eli Friedman Date: Thu, 19 Sep 2013 01:12:33 +0000 (+0000) Subject: Fix crash with cast of value-dependent expr. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f91e86c9462006e819ff0d02df564d9b715c047e;p=clang Fix crash with cast of value-dependent expr. We don't really need to perform semantic analysis on the dependent expression anyway, so just call the cast dependent. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190981 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCast.cpp b/lib/Sema/SemaCast.cpp index 032cd6efb7..46b5b45306 100644 --- a/lib/Sema/SemaCast.cpp +++ b/lib/Sema/SemaCast.cpp @@ -243,7 +243,9 @@ Sema::BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, // If the type is dependent, we won't do the semantic analysis now. // FIXME: should we check this in a more fine-grained manner? - bool TypeDependent = DestType->isDependentType() || Ex.get()->isTypeDependent(); + bool TypeDependent = DestType->isDependentType() || + Ex.get()->isTypeDependent() || + Ex.get()->isValueDependent(); CastOperation Op(*this, DestType, E); Op.OpRange = SourceRange(OpLoc, Parens.getEnd()); @@ -2008,7 +2010,8 @@ void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle, } // If the type is dependent, we won't do any other semantic analysis now. - if (DestType->isDependentType() || SrcExpr.get()->isTypeDependent()) { + if (DestType->isDependentType() || SrcExpr.get()->isTypeDependent() || + SrcExpr.get()->isValueDependent()) { assert(Kind == CK_Dependent); return; } diff --git a/test/SemaTemplate/dependent-expr.cpp b/test/SemaTemplate/dependent-expr.cpp index d75b0f3e30..01ac42ed42 100644 --- a/test/SemaTemplate/dependent-expr.cpp +++ b/test/SemaTemplate/dependent-expr.cpp @@ -72,3 +72,10 @@ namespace PR8795 { return data[0]; } } + +template struct CastDependentIntToPointer { + static void* f() { + T *x; + return ((void*)(((unsigned long)(x)|0x1ul))); + } +};