With the following code:
struct Foo {};
template<class T>
void Destruct(T *obj)
{
obj->~T();
}
int main(int /*argc*/, const char * /*argv*/[])
{
char buffer[sizeof(Foo)];
Destruct((Foo*)buffer);
return 0;
}
Visual Studio 2015 will issue a warning for unreferenced parameter:
warning C4100: 'obj': unreferenced formal parameter
Is this a legitimate warning or a bug in the compiler?
Online Repro here: https://godbolt.org/z/xq96GU
Edit: updated the sample to a full example
Edit 2: you need to enable /W4 for this to occur in visual studio 2015, /W3 is not enough; Also confirmed this does not occur in 2017.
Edit 3: For the CNR, here is the output from command line with all arguments used to repro:
>"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe" /W4 test.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
test.cpp
test.cpp(4): warning C4100: 'obj': unreferenced formal parameter
test.cpp(12): note: see reference to function template instantiation 'void Destruct<Foo>(T *)' being compiled
with
[
T=Foo
]
Microsoft (R) Incremental Linker Version 14.00.24215.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
Edit 4 Added sample reproduction on godbolt.org Edit 5 Actually /W4 is enough to reproduce, /Wall is not necessary