Uploaded image for project: 'SonarCFamily'
  1. SonarCFamily
  2. CPP-1398

C++ Rule: Do not invoke virtual functions from constructors or destructors

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.11
    • Component/s: C++, Rules
    • Labels:
      None

      Description

      #include <iostream>
      
      struct B {
        B() {
          std::cout << "B()" << std::endl;
          fun();
        }
      
        virtual void fun() {
          std::cout << "B::fun()" << std::endl;
        }
      };
      
      struct S : B {
        S() {
          std::cout << "S()" << std::endl;
        }
      
        void fun() override {
          std::cout << "S::fun()" << std::endl;
        }
      };
      
      int main() {
        S();
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              alban.auzeill Alban Auzeill
              Reporter:
              evgeny.mandrikov Evgeny Mandrikov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: