diff options
Diffstat (limited to 'compilerplugins/clang/sequenceloop.cxx')
-rw-r--r-- | compilerplugins/clang/sequenceloop.cxx | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/compilerplugins/clang/sequenceloop.cxx b/compilerplugins/clang/sequenceloop.cxx index 7f14d6c4d951..9a620f26be52 100644 --- a/compilerplugins/clang/sequenceloop.cxx +++ b/compilerplugins/clang/sequenceloop.cxx @@ -63,6 +63,12 @@ bool SequenceLoop::VisitCXXForRangeStmt(CXXForRangeStmt const* forStmt) if (!tc2.LvalueReference().Const()) return true; + // bit awkward, but the only way to sniff out if we're being passed a value or a reference + auto rangeDeclStmt = dyn_cast<DeclStmt>(forStmt->getRangeStmt()); + auto rangeVarDecl = dyn_cast<VarDecl>(rangeDeclStmt->getSingleDecl()); + if (rangeVarDecl->getType()->isRValueReferenceType()) + return true; + report(DiagnosticsEngine::Warning, ("use std::as_const, or otherwise make the for-range-initializer expression const, to" " avoid creating a copy of the Sequence"), |