Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: ollydbg on June 04, 2012, 05:31:01 pm

Title: how to remove those compiler warnings
Post by: ollydbg on June 04, 2012, 05:31:01 pm
Code
include\editorbase.h:36:22: warning: 'virtual void EditorBase::operator=(const EditorBase&)' was hidden [-Woverloaded-virtual]
include\cbeditor.h:70:22: warning:   by 'virtual void cbEditor::operator=(const cbEditor&)' [-Woverloaded-virtual]

I see a lot of such warnings, can we remove them?

Thanks.

MinGW GCC 4.6.3.
Title: Re: how to remove those compiler warnings
Post by: oBFusCATed on June 04, 2012, 06:26:48 pm
There is no point in operator= being virtual. You can try to remove the virtuals and see what happens :)
Title: Re: how to remove those compiler warnings
Post by: MortenMacFly on June 04, 2012, 08:24:05 pm
There is no point in operator= being virtual. You can try to remove the virtuals and see what happens :)
Why not? If you specialise EditorBase you should ensure also to specialise this operator, don't you?
Title: Re: how to remove those compiler warnings
Post by: jarod42 on June 04, 2012, 09:24:09 pm
Code
class DerivedClass : public BaseClass
{
using BaseClass::hiddenFunction;

// other stuff.
};
should remove the warnings.

but I agree that
Code
DerivedClass::operator =(const BaseClass&)
is strange
Title: Re: how to remove those compiler warnings
Post by: oBFusCATed on June 04, 2012, 10:58:03 pm
Why not? If you specialise EditorBase you should ensure also to specialise this operator, don't you?
It is quite more complex.
Here is a thorough explanation: http://icu-project.org/docs/papers/cpp_report/the_assignment_operator_revisited.html (scroll to the virtual assignment).

Quote
Remember clone()? This is the polymorphic copy constructor. If you need polymorphic copy on a group of related classes, you define a virtual function called clone() and every class in the tree overrides it to call his own copy constructor. You can’t just call X’s copy constructor for the same reason you can’t just call X’s assignment operator.

And this is an explanation for the warning: http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9
It happens because the compiler always generates Derived& operator=(Derived &p) no matter if there is Base& operator=(Base &p) (virtual or not).

p.s. I suppose the best we could do is to make operator= an unimplemented private function.
Title: Re: how to remove those compiler warnings
Post by: oBFusCATed on June 05, 2012, 10:23:44 am
p.s. I suppose the best we could do is to make operator= an unimplemented private function.
Turns out that the script bindings are using the operator=, but the versions in EditorBase and cbEditor both throw an exception,
so the second best thing is to remove the virtual keyword in their declarations.

EditorBase:
virtual void operator=(const EditorBase& /*rhs*/){ cbThrow(_T("Can't assign an EditorBase* !!!")); }
cbEditor:
virtual void operator=(const cbEditor& /*rhs*/){ cbThrow(_T("Can't assign an cbEditor* !!!")); }

No inheritance is used here...
Title: Re: how to remove those compiler warnings
Post by: ollydbg on June 07, 2012, 03:47:32 am
p.s. I suppose the best we could do is to make operator= an unimplemented private function.
Turns out that the script bindings are using the operator=, but the versions in EditorBase and cbEditor both throw an exception,
so the second best thing is to remove the virtual keyword in their declarations.

EditorBase:
virtual void operator=(const EditorBase& /*rhs*/){ cbThrow(_T("Can't assign an EditorBase* !!!")); }
cbEditor:
virtual void operator=(const cbEditor& /*rhs*/){ cbThrow(_T("Can't assign an cbEditor* !!!")); }

No inheritance is used here...

Ok, remove the "virtual" keyword, then there is not such warning now.

I see another kind of warning:
Quote
include\cbplugin.h:169:22: warning: 'virtual bool cbPlugin::BuildToolBar(wxToolBar*, int&)' was hidden [-Woverloaded-virtual]
include\cbplugin.h:408:22: warning:   by 'virtual bool cbDebuggerPlugin::BuildToolBar(wxToolBar*)' [-Woverloaded-virtual]

Here:in cbPlugin:
Code
        virtual bool BuildToolBar(wxToolBar* toolBar) = 0;
        virtual bool BuildToolBar(wxToolBar* toolBar, int &priority) { priority = 50; return BuildToolBar(toolBar); }

