Created attachment 17475
Testcase for the bug
The automatic fix for the "destructor is called, class has virtual members but
no virtual destructor" warning can break templated code. Testcase is below & in
attachment, when using -Wall -Wextra with the below code and running clang-tidy
-fix it will add a qualification for to the "my_t->~T();" line, which is
obviously wrong - it should not touch that template, other classes might be
using it.
/* CMakeLists.txt for compile_commands.json
cmake_minimum_required (VERSION 2.8.11)
project (HELLO)
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
add_executable(hello hello.cpp)
*/
/* hello.cpp */
#include <new>
template <typename T>
struct StupidContainer
{
char* data;
T* my_t;
StupidContainer()
{
data = new char[sizeof(T)];
my_t = reinterpret_cast<T*>(data);
new (my_t) T();
}
~StupidContainer()
{
my_t->~T();
delete[] data;
}
};
struct BuggyClass {
virtual void f() {}
~BuggyClass() {}
};
int main()
{
StupidContainer<BuggyClass> foobar;
}
hello.cpp
(712 bytes, application/octet-stream)