dbTalk Databases Forums  

Beta 2: Warning when compiling program in FC4 GCC4

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss Beta 2: Warning when compiling program in FC4 GCC4 in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Carlos M. Gutierrez
 
Posts: n/a

Default Beta 2: Warning when compiling program in FC4 GCC4 - 07-21-2005 , 11:58 AM







I just installed 2.0.0 Beta 2 on a Fedora Core 4 system. I am getting the
following warning:

/usr/local/include/mysql++/noexceptions.h: In member function
mysqlpp::NoExceptions& mysqlpp::NoExceptions:perator=(const
mysqlpp::NoExceptions&):
/usr/local/include/mysql++/noexceptions.h:129: warning: no return
statement in function returning non-void


And the offending line of code seems to be at the end of:


private:
OptionalExceptions& assoc_;
bool exceptions_were_enabled_;

// Hidden assignment operator and copy ctor, because we should not
// be copied.
NoExceptions(const NoExceptions&);
NoExceptions& operator=(const NoExceptions&) { }

As defined in that last line, operator= should return a NoExceptions
reference but it does not. I am not an expert programmer, should the "{
}" just become ";" ?

If not, what should I do? I am including mysqlpp as follows:

#include <mysql++.h>

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Carlos M. Gutierrez
 
Posts: n/a

Default Re: Beta 2: Warning when compiling program in FC4 GCC4 - 07-21-2005 , 12:07 PM








On Thu, 21 Jul 2005, Carlos M. Gutierrez wrote:

Quote:
I just installed 2.0.0 Beta 2 on a Fedora Core 4 system. I am getting the
following warning:

/usr/local/include/mysql++/noexceptions.h: In member function
mysqlpp::NoExceptions& mysqlpp::NoExceptions:perator=(const
mysqlpp::NoExceptions&):
/usr/local/include/mysql++/noexceptions.h:129: warning: no return statement
in function returning non-void
BTW, I am compiling with -Wall as in:

g++ -g -Wall -fPIC -I/usr/local/mysql/include/mysql
-I/usr/local/include/mysql++ -c -o TFixcountsApp.o TFixcountsApp.cc

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
Chris Frey
 
Posts: n/a

Default Re: Beta 2: Warning when compiling program in FC4 GCC4 - 07-21-2005 , 05:12 PM



On Thu, Jul 21, 2005 at 12:58:19PM -0400, Carlos M. Gutierrez wrote:
Quote:
private:
OptionalExceptions& assoc_;
bool exceptions_were_enabled_;

// Hidden assignment operator and copy ctor, because we should not
// be copied.
NoExceptions(const NoExceptions&);
NoExceptions& operator=(const NoExceptions&) { }

As defined in that last line, operator= should return a NoExceptions
reference but it does not. I am not an expert programmer, should the "{
}" just become ";" ?
Yes.

The latest SVN version has this "fixed", but incorrectly in my
opinion. It currently just returns *this, whereas I don't think
operator=() should be defined at all, just declared.

- Chris


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #4  
Old   
Warren Young
 
Posts: n/a

Default Re: Beta 2: Warning when compiling program in FC4 GCC4 - 07-21-2005 , 07:29 PM



Chris Frey wrote:
Quote:
The latest SVN version has this "fixed", but incorrectly in my
opinion. It currently just returns *this, whereas I don't think
operator=() should be defined at all, just declared.
Does this actually suppress the compiler-generated version?

Regardless, operator= does normally return *this, so the only problem
with doing it this way is that it generates a tiny bit more code than if
it were only declared and not defined.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #5  
Old   
Chris Frey
 
Posts: n/a

Default Re: Beta 2: Warning when compiling program in FC4 GCC4 - 07-21-2005 , 09:46 PM



On Thu, Jul 21, 2005 at 06:29:03PM -0600, Warren Young wrote:
Quote:
Chris Frey wrote:

The latest SVN version has this "fixed", but incorrectly in my
opinion. It currently just returns *this, whereas I don't think
operator=() should be defined at all, just declared.

Does this actually suppress the compiler-generated version?
Yep.

tmp $ cat oe.cc
class A
{
private:
A(const A&);
A& operator=(const A&);

int i;

public:
A() : i(5) {}
};

int main()
{
A a, b;
a = b;
return 0;
}

tmp $ g++ -Wall -o oe oe.cc
oe.cc: In function `int main()':
oe.cc:5: error: `A& A:perator=(const A&)' is private
oe.cc:16: error: within this context


This also flags an error for derived classes too. The thing you want
to be careful about is if you're doing virtual operator=(), with a
base class as the const reference argument. For example:

class A {
public:
virtual A& operator=(const A&); // this overrides the default
};

class B : public A {
public:
virtual A& operator=(const A&); // this does not
// there is a hidden, automatic, operator=(const B&) here too!
// and the automatic operator=() will call the user-defined
// A:perator=() for us.
};



Quote:
Regardless, operator= does normally return *this, so the only problem
with doing it this way is that it generates a tiny bit more code than if
it were only declared and not defined.
I think all we care about is the compiler warning, so no copy is done
accidentally.

- Chris


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.