brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · e21dedf Raw
40 lines · plain
1.. title:: clang-tidy - portability-template-virtual-member-function2 3portability-template-virtual-member-function4============================================5 6Finds cases when an uninstantiated virtual member function in a template class7causes cross-compiler incompatibility.8 9Upon instantiating a template class, non-virtual member functions don't have10to be instantiated unless they are used. Virtual member function instantiation11on the other hand is unspecified and depends on the implementation of the12compiler.13 14In the following snippets the virtual member function is not instantiated by15GCC and Clang, but it is instantiated by MSVC, so while the snippet is accepted16by the former compilers, it is rejected by the latter.17 18.. code:: c++19 20    template<typename T>21    struct CrossPlatformError {22        virtual ~CrossPlatformError() = default;23 24        static void used() {}25 26        virtual void unused() {27            T MSVCError = this;28        };29    };30 31    int main() {32        CrossPlatformError<int>::used();33        return 0;34    }35 36Cross-platform projects that need to support MSVC on Windows might see compiler37errors because certain virtual member functions are instantiated, which are not38instantiated by other compilers on other platforms. This check highlights such39virtual member functions.40