When I try to copy one instance of a class to another instance of the same class, the compiler has a hissy fit. It occurs when the object in the class is a bitfield and is volatile. One of the error messages I find humorous. It mentions a const volatile. I've never seen one of those before.
Here's a simple project. It consists of main.cpp only. I define the simple class, create 2 instances of it, and try to copy one to the other using the good old assignment operator '='. It only fails if I use gcc with the -std=gnu++11. It only fails if I declare the data member to be volatile and a bitfield.
I have seen this problem before, or something similar, with gcc. Motorola's compiler sees no problem.
Here is main.cpp and also the project template.
// This program copies one instance of a class to another instance of the same class. // Gcc with -std=gnu++11 fails if the object in the class is a bitfield and is volatile. // If I remove the -std=gnu++11 from the project, it compiles okay. // Microsoft's compiler thinks it's okay too. This makes 3 of us. ;) // I'm using Atmel Studio 6.2. // I put -std=gnu++11 in the compiler options Miscellaneous category. class Class_with_volatile { struct Control { unsigned char software : 1; unsigned char reserved : 7; }; // If you comment out the following volatile and uncomment the non-volatile, it compiles okay. volatile Control control; // This doesn't work with gcc ++11. // Control control; // This works. }; int main(void) { Class_with_volatile class_with_volatile_1; Class_with_volatile class_with_volatile_2; class_with_volatile_2 = class_with_volatile_1; // Won't compile with -std=gnu++11 and volatile bitfield object. while(1) { volatile int count; count++; } }