Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove virtual calls in constructor/destructor #1428

Merged
merged 8 commits into from
May 9, 2023

Conversation

hainest
Copy link
Contributor

@hainest hainest commented May 9, 2023

Not technically bugs, but it's better to be explicit to remove any ambiguity. Found using cppcheck's virtualCallInConstructor.

Found using cppcheck:

common/src/addrtranslate-win.C:49:17: style: Virtual function 'init' is called from constructor 'AddressTranslateWin(PID pid,PROC_HANDLE phandle)' at line 168. Dynamic binding is not used. [virtualCallInConstructor]
   virtual bool init();
Found using cppcheck:

common/src/NodeIterator.h:293:18: style: Virtual function 'inc' is
called from constructor
'NodeIteratorPredicateObj(Graph::NodePredicate::Ptr
p,NodeIterator&b,NodeIterator&e)' at line 331. Dynamic binding is not
used. [virtualCallInConstructor]
Found using cppcheck:

common/src/NodeIterator.h:352:18: style: Virtual function 'inc' is
called from constructor
'NodeIteratorPredicateFunc(Graph::NodePredicateFunc
p,void*u,NodeIterator&b,NodeIterator&e)' at line 394. Dynamic binding is
not used. [virtualCallInConstructor]
Found using cppcheck:

instructionAPI/src/InstructionDecoder-x86.h:74:49: style: Virtual function 'setMode' is called from constructor 'InstructionDecoder_x86(Architecture a)' at line 144. Dynamic binding is not used. [virtualCallInConstructor]
                INSTRUCTION_EXPORT virtual void setMode(bool is64);
                                                ^
instructionAPI/src/InstructionDecoder-x86.C:144:28: note: Calling setMode
      if(a == Arch_x86_64) setMode(true);
                           ^
instructionAPI/src/InstructionDecoder-x86.h:74:49: note: setMode is a virtual function
                INSTRUCTION_EXPORT virtual void setMode(bool is64);
Found using cppcheck:

parseAPI/h/CFGFactory.h:117:18: style: Virtual function 'free_block' is called from destructor '~CFGFactory()' at line 92. Dynamic binding is not used. [virtualCallInConstructor]
    virtual void free_block(Block * b);
                 ^
parseAPI/src/CFGFactory.C:92:5: note: Calling destroy_block
    destroy_block(b);
    ^
parseAPI/src/CFGFactory.C:182:5: note: Calling free_block
    free_block(b);
    ^
parseAPI/h/CFGFactory.h:117:18: note: free_block is a virtual function
    virtual void free_block(Block * b);
Found using cppcheck:

parseAPI/h/CFGFactory.h:116:18: style: Virtual function 'free_func' is called from destructor '~CFGFactory()' at line 95. Dynamic binding is not used. [virtualCallInConstructor]
    virtual void free_func(Function * f);
                 ^
parseAPI/src/CFGFactory.C:95:5: note: Calling destroy_func
    destroy_func(f);
    ^
parseAPI/src/CFGFactory.C:172:4: note: Calling free_func
   free_func(f);
   ^
parseAPI/h/CFGFactory.h:116:18: note: free_func is a virtual function
    virtual void free_func(Function * f);
Found using cppcheck:

proccontrol/src/freebsd.C:1046:17: warning: Member variable 'freebsd_thread::is_exited' is not initialized in the constructor. [uninitMemberVar]
freebsd_thread::freebsd_thread(int_process *p, Dyninst::THR_ID t, Dyninst::LWP l)
                ^
proccontrol/src/freebsd.h:122:17: style: Virtual function 'getEventQueue' is called from destructor '~freebsd_process()' at line 795. Dynamic binding is not used. [virtualCallInConstructor]
    virtual int getEventQueue();
                ^
proccontrol/src/freebsd.C:795:22: note: Calling getEventQueue
    int eventQueue = getEventQueue();
                     ^
proccontrol/src/freebsd.h:122:17: note: getEventQueue is a virtual function
    virtual int getEventQueue();
@hainest hainest added the code cleanup Bring the code up to modern standards or remove deprecated features label May 9, 2023
@hainest hainest requested a review from kupsch May 9, 2023 16:45
@hainest hainest self-assigned this May 9, 2023
@hainest hainest merged commit 85fb0f9 into master May 9, 2023
@hainest hainest deleted the fix_virtual_call_in_constructor branch May 9, 2023 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code cleanup Bring the code up to modern standards or remove deprecated features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants