From 3022d74801a3bca34fa9fb79d3aff1b090fbc14f Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 19 Jan 2017 11:14:55 +0100 Subject: [PATCH] Do not suggest pass by reference for std::initializer_list --- lib/checkother.cpp | 2 +- test/testother.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ed332119c..3c06188f3 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1455,7 +1455,7 @@ void CheckOther::checkPassByReference() const Token* const tok = var->typeStartToken(); if (var->isStlStringType()) { ; - } else if (var->isStlType() && Token::Match(tok, "std :: %type% <") && !Token::simpleMatch(tok->linkAt(3), "> ::")) { + } else if (var->isStlType() && Token::Match(tok, "std :: %type% <") && !Token::simpleMatch(tok->linkAt(3), "> ::") && tok->strAt(2) != "initializer_list") { ; } else if (var->type() && !var->type()->isEnumType()) { // Check if type is a struct or class. // Ensure that it is a large object. diff --git a/test/testother.cpp b/test/testother.cpp index f70097951..9dbe1016f 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1386,6 +1386,9 @@ private: check("void f(const std::streamoff pos) {}"); ASSERT_EQUALS("", errout.str()); + check("void f(std::initializer_list i) {}"); + ASSERT_EQUALS("", errout.str()); + // #5824 check("void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}"); ASSERT_EQUALS("", errout.str());