and in derived class:
Code
virtual bool BuildToolBar(wxToolBar* toolBar);
Title: Re: how to remove those compiler warnings
Post by: oBFusCATed on June 07, 2012, 10:02:11 am
This one should be fixed using "using bla bla".
Title: Re: how to remove those compiler warnings
Post by: ptDev on June 07, 2012, 10:09:32 am
I see another kind of warning:
Quote
include\cbplugin.h:169:22: warning: 'virtual bool cbPlugin::BuildToolBar(wxToolBar*, int&)' was hidden [-Woverloaded-virtual]
include\cbplugin.h:408:22: warning:   by 'virtual bool cbDebuggerPlugin::BuildToolBar(wxToolBar*)' [-Woverloaded-virtual]

Here:in cbPlugin:
Code
        virtual bool BuildToolBar(wxToolBar* toolBar) = 0;
        virtual bool BuildToolBar(wxToolBar* toolBar, int &priority) { priority = 50; return BuildToolBar(toolBar); }

and in derived class:
Code
virtual bool BuildToolBar(wxToolBar* toolBar);

Does cbPlugin::BuildToolBar(wxToolBar* toolBar, int &priority) really need to be virtual? I would fix that by making it non-virtual. Otherwise, you lose the method (or need to re-implement it) in the derived class.
Title: Re: how to remove those compiler warnings
Post by: jarod42 on June 07, 2012, 10:21:55 am
I would suggest to rename the method to avoid future similar warnings for derived class.
Title: Re: how to remove those compiler warnings
Post by: oBFusCATed on June 07, 2012, 10:45:00 am
ptDev: If it is not virtual how would you change the priority?
jarod42: This is an option, too, but someone should come up with a good name - always a hard task.
Title: Re: how to remove those compiler warnings
Post by: jarod42 on June 07, 2012, 01:21:27 pm
Code
virtual int getPriority() const { return 50; }
or
Code
virtual void changePriority(int& priority) { priority = 50; }

and then

Code
bool BuildToolBarAndSetPriority(wxToolBar* toolBar, int &priority)
{
  changePriority(priority);
  return BuildToolBar(toolBar);
}

