diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-10-21 11:58:39 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-10-21 15:50:35 +0200 |
commit | 767092fe2cab4a8b28426a6b2b1c752277fc7df6 (patch) | |
tree | d243b943d804167f1062efa8cf1a3ef59b1e47ca /compilerplugins | |
parent | 57a03d7a52680e7177d07efe364785d53bf0a6df (diff) |
loplugin:referencecasting look for a new pattern
Change-Id: Ib7ded8db2c513909159f0876389f63b60082a529
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141618
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/referencecasting.cxx | 11 | ||||
-rw-r--r-- | compilerplugins/clang/test/referencecasting.cxx | 5 |
2 files changed, 15 insertions, 1 deletions
diff --git a/compilerplugins/clang/referencecasting.cxx b/compilerplugins/clang/referencecasting.cxx index dae0ce89d81f..2cc4a627bba9 100644 --- a/compilerplugins/clang/referencecasting.cxx +++ b/compilerplugins/clang/referencecasting.cxx @@ -151,7 +151,7 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) { if (auto castExpr = dyn_cast<CastExpr>(constructorArg0)) { - constructorArg0 = castExpr->getSubExpr(); + constructorArg0 = castExpr->getSubExprAsWritten(); continue; } if (auto matTempExpr = dyn_cast<MaterializeTemporaryExpr>(constructorArg0)) @@ -174,6 +174,15 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) constructorArg0 = parenExpr->getSubExpr(); continue; } + // for the "uno::Reference<X>(*this, UNO_QUERY)" case + if (auto unaryOper = dyn_cast<UnaryOperator>(constructorArg0)) + { + if (unaryOper->getOpcode() == UO_Deref) + { + constructorArg0 = unaryOper->getSubExpr(); + continue; + } + } argType = constructorArg0->getType(); break; } diff --git a/compilerplugins/clang/test/referencecasting.cxx b/compilerplugins/clang/test/referencecasting.cxx index 1f3480dbee5b..beb69cc86616 100644 --- a/compilerplugins/clang/test/referencecasting.cxx +++ b/compilerplugins/clang/test/referencecasting.cxx @@ -206,6 +206,11 @@ class Foo : public cppu::WeakImplHelper<css::lang::XComponent, css::io::XInputSt return css::uno::Reference<css::io::XInputStream>(static_cast<css::io::XInputStream*>(this), css::uno::UNO_QUERY); } + css::uno::Reference<css::io::XInputStream> bar3() + { + // expected-error@+1 {{the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]}} + return css::uno::Reference<css::io::XInputStream>(*this, css::uno::UNO_QUERY); + } }; } |