c++ – MSVC 2019 static analysis: C26434 function hides a non-virtual function – which is a constructor


I have a class template derived from another class template, derived from a third class template. All have an empty default constructor, and an empty virtual destructor.

Using MSVC 2019, compiling for x64, c++17

When I run Visual Studio’s built-in static analysis, I get the following 2 warnings:

Warning C26434 Function 'Derived1<T,T,double>::Derived1<T,T,double>' hides a non-virtual function 'Base<T,T,double>::Base<T,T,double>'.

Warning C26434 Function 'Derived2<T,T,double>::Derived2<T,T,double>' hides a non-virtual function 'Derived1<T,T,double>::Derived1<T,T,double>'.

Might be of note that I don’t see them when compiling in Debug, only Release (/O2)
This also happens for a second existing class hierarchy.

I was not aware that it was even possible to hide a constructor, which could never be virtual to begin with?

Are these some weird false positives or is there something sinister going on?

#include <iostream>

template <typename A, typename B, typename C>
class Base
{
public:
    Base() {}
    virtual ~Base() {}
};

template <typename A, typename B, typename C>
class Derived1 : public Base<A,B,C>
{
public:
    Derived1() {}
    virtual ~Derived1() {}
};

template <typename A, typename B, typename C>
class Derived2 : public Derived1<A,B,C>
{
public:
    Derived2() {}
    virtual ~Derived2() {}
};

class T {};

int main() {
    Derived2<T,T,double> d;
    std::cout << sizeof(d) << "\n";  // to prevent optimizing away the instantiation
    return 0;
}

https://godbolt.org/z/8P5ef7ahd

Leave a Reply

Your email address will not be published. Required fields are marked *