should be cleaner, I think.
Title: Re: how to remove those compiler warnings
Post by: ollydbg on June 15, 2012, 08:05:08 am
Some days later, I rethink it. Now. follow jarod42's advice
The code
Code
ToolbarInfo MainFrame::DoAddPluginToolbar(cbPlugin* plugin)
{
    ToolbarInfo info;
    info.toolbar = Manager::Get()->CreateEmptyToolbar();
    info.priority = 50;
    if (plugin->BuildToolBar(info.toolbar, info.priority))
    {
        SetToolBar(0);
        InitToolbar(info.toolbar);

becomes like below:

In base class, add a function:
Code
virtual int GetToolBarPriority() { return 50; }

If some derived plugin class need to implement some other priority values, they should override their own.

Code
ToolbarInfo MainFrame::DoAddPluginToolbar(cbPlugin* plugin)
{
    ToolbarInfo info;
    info.toolbar = Manager::Get()->CreateEmptyToolbar();
    //info.priority = 50;
    if (plugin->BuildToolbar(info.toolbar))
    {
        info.priority = plugin->GetToolBarPriority();
        SetToolBar(0);
        InitToolbar(info.toolbar);

Is it right?
Title: Re: how to remove those compiler warnings
Post by: oBFusCATed on June 15, 2012, 09:31:12 am
Try it and see if it works...
Title: Re: how to remove those compiler warnings
Post by: ollydbg on June 15, 2012, 09:48:55 am
Try it and see if it works...
I test it, and it works just fine.

Is the function name: GetToolBarPriority()  OK?

Ok to commit? (Include the change that remove the "virtual" keyword in operator=).
Title: Re: how to remove those compiler warnings
Post by: oBFusCATed on June 15, 2012, 09:55:13 am
Please commit them as separate changes and, also please increase the SDK version number in cbplugin.h and remember to fix all plugins to use the new API.
Title: Re: how to remove those compiler warnings
Post by: ollydbg on June 15, 2012, 10:20:48 am
Done in rev 8048 and rev 8049. Thanks for all your guy's suggestions!!!
Title: Re: how to remove those compiler warnings
Post by: ollydbg on June 17, 2012, 07:33:21 am
There are still some warnings like:
Code
[ 35.4%] g++.exe -Wall -g -pipe -mthreads -fmessage-length=0 -fexceptions -Winvalid-pch -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DcbDEBUG -DCB_PRECOMP -DWX_PRECOMP -DwxUSE_UNICODE  -Woverloaded-virtual -DEXPORT_LIB -DEXPORT_EVENTS -DWXMAKINGDLL_PROPGRID -DwxPG_USE_WXMODULE=0 -DWXMAKINGDLL_SCI    -iquote.objs\include -I.objs\include -I. -IE:\code\cb\wx\wxWidgets-2.8.12\include -IE:\code\cb\wx\wxWidgets-2.8.12\contrib\include -IE:\code\cb\wx\wxWidgets-2.8.12\lib\gcc_dll\mswu -Isdk\wxscintilla\include -Isdk\wxpropgrid\include -Iinclude\tinyxml -Iinclude -Iinclude\tinyxml -Iinclude\scripting\bindings -Iinclude\scripting\include -Iinclude\scripting\sqplus -Iinclude\mozilla_chardet -Isdk\wxpropgrid\include  -c sdk\scripting\bindings\sc_progress.cpp -o .objs\sdk\scripting\bindings\sc_progress.o
E:\code\cb\wx\wxWidgets-2.8.12\include/wx/generic/progdlgg.h:55:17: warning: 'virtual bool wxProgressDialog::Update(int, const wxString&, bool*)' was hidden [-Woverloaded-virtual]
sdk\scripting\bindings\sc_progress.cpp:42:14: warning:   by 'bool ProgressDialog::Update(int, const wxString&)' [-Woverloaded-virtual]
E:\code\cb\wx\wxWidgets-2.8.12\include/wx/generic/progdlgg.h:62:18: warning: 'virtual void wxProgressDialog::Update()' was hidden [-Woverloaded-virtual]
sdk\scripting\bindings\sc_progress.cpp:42:14: warning:   by 'bool ProgressDialog::Update(int, const wxString&)' [-Woverloaded-virtual]

Code
class ProgressDialog : public wxProgressDialog
{
    public:
        ProgressDialog()
            : wxProgressDialog(_("Progress"),
                                _("Please wait while operation is in progress..."),
                                100, 0,
                                wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT)
        {
        }

        ~ProgressDialog()
        {
        }

        ProgressDialog& operator=(const ProgressDialog&)
        {
            cbThrow(_T("ProgressDialog copy constructor should never be called!"));
        }

        bool Update(int value, const wxString& newmsg)
        {
            return wxProgressDialog::Update(value, newmsg, 0);
        }
};

and

Code
class WXDLLEXPORT wxProgressDialog : public wxDialog
{
DECLARE_DYNAMIC_CLASS(wxProgressDialog)
public:
   /* Creates and displays dialog, disables event handling for other
       frames or parent frame to avoid recursion problems.
       @param title title for window
       @param message message to display in window
       @param maximum value for status bar, if <= 0, no bar is shown
       @param parent window or NULL
       @param style is the bit mask of wxPD_XXX constants from wx/defs.h
   */
   wxProgressDialog(const wxString &title, wxString const &message,
                    int maximum = 100,
                    wxWindow *parent = NULL,
                    int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE);
   /* Destructor.
       Re-enables event handling for other windows.
   */
   virtual ~wxProgressDialog();

   /* Update the status bar to the new value.
       @param value new value
       @param newmsg if used, new message to display
       @returns true if ABORT button has not been pressed
   */
   virtual bool Update(int value, const wxString& newmsg = wxEmptyString, bool *skip = NULL);

    /* Switches the dialog to use a gauge in indeterminate mode and calls
       wxGauge::Pulse() to show to the user a bit of progress */
    virtual bool Pulse(const wxString& newmsg = wxEmptyString, bool *skip = NULL);

    // Must provide overload to avoid hiding it (and warnings about it)
    virtual void Update() { wxDialog::Update(); }

Any ideas to handle this issue? Thanks.
Title: Re: how to remove those compiler warnings
Post by: jarod42 on June 18, 2012, 12:40:49 pm
Code
class DerivedClass : public BaseClass
{
using BaseClass::hiddenFunction;

// other stuff.
};
should remove the warnings.

but as seeing the code,
Code
ProgressDialog::update
may be removed.

Note also that
Code
ProgressDialog::operator =
should be private without implementation (or with the 'delete' keyword with C++11).
Title: Re: how to remove those compiler warnings
Post by: MortenMacFly on June 18, 2012, 08:00:25 pm
...be careful here, this is a script binding. Squirrel needs an equality operator exactly as it is setup. So this might look weird, but its a requirement. You better don't change it, but we should comment these workarounds in the code.