I believe this is a false positive:<div>-----------------------------------------</div><div><div> #include <typeinfo></div><div> #include <vector></div><div><br></div><div> struct A {</div><div> virtual ~A();</div><div> };</div><div><br></div><div> const char *foo(const std::vector<A*> &v) {</div><div> const std::type_info &t = typeid(*v[0]);</div><div> return <a href="http://t.name" target="_blank" class="cremed">t.name</a>();</div><div> } </div></div><div><span style="line-height:19.7999992370605px">-----------------------------------------</span><br></div><div><br></div><div>This warning seems to be pretty annoying as it's on by default.</div><div><br></div><div>Is it possible to revert/disable and reland it gradually, making sure we don't get false positives along the way?</div><div>or at least put it under a separate flag for the time being?</div><br><div class="gmail_quote">On Thu Dec 18 2014 at 9:01:03 PM Aaron Ballman <<a href="mailto:aaron@aaronballman.com" target="_blank" class="cremed">aaron@aaronballman.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: aaronballman<br>
Date: Wed Dec 17 15:57:17 2014<br>
New Revision: 224465<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=224465&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject?rev=224465&view=rev</a><br>
Log:<br>
Adding a -Wunused-value warning for expressions with side effects used in an unevaluated expression context, such as sizeof(), or decltype(). Also adds a similar warning when the expression passed to typeid() *is* evaluated, since it is equally likely that the user would expect the expression operand to be unevaluated in that case.<br>
<br>
Modified:<br>
cfe/trunk/include/clang/AST/<u></u>Ex<u></u>pr.h<br>
cfe/trunk/include/clang/Basic/<u></u><u></u>DiagnosticSemaKinds.td<br>
cfe/trunk/include/clang/Sema/<u></u>S<u></u>ema.h<br>
cfe/trunk/lib/AST/Expr.cpp<br>
cfe/trunk/lib/Sema/SemaExpr.<u></u>cp<u></u>p<br>
cfe/trunk/lib/Sema/<u></u>SemaExprCXX<u></u>.cpp<br>
cfe/trunk/lib/Sema/<u></u>SemaTemplat<u></u>eDeduction.cpp<br>
cfe/trunk/lib/Sema/SemaType.<u></u>cp<u></u>p<br>
cfe/trunk/test/CXX/expr/expr.<u></u>p<u></u>rim/expr.prim.lambda/p2-<u></u>generi<u></u>c-lambda-1y.cpp<br>
cfe/trunk/test/CXX/expr/expr.<u></u>p<u></u>rim/expr.prim.lambda/p2.cpp<br>
cfe/trunk/test/CXX/expr/expr.<u></u>u<u></u>nary/expr.unary.noexcept/<u></u>sema.<u></u>cpp<br>
cfe/trunk/test/Sema/bitfield.c<br>
cfe/trunk/test/Sema/expr-<u></u>comma<u></u>-c99.c<br>
cfe/trunk/test/Sema/expr-<u></u>comma<u></u>.c<br>
cfe/trunk/test/Sema/warn-<u></u>unuse<u></u>d-value.c<br>
cfe/trunk/test/SemaCXX/<u></u>constan<u></u>t-expression-cxx11.cpp<br>
cfe/trunk/test/SemaCXX/<u></u>runtime<u></u>diag-ppe.cpp<br>
cfe/trunk/test/SemaCXX/<u></u>undefin<u></u>ed-internal.cpp<br>
cfe/trunk/test/SemaCXX/vararg-<u></u><u></u>non-pod.cpp<br>
cfe/trunk/test/SemaCXX/warn-<u></u>un<u></u>used-result.cpp<br>
cfe/trunk/test/SemaCXX/warn-<u></u>un<u></u>used-value-cxx11.cpp<br>
cfe/trunk/test/SemaCXX/warn-<u></u>un<u></u>used-value.cpp<br>
cfe/trunk/test/SemaObjCXX/<a href="http://arc-ppe.mm" target="_blank" class="cremed">arc-<u></u><u></u>ppe.mm</a><br>
<br>
Modified: cfe/trunk/include/clang/AST/<u></u>Ex<u></u>pr.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/include/<u></u>clang/<u></u>AST/Expr.h?rev=224465&<u></u>r1=<u></u>224464&r2=224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/include/clang/AST/<u></u>Ex<u></u>pr.h (original)<br>
+++ cfe/trunk/include/clang/AST/<u></u>Ex<u></u>pr.h Wed Dec 17 15:57:17 2014<br>
@@ -586,8 +586,13 @@ public:<br>
<br>
/// HasSideEffects - This routine returns true for all those expressions<br>
/// which have any effect other than producing a value. Example is a function<br>
- /// call, volatile variable read, or throwing an exception.<br>
- bool HasSideEffects(const ASTContext &Ctx) const;<br>
+ /// call, volatile variable read, or throwing an exception. If<br>
+ /// IncludePossibleEffects is false, this call treats certain expressions with<br>
+ /// potential side effects (such as function call-like expressions,<br>
+ /// instantiation-dependent expressions, or invocations from a macro) as not<br>
+ /// having side effects.<br>
+ bool HasSideEffects(const ASTContext &Ctx,<br>
+ bool IncludePossibleEffects = true) const;<br>
<br>
/// \brief Determine whether this expression involves a call to any function<br>
/// that is not trivial.<br>
<br>
Modified: cfe/trunk/include/clang/Basic/<u></u><u></u>DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/include/<u></u>clang/<u></u>Basic/<u></u>DiagnosticSemaKinds.td?<u></u>rev=<u></u>224465&r1=224464&r2=<u></u>224465&<u></u>view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/include/clang/Basic/<u></u><u></u>DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/<u></u><u></u>DiagnosticSemaKinds.td Wed Dec 17 15:57:17 2014<br>
@@ -6107,6 +6107,12 @@ def warn_unused_container_<u></u>subscrip<u></u>t_expr<br>
def warn_unused_call : Warning<<br>
"ignoring return value of function declared with %0 attribute">,<br>
InGroup<UnusedValue>;<br>
+def warn_side_effects_unevaluated_<u></u><u></u>context : Warning<<br>
+ "expression with side effects has no effect in an unevaluated context">,<br>
+ InGroup<UnusedValue>;<br>
+def warn_side_effects_typeid : Warning<<br>
+ "expression with side effects will be evaluated despite being used as an "<br>
+ "operand to 'typeid'">, InGroup<UnusedValue>;<br>
def warn_unused_result : Warning<<br>
"ignoring return value of function declared with warn_unused_result "<br>
"attribute">, InGroup<DiagGroup<"unused-<u></u>resu<u></u>lt">>;<br>
<br>
Modified: cfe/trunk/include/clang/Sema/<u></u>S<u></u>ema.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/include/<u></u>clang/<u></u>Sema/Sema.h?rev=224465&<u></u>r1=<u></u>224464&r2=224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/include/clang/Sema/<u></u>S<u></u>ema.h (original)<br>
+++ cfe/trunk/include/clang/Sema/<u></u>S<u></u>ema.h Wed Dec 17 15:57:17 2014<br>
@@ -1399,7 +1399,10 @@ public:<br>
const CXXScopeSpec &SS, QualType T);<br>
<br>
QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);<br>
- QualType BuildDecltypeType(Expr *E, SourceLocation Loc);<br>
+ /// If AsUnevaluated is false, E is treated as though it were an evaluated<br>
+ /// context, such as when building a type for decltype(auto).<br>
+ QualType BuildDecltypeType(Expr *E, SourceLocation Loc,<br>
+ bool AsUnevaluated = true);<br>
QualType BuildUnaryTransformType(<u></u>QualTy<u></u>pe BaseType,<br>
UnaryTransformType::UTTKind UKind,<br>
SourceLocation Loc);<br>
<br>
Modified: cfe/trunk/lib/AST/Expr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/lib/AST/<u></u>Expr.<u></u>cpp?rev=224465&r1=224464&<u></u>r2=<u></u>224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/lib/AST/Expr.cpp (original)<br>
+++ cfe/trunk/lib/AST/Expr.cpp Wed Dec 17 15:57:17 2014<br>
@@ -2866,9 +2866,16 @@ bool Expr::isConstantInitializer(<u></u>AS<u></u>TCont<br>
return false;<br>
}<br>
<br>
-bool Expr::HasSideEffects(const ASTContext &Ctx) const {<br>
+bool Expr::HasSideEffects(const ASTContext &Ctx,<br>
+ bool IncludePossibleEffects) const {<br>
+ // In circumstances where we care about definite side effects instead of<br>
+ // potential side effects, we want to ignore expressions that are part of a<br>
+ // macro expansion as a potential side effect.<br>
+ if (!IncludePossibleEffects && getExprLoc().isMacroID())<br>
+ return false;<br>
+<br>
if (isInstantiationDependent())<br>
- return true;<br>
+ return IncludePossibleEffects;<br>
<br>
switch (getStmtClass()) {<br>
case NoStmtClass:<br>
@@ -2921,21 +2928,27 @@ bool Expr::HasSideEffects(const ASTConte<br>
return false;<br>
<br>
case CallExprClass:<br>
+ case CXXOperatorCallExprClass:<br>
+ case CXXMemberCallExprClass:<br>
+ case CUDAKernelCallExprClass:<br>
+ case BlockExprClass:<br>
+ case CXXBindTemporaryExprClass:<br>
+ case UserDefinedLiteralClass:<br>
+ // We don't know a call definitely has side effects, but we can check the<br>
+ // call's operands.<br>
+ if (!IncludePossibleEffects)<br>
+ break;<br>
+ return true;<br>
+<br>
case MSPropertyRefExprClass:<br>
case CompoundAssignOperatorClass:<br>
case VAArgExprClass:<br>
case AtomicExprClass:<br>
case StmtExprClass:<br>
- case CXXOperatorCallExprClass:<br>
- case CXXMemberCallExprClass:<br>
- case UserDefinedLiteralClass:<br>
case CXXThrowExprClass:<br>
case CXXNewExprClass:<br>
case CXXDeleteExprClass:<br>
case ExprWithCleanupsClass:<br>
- case CXXBindTemporaryExprClass:<br>
- case BlockExprClass:<br>
- case CUDAKernelCallExprClass:<br>
// These always have a side-effect.<br>
return true;<br>
<br>
@@ -2971,24 +2984,26 @@ bool Expr::HasSideEffects(const ASTConte<br>
case InitListExprClass:<br>
// FIXME: The children for an InitListExpr doesn't include the array filler.<br>
if (const Expr *E = cast<InitListExpr>(this)-><u></u>getA<u></u>rrayFiller())<br>
- if (E->HasSideEffects(Ctx))<br>
+ if (E->HasSideEffects(Ctx, IncludePossibleEffects))<br>
return true;<br>
break;<br>
<br>
case GenericSelectionExprClass:<br>
return cast<GenericSelectionExpr>(<u></u>thi<u></u>s)->getResultExpr()-><br>
- HasSideEffects(Ctx);<br>
+ HasSideEffects(Ctx, IncludePossibleEffects);<br>
<br>
case ChooseExprClass:<br>
- return cast<ChooseExpr>(this)-><u></u>getCho<u></u>senSubExpr()-><u></u>HasSideEffects(<u></u>Ctx);<br>
+ return cast<ChooseExpr>(this)-><u></u>getCho<u></u>senSubExpr()-><u></u>HasSideEffects(<br>
+ Ctx, IncludePossibleEffects);<br>
<br>
case CXXDefaultArgExprClass:<br>
- return cast<CXXDefaultArgExpr>(this)-<u></u><u></u>>getExpr()->HasSideEffects(<u></u>Ctx<u></u>);<br>
+ return cast<CXXDefaultArgExpr>(this)-<u></u><u></u>>getExpr()->HasSideEffects(<br>
+ Ctx, IncludePossibleEffects);<br>
<br>
case CXXDefaultInitExprClass: {<br>
const FieldDecl *FD = cast<CXXDefaultInitExpr>(this)<u></u><u></u>->getField();<br>
if (const Expr *E = FD->getInClassInitializer())<br>
- return E->HasSideEffects(Ctx);<br>
+ return E->HasSideEffects(Ctx, IncludePossibleEffects);<br>
// If we've not yet parsed the initializer, assume it has side-effects.<br>
return true;<br>
}<br>
@@ -3021,7 +3036,7 @@ bool Expr::HasSideEffects(const ASTConte<br>
case CXXConstructExprClass:<br>
case CXXTemporaryObjectExprClass: {<br>
const CXXConstructExpr *CE = cast<CXXConstructExpr>(this);<br>
- if (!CE->getConstructor()-><u></u>isTriv<u></u>ial())<br>
+ if (!CE->getConstructor()-><u></u>isTriv<u></u>ial() && IncludePossibleEffects)<br>
return true;<br>
// A trivial constructor does not add any side-effects of its own. Just look<br>
// at its arguments.<br>
@@ -3049,7 +3064,7 @@ bool Expr::HasSideEffects(const ASTConte<br>
const Expr *Subexpr = *I;<br>
if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(<u></u>Sube<u></u>xpr))<br>
Subexpr = OVE->getSourceExpr();<br>
- if (Subexpr->HasSideEffects(Ctx))<br>
+ if (Subexpr->HasSideEffects(Ctx, IncludePossibleEffects))<br>
return true;<br>
}<br>
return false;<br>
@@ -3058,22 +3073,24 @@ bool Expr::HasSideEffects(const ASTConte<br>
case ObjCBoxedExprClass:<br>
case ObjCArrayLiteralClass:<br>
case ObjCDictionaryLiteralClass:<br>
- case ObjCMessageExprClass:<br>
case ObjCSelectorExprClass:<br>
case ObjCProtocolExprClass:<br>
- case ObjCPropertyRefExprClass:<br>
case ObjCIsaExprClass:<br>
case ObjCIndirectCopyRestoreExprCla<u></u><u></u>ss:<br>
case ObjCSubscriptRefExprClass:<br>
case ObjCBridgedCastExprClass:<br>
- // FIXME: Classify these cases better.<br>
- return true;<br>
+ case ObjCMessageExprClass:<br>
+ case ObjCPropertyRefExprClass:<br>
+ // FIXME: Classify these cases better.<br>
+ if (IncludePossibleEffects)<br>
+ return true;<br>
+ break;<br>
}<br>
<br>
// Recurse to children.<br>
for (const_child_range SubStmts = children(); SubStmts; ++SubStmts)<br>
if (const Stmt *S = *SubStmts)<br>
- if (cast<Expr>(S)-><u></u>HasSideEffects<u></u>(Ctx))<br>
+ if (cast<Expr>(S)-><u></u>HasSideEffects<u></u>(Ctx, IncludePossibleEffects))<br>
return true;<br>
<br>
return false;<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaExpr.<u></u>cp<u></u>p<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/lib/Sema/<u></u>SemaE<u></u>xpr.cpp?rev=224465&r1=<u></u>224464&<u></u>r2=224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/lib/Sema/SemaExpr.<u></u>cp<u></u>p (original)<br>
+++ cfe/trunk/lib/Sema/SemaExpr.<u></u>cp<u></u>p Wed Dec 17 15:57:17 2014<br>
@@ -1290,6 +1290,13 @@ Sema::<u></u>CreateGenericSelectionEx<u></u>pr(<u></u>SourceL<br>
ControllingExpr = result.get();<br>
}<br>
<br>
+ // The controlling expression is an unevaluated operand, so side effects are<br>
+ // likely unintended.<br>
+ if (ActiveTemplateInstantiations.<u></u><u></u>empty() &&<br>
+ ControllingExpr-><u></u>HasSideEffect<u></u>s(Context, false))<br>
+ Diag(ControllingExpr-><u></u>getExprL<u></u>oc(),<br>
+ diag::warn_side_effects_<u></u>uneva<u></u>luated_context);<br>
+<br>
bool TypeErrorFound = false,<br>
IsResultDependent = ControllingExpr-><u></u>isTypeDepende<u></u>nt(),<br>
ContainsUnexpandedParameterPac<u></u><u></u>k<br>
@@ -3525,6 +3532,12 @@ bool Sema::<u></u>CheckUnaryExprOrTypeTrai<u></u>tOper<br>
return true;<br>
}<br>
<br>
+ // The operand for sizeof and alignof is in an unevaluated expression context,<br>
+ // so side effects could result in unintended consequences.<br>
+ if ((ExprKind == UETT_SizeOf || ExprKind == UETT_AlignOf) &&<br>
+ ActiveTemplateInstantiations.<u></u>e<u></u>mpty() && E->HasSideEffects(Context, false))<br>
+ Diag(E->getExprLoc(), diag::warn_side_effects_<u></u>uneval<u></u>uated_context);<br>
+<br>
if (<u></u>CheckObjCTraitOperandConstrai<u></u>n<u></u>ts(*this, ExprTy, E->getExprLoc(),<br>
E->getSourceRange(), ExprKind))<br>
return true;<br>
<br>
Modified: cfe/trunk/lib/Sema/<u></u>SemaExprCXX<u></u>.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/lib/Sema/<u></u>SemaE<u></u>xprCXX.cpp?rev=224465&r1=<u></u>22446<u></u>4&r2=224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/lib/Sema/<u></u>SemaExprCXX<u></u>.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<u></u>SemaExprCXX<u></u>.cpp Wed Dec 17 15:57:17 2014<br>
@@ -396,6 +396,7 @@ ExprResult Sema::BuildCXXTypeId(QualType<br>
SourceLocation TypeidLoc,<br>
Expr *E,<br>
SourceLocation RParenLoc) {<br>
+ bool WasEvaluated = false;<br>
if (E && !E->isTypeDependent()) {<br>
if (E->getType()-><u></u>isPlaceholderTy<u></u>pe()) {<br>
ExprResult result = CheckPlaceholderExpr(E);<br>
@@ -425,6 +426,7 @@ ExprResult Sema::BuildCXXTypeId(QualType<br>
<br>
// We require a vtable to query the type at run time.<br>
MarkVTableUsed(TypeidLoc, RecordD);<br>
+ WasEvaluated = true;<br>
}<br>
}<br>
<br>
@@ -444,6 +446,14 @@ ExprResult Sema::BuildCXXTypeId(QualType<br>
if (E->getType()-><u></u>isVariablyModif<u></u>iedType())<br>
return ExprError(Diag(TypeidLoc, diag::err_variably_modified_<u></u>ty<u></u>peid)<br>
<< E->getType());<br>
+ else if (ActiveTemplateInstantiations.<u></u><u></u>empty() &&<br>
+ E->HasSideEffects(Context, WasEvaluated)) {<br>
+ // The expression operand for typeid is in an unevaluated expression<br>
+ // context, so side effects could result in unintended consequences.<br>
+ Diag(E->getExprLoc(), WasEvaluated<br>
+ ? diag::warn_side_effects_typeid<br>
+ : diag::warn_side_effects_<u></u>uneval<u></u>uated_context);<br>
+ }<br>
<br>
return new (Context) CXXTypeidExpr(TypeInfoType.<u></u>wit<u></u>hConst(), E,<br>
SourceRange(TypeidLoc, RParenLoc));<br>
@@ -5622,7 +5632,8 @@ ExprResult Sema::ActOnPseudoDestructorEx<br>
if (CheckArrow(*this, ObjectType, Base, OpKind, OpLoc))<br>
return ExprError();<br>
<br>
- QualType T = BuildDecltypeType(DS.<u></u>getRepAsE<u></u>xpr(), DS.getTypeSpecTypeLoc());<br>
+ QualType T = BuildDecltypeType(DS.<u></u>getRepAsE<u></u>xpr(), DS.getTypeSpecTypeLoc(),<br>
+ false);<br>
<br>
TypeLocBuilder TLB;<br>
DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T);<br>
@@ -5690,6 +5701,13 @@ ExprResult Sema::BuildCXXMemberCallExpr(<br>
<br>
ExprResult Sema::BuildCXXNoexceptExpr(<u></u>Sou<u></u>rceLocation KeyLoc, Expr *Operand,<br>
SourceLocation RParen) {<br>
+ if (ActiveTemplateInstantiations.<u></u><u></u>empty() &&<br>
+ Operand->HasSideEffects(<u></u>Contex<u></u>t, false)) {<br>
+ // The expression operand for noexcept is in an unevaluated expression<br>
+ // context, so side effects could result in unintended consequences.<br>
+ Diag(Operand->getExprLoc(), diag::warn_side_effects_<u></u>uneval<u></u>uated_context);<br>
+ }<br>
+<br>
CanThrowResult CanThrow = canThrow(Operand);<br>
return new (Context)<br>
CXXNoexceptExpr(Context.<u></u>BoolT<u></u>y, Operand, CanThrow, KeyLoc, RParen);<br>
<br>
Modified: cfe/trunk/lib/Sema/<u></u>SemaTemplat<u></u>eDeduction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/lib/Sema/<u></u>SemaT<u></u>emplateDeduction.cpp?rev=<u></u>22446<u></u>5&r1=224464&r2=224465&<u></u>view=<u></u>diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/lib/Sema/<u></u>SemaTemplat<u></u>eDeduction.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<u></u>SemaTemplat<u></u>eDeduction.cpp Wed Dec 17 15:57:17 2014<br>
@@ -3989,7 +3989,7 @@ Sema::DeduceAutoType(TypeLoc Type, Expr<br>
return DAR_FailedAlreadyDiagnosed;<br>
}<br>
<br>
- QualType Deduced = BuildDecltypeType(Init, Init->getLocStart());<br>
+ QualType Deduced = BuildDecltypeType(Init, Init->getLocStart(), false);<br>
// FIXME: Support a non-canonical deduced type for 'auto'.<br>
Deduced = Context.getCanonicalType(<u></u>Deduc<u></u>ed);<br>
Result = SubstituteAutoTransform(*this, Deduced).Apply(Type);<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaType.<u></u>cp<u></u>p<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/lib/Sema/<u></u>SemaT<u></u>ype.cpp?rev=224465&r1=<u></u>224464&<u></u>r2=224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/lib/Sema/SemaType.<u></u>cp<u></u>p (original)<br>
+++ cfe/trunk/lib/Sema/SemaType.<u></u>cp<u></u>p Wed Dec 17 15:57:17 2014<br>
@@ -5518,11 +5518,19 @@ static QualType getDecltypeForExpr(Sema<br>
return T;<br>
}<br>
<br>
-QualType Sema::BuildDecltypeType(Expr *E, SourceLocation Loc) {<br>
+QualType Sema::BuildDecltypeType(Expr *E, SourceLocation Loc,<br>
+ bool AsUnevaluated) {<br>
ExprResult ER = CheckPlaceholderExpr(E);<br>
if (ER.isInvalid()) return QualType();<br>
E = ER.get();<br>
<br>
+ if (AsUnevaluated && ActiveTemplateInstantiations.<u></u>e<u></u>mpty() &&<br>
+ E->HasSideEffects(Context, false)) {<br>
+ // The expression operand for decltype is in an unevaluated expression<br>
+ // context, so side effects could result in unintended consequences.<br>
+ Diag(E->getExprLoc(), diag::warn_side_effects_<u></u>uneval<u></u>uated_context);<br>
+ }<br>
+<br>
return Context.getDecltypeType(E, getDecltypeForExpr(*this, E));<br>
}<br>
<br>
<br>
Modified: cfe/trunk/test/CXX/expr/expr.<u></u>p<u></u>rim/expr.prim.lambda/p2-<u></u>generi<u></u>c-lambda-1y.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p2-generic-lambda-1y.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/CXX/<u></u>expr/<u></u>expr.prim/expr.prim.<u></u>lambda/p2-<u></u>generic-lambda-1y.<u></u>cpp?rev=<u></u>224465&r1=224464&r2=<u></u>224465&<u></u>view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/CXX/expr/expr.<u></u>p<u></u>rim/expr.prim.lambda/p2-<u></u>generi<u></u>c-lambda-1y.cpp (original)<br>
+++ cfe/trunk/test/CXX/expr/expr.<u></u>p<u></u>rim/expr.prim.lambda/p2-<u></u>generi<u></u>c-lambda-1y.cpp Wed Dec 17 15:57:17 2014<br>
@@ -18,7 +18,7 @@ void unevaluated_operand(P &p, int i) {<br>
// FIXME: this should only emit one error.<br>
int i2 = sizeof([](auto a, auto b)->void{}(3, '4')); // expected-error{{lambda expression in an unevaluated operand}} \<br>
// expected-error{{invalid application of 'sizeof'}}<br>
- const std::type_info &ti1 = typeid([](auto &a) -> P& { static P p; return p; }(i));<br>
+ const std::type_info &ti1 = typeid([](auto &a) -> P& { static P p; return p; }(i)); // expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}<br>
const std::type_info &ti2 = typeid([](auto) -> int { return i; }(i)); // expected-error{{lambda expression in an unevaluated operand}}\<br>
// expected-error{{cannot be implicitly captured}}\<br>
// expected-note{{begins here}}<br>
<br>
Modified: cfe/trunk/test/CXX/expr/expr.<u></u>p<u></u>rim/expr.prim.lambda/p2.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p2.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/CXX/<u></u>expr/<u></u>expr.prim/expr.prim.<u></u>lambda/p2.<u></u>cpp?rev=224465&r1=<u></u>224464&r2=<u></u>224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/CXX/expr/expr.<u></u>p<u></u>rim/expr.prim.lambda/p2.cpp (original)<br>
+++ cfe/trunk/test/CXX/expr/expr.<u></u>p<u></u>rim/expr.prim.lambda/p2.cpp Wed Dec 17 15:57:17 2014<br>
@@ -1,4 +1,4 @@<br>
-// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify<br>
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wno-unused-value %s -verify<br>
<br>
// prvalue<br>
void prvalue() {<br>
<br>
Modified: cfe/trunk/test/CXX/expr/expr.<u></u>u<u></u>nary/expr.unary.noexcept/<u></u>sema.<u></u>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/CXX/<u></u>expr/<u></u>expr.unary/expr.unary.<u></u>noexcept<u></u>/sema.cpp?rev=224465&<u></u>r1=<u></u>224464&r2=224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/CXX/expr/expr.<u></u>u<u></u>nary/expr.unary.noexcept/<u></u>sema.<u></u>cpp (original)<br>
+++ cfe/trunk/test/CXX/expr/expr.<u></u>u<u></u>nary/expr.unary.noexcept/<u></u>sema.<u></u>cpp Wed Dec 17 15:57:17 2014<br>
@@ -1,4 +1,4 @@<br>
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -fms-extensions -Wno-delete-incomplete %s<br>
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -fms-extensions -Wno-delete-incomplete -Wno-unused-value %s<br>
// expected-no-diagnostics<br>
<br>
#define P(e) static_assert(noexcept(e), "expected nothrow")<br>
<br>
Modified: cfe/trunk/test/Sema/bitfield.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/bitfield.c?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/Sema/<u></u>bitf<u></u>ield.c?rev=224465&r1=<u></u>224464&<u></u>r2=224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/Sema/bitfield.c (original)<br>
+++ cfe/trunk/test/Sema/bitfield.c Wed Dec 17 15:57:17 2014<br>
@@ -1,4 +1,5 @@<br>
-// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c11<br>
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c11 -Wno-unused-value<br>
+<br>
enum e0; // expected-note{{forward declaration of 'enum e0'}}<br>
<br>
struct a {<br>
<br>
Modified: cfe/trunk/test/Sema/expr-<u></u>comma<u></u>-c99.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/expr-comma-c99.c?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/Sema/<u></u>expr<u></u>-comma-c99.c?rev=224465&<u></u>r1=<u></u>224464&r2=224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/Sema/expr-<u></u>comma<u></u>-c99.c (original)<br>
+++ cfe/trunk/test/Sema/expr-<u></u>comma<u></u>-c99.c Wed Dec 17 15:57:17 2014<br>
@@ -1,5 +1,4 @@<br>
// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c99 -Wno-sizeof-array-decay<br>
-// expected-no-diagnostics<br>
// rdar://6095180<br>
<br>
struct s { char c[17]; };<br>
@@ -14,5 +13,5 @@ int B[sizeof((a.c)) == 17 ? 1 : -1];<br>
// comma does array/function promotion in c99.<br>
int X[sizeof(0, (foo().c)) == sizeof(char*) ? 1 : -1];<br>
int Y[sizeof(0, (a,b).c) == sizeof(char*) ? 1 : -1];<br>
-int Z[sizeof(0, (a=b).c) == sizeof(char*) ? 1 : -1];<br>
+int Z[sizeof(0, (a=b).c) == sizeof(char*) ? 1 : -1]; // expected-warning {{expression with side effects has no effect in an unevaluated context}}<br>
<br>
<br>
Modified: cfe/trunk/test/Sema/expr-<u></u>comma<u></u>.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/expr-comma.c?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/Sema/<u></u>expr<u></u>-comma.c?rev=224465&r1=<u></u>224464&<u></u>r2=224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/Sema/expr-<u></u>comma<u></u>.c (original)<br>
+++ cfe/trunk/test/Sema/expr-<u></u>comma<u></u>.c Wed Dec 17 15:57:17 2014<br>
@@ -1,5 +1,4 @@<br>
// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c89 -Wno-sizeof-array-decay<br>
-// expected-no-diagnostics<br>
// rdar://6095180<br>
<br>
struct s { char c[17]; };<br>
@@ -15,4 +14,4 @@ int B[sizeof((a.c)) == 17 ? 1 : -1];<br>
int W[sizeof(0, a.c) == sizeof(char*) ? 1 : -1];<br>
int X[sizeof(0, (foo().c)) == 17 ? 1 : -1];<br>
int Y[sizeof(0, (a,b).c) == 17 ? 1 : -1];<br>
-int Z[sizeof(0, (a=b).c) == 17 ? 1 : -1];<br>
+int Z[sizeof(0, (a=b).c) == 17 ? 1 : -1]; // expected-warning {{expression with side effects has no effect in an unevaluated context}}<br>
<br>
Modified: cfe/trunk/test/Sema/warn-<u></u>unuse<u></u>d-value.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unused-value.c?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/Sema/<u></u>warn<u></u>-unused-value.c?rev=<u></u>224465&r1=<u></u>224464&r2=224465&<u></u>view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/Sema/warn-<u></u>unuse<u></u>d-value.c (original)<br>
+++ cfe/trunk/test/Sema/warn-<u></u>unuse<u></u>d-value.c Wed Dec 17 15:57:17 2014<br>
@@ -1,6 +1,6 @@<br>
-// RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value -Wunused-label %s<br>
-// RUN: %clang_cc1 -fsyntax-only -verify -Wunused %s<br>
-// RUN: %clang_cc1 -fsyntax-only -verify -Wall %s<br>
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -verify -Wunused-value -Wunused-label %s<br>
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -verify -Wunused %s<br>
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -verify -Wall %s<br>
<br>
int i = 0;<br>
int j = 0;<br>
@@ -88,3 +88,22 @@ void f1(struct s0 *a) {<br>
// rdar://8139785<br>
f0((int)(a->f0 + 1, 10)); // expected-warning {{expression result unused}}<br>
}<br>
+<br>
+void blah(int a);<br>
+#define GenTest(x) _Generic(x, default : blah)(x)<br>
+<br>
+void unevaluated_operands(void) {<br>
+ int val = 0;<br>
+<br>
+ (void)sizeof(++val); // expected-warning {{expression with side effects has no effect in an unevaluated context}}<br>
+ (void)_Generic(val++, default : 0); // expected-warning {{expression with side effects has no effect in an unevaluated context}}<br>
+ (void)_Alignof(val++); // expected-warning {{expression with side effects has no effect in an unevaluated context}} expected-warning {{'_Alignof' applied to an expression is a GNU extension}}<br>
+<br>
+ // VLAs can have side effects so long as it's part of the type and not<br>
+ // an expression.<br>
+ (void)sizeof(int[++val]); // Ok<br>
+ (void)_Alignof(int[++val]); // Ok<br>
+<br>
+ // Side effects as part of macro expansion are ok.<br>
+ GenTest(val++);<br>
+}<br>
<br>
Modified: cfe/trunk/test/SemaCXX/<u></u>constan<u></u>t-expression-cxx11.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/<u></u>SemaCXX/<u></u>constant-expression-<u></u>cxx11.cpp?<u></u>rev=224465&r1=<u></u>224464&r2=<u></u>224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/SemaCXX/<u></u>constan<u></u>t-expression-cxx11.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/<u></u>constan<u></u>t-expression-cxx11.cpp Wed Dec 17 15:57:17 2014<br>
@@ -1613,7 +1613,8 @@ namespace TypeId {<br>
A &g();<br>
constexpr auto &x = typeid(f());<br>
constexpr auto &y = typeid(g()); // expected-error{{constant expression}} \<br>
- // expected-note{{typeid applied to expression of polymorphic type 'TypeId::A' is not allowed in a constant expression}}<br>
+ // expected-note{{typeid applied to expression of polymorphic type 'TypeId::A' is not allowed in a constant expression}} \<br>
+ // expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}<br>
}<br>
<br>
namespace PR14203 {<br>
<br>
Modified: cfe/trunk/test/SemaCXX/<u></u>runtime<u></u>diag-ppe.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/runtimediag-ppe.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/<u></u>SemaCXX/<u></u>runtimediag-ppe.cpp?<u></u>rev=<u></u>224465&r1=224464&r2=<u></u>224465&<u></u>view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/SemaCXX/<u></u>runtime<u></u>diag-ppe.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/<u></u>runtime<u></u>diag-ppe.cpp Wed Dec 17 15:57:17 2014<br>
@@ -1,4 +1,4 @@<br>
-// RUN: %clang_cc1 -fsyntax-only -verify %s<br>
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value %s<br>
<br>
// Make sure diagnostics that we don't print based on runtime control<br>
// flow are delayed correctly in cases where we can't immediately tell whether<br>
<br>
Modified: cfe/trunk/test/SemaCXX/<u></u>undefin<u></u>ed-internal.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/undefined-internal.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/<u></u>SemaCXX/<u></u>undefined-internal.<u></u>cpp?rev=<u></u>224465&r1=224464&r2=<u></u>224465&<u></u>view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/SemaCXX/<u></u>undefin<u></u>ed-internal.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/<u></u>undefin<u></u>ed-internal.cpp Wed Dec 17 15:57:17 2014<br>
@@ -163,7 +163,7 @@ namespace cxx11_odr_rules {<br>
<br>
// Check that the checks work with unevaluated contexts<br>
(void)sizeof(p(A::used1));<br>
- (void)typeid(p(A::used1)); // xpected-note {{used here}}<br>
+ (void)typeid(p(A::used1)); // expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}} xpected-note {{used here}}<br>
<br>
// Misc other testing<br>
a(A::unused, 1 ? A::used2 : A::used2); // xpected-note {{used here}}<br>
<br>
Modified: cfe/trunk/test/SemaCXX/vararg-<u></u><u></u>non-pod.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/vararg-non-pod.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/<u></u>SemaCXX/<u></u>vararg-non-pod.cpp?<u></u>rev=224465&<u></u>r1=224464&r2=<u></u>224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/SemaCXX/vararg-<u></u><u></u>non-pod.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/vararg-<u></u><u></u>non-pod.cpp Wed Dec 17 15:57:17 2014<br>
@@ -103,7 +103,7 @@ Base &get_base(...);<br>
int eat_base(...);<br>
<br>
void test_typeid(Base &base) {<br>
- (void)typeid(get_base(base)); // expected-warning{{cannot pass object of non-POD type 'Base' through variadic function; call will abort at runtime}}<br>
+ (void)typeid(get_base(base)); // expected-warning{{cannot pass object of non-POD type 'Base' through variadic function; call will abort at runtime}} expected-warning{{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}<br>
(void)typeid(eat_base(base)); // okay<br>
}<br>
<br>
<br>
Modified: cfe/trunk/test/SemaCXX/warn-<u></u>un<u></u>used-result.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-result.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/<u></u>SemaCXX/<u></u>warn-unused-result.<u></u>cpp?rev=<u></u>224465&r1=224464&r2=<u></u>224465&<u></u>view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/SemaCXX/warn-<u></u>un<u></u>used-result.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/warn-<u></u>un<u></u>used-result.cpp Wed Dec 17 15:57:17 2014<br>
@@ -132,7 +132,7 @@ void g() {<br>
D d;<br>
C c;<br>
(void)typeid(f(), c); // Should not warn.<br>
- (void)typeid(f(), d); // expected-warning {{ignoring return value}}<br>
+ (void)typeid(f(), d); // expected-warning {{ignoring return value}} expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}<br>
<br>
// The sizeof expression operand is never evaluated.<br>
(void)sizeof(f(), c); // Should not warn.<br>
<br>
Modified: cfe/trunk/test/SemaCXX/warn-<u></u>un<u></u>used-value-cxx11.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-value-cxx11.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/<u></u>SemaCXX/<u></u>warn-unused-value-<u></u>cxx11.cpp?<u></u>rev=224465&r1=<u></u>224464&r2=<u></u>224465&view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/SemaCXX/warn-<u></u>un<u></u>used-value-cxx11.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/warn-<u></u>un<u></u>used-value-cxx11.cpp Wed Dec 17 15:57:17 2014<br>
@@ -1,5 +1,4 @@<br>
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Wunused-value %s<br>
-// expected-no-diagnostics<br>
<br>
void f() __attribute__((const));<br>
<br>
@@ -13,4 +12,33 @@ auto foo(T) -> decltype(f(), bool()) { /<br>
void g() {<br>
foo(1);<br>
}<br>
+<br>
+void h() {<br>
+ int i = 0;<br>
+ (void)noexcept(++i); // expected-warning {{expression with side effects has no effect in an unevaluated context}}<br>
+ decltype(i++) j = 0; // expected-warning {{expression with side effects has no effect in an unevaluated context}}<br>
}<br>
+<br>
+struct S {<br>
+ S operator++(int);<br>
+ S(int i);<br>
+ S();<br>
+<br>
+ int& f();<br>
+ S g();<br>
+};<br>
+<br>
+void j() {<br>
+ S s;<br>
+ int i = 0;<br>
+ (void)noexcept(s++); // Ok<br>
+ (void)noexcept(i++); // expected-warning {{expression with side effects has no effect in an unevaluated context}}<br>
+ (void)noexcept(i = 5); // expected-warning {{expression with side effects has no effect in an unevaluated context}}<br>
+ (void)noexcept(s = 5); // Ok<br>
+<br>
+ (void)sizeof(s.f()); // Ok<br>
+ (void)sizeof(s.f() = 5); // expected-warning {{expression with side effects has no effect in an unevaluated context}}<br>
+ (void)noexcept(s.g() = 5); // Ok<br>
+}<br>
+<br>
+}<br>
\ No newline at end of file<br>
<br>
Modified: cfe/trunk/test/SemaCXX/warn-<u></u>un<u></u>used-value.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-value.cpp?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/<u></u>SemaCXX/<u></u>warn-unused-value.cpp?<u></u>rev=<u></u>224465&r1=224464&r2=<u></u>224465&<u></u>view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/SemaCXX/warn-<u></u>un<u></u>used-value.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/warn-<u></u>un<u></u>used-value.cpp Wed Dec 17 15:57:17 2014<br>
@@ -39,13 +39,13 @@ namespace test2 {<br>
void method() const {<br>
X* x;<br>
&x[0]; // expected-warning {{expression result unused}}<br>
- }<br>
+ }<br>
};<br>
typedef basic_string<char> string;<br>
- void func(const std::string& str) {<br>
+ void func(const std::string& str) {<br>
str.method(); // expected-note {{in instantiation of member function}}<br>
}<br>
- }<br>
+ }<br>
}<br>
}<br>
<br>
@@ -69,3 +69,30 @@ void f() {<br>
Unused(1, 1); // expected-warning {{expression result unused}}<br>
}<br>
}<br>
+<br>
+namespace std {<br>
+ struct type_info {};<br>
+}<br>
+<br>
+namespace test4 {<br>
+struct Good { Good &f(); };<br>
+struct Bad { virtual Bad& f(); };<br>
+<br>
+void f() {<br>
+ int i = 0;<br>
+ (void)typeid(++i); // expected-warning {{expression with side effects has no effect in an unevaluated context}}<br>
+<br>
+ Good g;<br>
+ (void)typeid(g.f()); // Ok; not a polymorphic use of a glvalue.<br>
+<br>
+ // This is a polymorphic use of a glvalue, which results in the typeid being<br>
+ // evaluated instead of unevaluated.<br>
+ Bad b;<br>
+ (void)typeid(b.f()); // expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}<br>
+<br>
+ // A dereference of a volatile pointer is a side effecting operation, despite<br>
+ // it being a reasonable operation.<br>
+ int * volatile x;<br>
+ (void)sizeof(*x); // expected-warning {{expression with side effects has no effect in an unevaluated context}}<br>
+}<br>
+}<br>
<br>
Modified: cfe/trunk/test/SemaObjCXX/<a href="http://arc-ppe.mm" target="_blank" class="cremed">arc-<u></u><u></u>ppe.mm</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/arc-ppe.mm?rev=224465&r1=224464&r2=224465&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-<u></u>pr<u></u>oject/cfe/trunk/test/<u></u>SemaObjCX<u></u>X/arc-ppe.mm?rev=<u></u>224465&r1=<u></u>224464&r2=224465&<u></u>view=diff</a><br>
==============================<u></u><u></u>==============================<u></u><u></u>==================<br>
--- cfe/trunk/test/SemaObjCXX/<a href="http://arc-ppe.mm" target="_blank" class="cremed">arc-<u></u><u></u>ppe.mm</a> (original)<br>
+++ cfe/trunk/test/SemaObjCXX/<a href="http://arc-ppe.mm" target="_blank" class="cremed">arc-<u></u><u></u>ppe.mm</a> Wed Dec 17 15:57:17 2014<br>
@@ -13,4 +13,4 @@ void test1() { (void)typeid(NP((void*)(i<br>
<br>
class Poly { virtual ~Poly(); };<br>
Poly& P(void*);<br>
-void test2() { (void)typeid(P((void*)(id*)0))<u></u><u></u>; } // expected-error {{pointer to non-const type 'id'}}<br>
+void test2() { (void)typeid(P((void*)(id*)0))<u></u><u></u>; } // expected-error {{pointer to non-const type 'id'}} expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}<br>
<br>
<br>
______________________________<u></u><u></u>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank" class="cremed">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/<u></u>mailm<u></u>an/listinfo/cfe-commits</a><br>
</blockquote></div>