From 0d434efc15ad67c32fda2e15c31f0b8b473f9ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 4 Apr 2018 13:04:40 +0200 Subject: [PATCH] virtualCallInConstructor: Clarify warning message --- lib/checkclass.cpp | 2 +- test/testclass.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 7e98d1abf..be4522962 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2291,7 +2291,7 @@ void CheckClass::getFirstVirtualFunctionCallStack( { const Function *callFunction = callToken->function(); if (callFunction->isVirtual() && (!callFunction->isPure() || !callFunction->hasBody())) { - callstack.push_back(callFunction->token); + callstack.push_back(callFunction->tokenDef); return; } std::map >::const_iterator found = virtualFunctionCallsMap.find(callFunction); diff --git a/test/testclass.cpp b/test/testclass.cpp index 95aec8747..21225030e 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -6348,6 +6348,13 @@ private: "{f();}\n"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Virtual function 'f' is called from constructor 'A()' at line 7.\n", errout.str()); + checkVirtualFunctionCall("class A {\n" + " virtual int f();\n" + " A() {f();}\n" + "};\n" + "int A::f() { return 1; }\n"); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Virtual function 'f' is called from constructor 'A()' at line 3.\n", errout.str()); + checkVirtualFunctionCall("class A\n" "{\n" " A() { A::f(); }\n"