I have this very simple piece of code;
#include <deque>
#include <vector>
using namespace std;
class A
{
public:
A(){};
~A(){};
deque<A> my_array; // vector<A> my_array;
};
int main(void)
{
}
If I compile this code with both g++ and icc/icpc on linux it compiles fine, even with -Wall
it gives no warnings. If I swap the deque to a vector the situation is the same.
I would like to build this code on windows using MSVCC (cl) but unfortunately it throws error c2027:
error C2027: use of undefined type 'A'
If however I change the std::deque
to a std::vector
it compiles fine with Visual Studio 2010.
My question is; is this behaviour to be expected for some reason? If so, why are there differences between compilers or is this a mistake with either g++/icc or MSVCC?
It's undefined behavior (both with std::deque
and with std::vector
,
so whatever an implementation does with it is fine, as far as the
standard is concerned. You're instantiating a standard container with
an incomplete type.
When compiling with g++, -Wall
(and in general, all options starting
with -W
) only concern the language. For library issues, you should be
compiling with -D_GLIBCXX_CONCEPT_CHECKS -D_GLIBCXX_DEBUG
-D_GLIBCXX_DEBUG_PEDANTIC
as well. (If this causes performance
problems, you can remove the last two -D
in optimized builds.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With