summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-06-02 15:22:39 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-06-05 21:17:55 +0200
commit0763d8413ed87d17fe2510608e2d7399834a5388 (patch)
tree075528a2e4c05b9081f497a4163f03eedf9321da /compilerplugins
parentf749e7d705e38bd9f076334ad978638272e0f361 (diff)
Reduce loplugin:redundantcast warnings about functional casts even futher
Change-Id: I8884e17c453831e048c43012ee176093c5b2f99e
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/redundantcast.cxx9
-rw-r--r--compilerplugins/clang/test/redundantcast.cxx8
2 files changed, 12 insertions, 5 deletions
diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx
index 87bed77a22f8..4e79415c4850 100644
--- a/compilerplugins/clang/redundantcast.cxx
+++ b/compilerplugins/clang/redundantcast.cxx
@@ -539,11 +539,12 @@ bool RedundantCast::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr const * exp
//
// std::initializer_list<Foo>{bar, baz}
//
- // ), and only to cases where the sub-expression already is a prvalue (and
- // thus the cast is unlikely meant to create a temporary):
+ // ), and only to cases where the sub-expression already is a prvalue of
+ // non-class type (and thus the cast is unlikely meant to create a
+ // temporary):
auto const sub = compat::getSubExprAsWritten(expr);
- if (sub->getValueKind() != VK_RValue || isa<InitListExpr>(sub)
- || isa<CXXStdInitializerListExpr>(sub))
+ if (sub->getValueKind() != VK_RValue || expr->getType()->isRecordType()
+ || isa<InitListExpr>(sub) || isa<CXXStdInitializerListExpr>(sub))
{
return true;
}
diff --git a/compilerplugins/clang/test/redundantcast.cxx b/compilerplugins/clang/test/redundantcast.cxx
index 22130b32196c..78624810fda9 100644
--- a/compilerplugins/clang/test/redundantcast.cxx
+++ b/compilerplugins/clang/test/redundantcast.cxx
@@ -253,7 +253,7 @@ void testStaticCast() {
// class prvalue, non-const:
(void) static_cast<S>(nsr()); // expected-error {{static_cast from 'S' prvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
- /* => */ (void) S(nsr()); //TODO: expected-error {{redundant functional cast from 'S' to 'S' [loplugin:redundantcast]}}
+ /* => */ (void) S(nsr());
// (void) static_cast<S &>(nsr());
(void) static_cast<S &&>(nsr());
(void) static_cast<S const>(nsr()); // expected-error {{static_cast from 'S' prvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
@@ -273,6 +273,11 @@ void testStaticCast() {
(void) static_cast<S const &&>(csr());
}
+void testFunctionalCast() {
+ (void) int(nir()); // expected-error {{redundant functional cast from 'int' to 'int' [loplugin:redundantcast]}}
+ (void) S(nsr());
+}
+
void testCStyleCast() {
Enum1 e = (Enum1)Enum1::X; // expected-error {{redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]}}
(void)e;
@@ -281,6 +286,7 @@ void testCStyleCast() {
int main() {
testConstCast();
testStaticCast();
+ testFunctionalCast();
testCStyleCast();
}