This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]