Take the 2-minute tour ×

I've updated my development machine to the just-released 12.04 version of Ubuntu, which apparently gave me a new version of GCC (4.6.3). Now source code that used to compile fine is giving me errors about the compiler-generated assignment operator:

source/local.cpp:1185:59: error: no match for ‘operator=’ in ‘olddata = stype::block_t((*(const oc::json_t*)(& local::database_t::getData(const sdata::uuid_t&, size_t*, sdata::override::type_t)((* & uuid), (& otype), (sdata::override::type_t)1u))), 0)’
source/local.cpp:1185:59: note: candidate is:
source/sdata/block.hpp:13:7: note: sdata::block_t& sdata::block_t::operator=(sdata::block_t&)
source/sdata/block.hpp:13:7: note:   no known conversion for argument 1 from ‘sdata::block_t’ to ‘sdata::block_t&’

So far as I can tell, the compiler-generated operator= should have the signature foo& operator=(const foo&), not foo& operator=(foo&). Is this a bug in this version of GCC, or is my understanding wrong? I can't find any references to this on the GCC bug-tracker, and I can't believe that no one else has run into it.

(Google doesn't make searching for terms that contain an equals sign easy, but with patience I found a single reference to this problem here, discussing GCC 4.6.2.)

share|improve this question

2 Answers 2

An example of a string class i did once:

String& String::operator=(const String& other)  {       
    // checking for self-assignment (pointer-compare)       
    if(this != &other) {
        delete[] s_buffer;
        s_length = other.Length();
        s_buffer = new char[s_length+1];
    return *this;   
share|improve this answer
Thanks, but that doesn't really answer the question. That's the way I think it should be, and the way I've always done it, but GCC now has a different opinion; I'm wondering if GCC is wrong or if I am. –  Head Geek Apr 28 '12 at 13:22
up vote 0 down vote accepted

I don't know what's correct, but GCC's behavior definitely causes problems. I'm calling it a bug.

Oddly enough, it doesn't seem to happen on every class, only a few, so until I can come up with a simple example, I can't really file a bug-report on it.

share|improve this answer

Your Answer


