From: Eli Friedman Date: Mon, 24 Sep 2012 23:02:26 +0000 (+0000) Subject: Handle C++ functional casts in a similar way to C-style casts in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6319917b5021e9602389b49ca4f245d235e9b90a;p=clang Handle C++ functional casts in a similar way to C-style casts in unused expression warnings. . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164569 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 74308a0093..30342585c8 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -2019,6 +2019,7 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, R1 = getSourceRange(); return true; } + case CXXFunctionalCastExprClass: case CStyleCastExprClass: { // Ignore an explicit cast to void unless the operand is a non-trivial // volatile lvalue. diff --git a/test/SemaCXX/unused.cpp b/test/SemaCXX/unused.cpp index 54898c828e..b9877a1ba4 100644 --- a/test/SemaCXX/unused.cpp +++ b/test/SemaCXX/unused.cpp @@ -34,3 +34,15 @@ namespace derefvolatile { (void)y; // don't warn here, because it's a common pattern. } } + +// +namespace AnonObject { + struct Foo { + Foo(const char* const message); + ~Foo(); + }; + void f() { + Foo("Hello World!"); // don't warn + int(1); // expected-warning {{expression result unused}} + } +}