Foo(300) = Foo(500); Why does a compiler compile that?

From: Alex Vinokur (alexvn_at_big-foot.com)
Date: 01/30/05


Date: Sun, 30 Jan 2005 11:48:10 +0200

Compiler GNU gpp.exe (GCC) 3.4.1

Foo(300) = Foo(500); // Foo(300) is const. Why does a compiler compile that?

------ foo.cpp ------
struct Foo
{
 explicit Foo(int) {}

 Foo& operator= (const Foo&)
 {
   return *this;
 }
};

int main()
{
Foo var1(100);
const Foo var2(200);

  var1 = Foo(500);
  Foo(300) = Foo(500); // Foo(300) is const. Why does a compiler compile that?
  // var2 = Foo(500); // A compiler doesn't compile that

  return 0;
}
---------------------

-- 
 Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn


Relevant Pages