This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[Warning] When passing const reference and default value
- From: Mathieu Malaterre <mmalater at nycap dot rr dot com>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 01 Nov 2004 17:09:34 -0500
- Subject: [Warning] When passing const reference and default value
Hello,
I was just wondering should the following code (*) produce a warning
when being compiled or not? I would tend to say yes, it should. If not
could someone explain me how the compiler could produce a string
reference out of the default const char * value ?
Thanks
Mathieu
(*)
#include <string>
#include <iostream>
void foo(std::string const & s = "bar" )
{
std::cout << s << std::endl;
}
int main()
{
foo( );
return 0;
}
//////////////////
// compilation line:
g++ -W -Wall -pedantic warn.cxx