- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[cpp]struct A {
int a = 10;
};
struct S {
union {
A a;
};
};
int main() {
S s;
return 0;
}[/cpp]
GCC gives an error:
error: use of deleted function 'S::S()'
ICC 13 update 1 on win compiles the code, but it mustn't because there is shadow using of A::A() ctor when union is not initialized.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
$ g++ bj.cpp
bj.cpp:3:11: error: ISO C++ forbids initialization of member ‘a’
bj.cpp:3:11: error: making ‘a’ static
bj.cpp:3:11: error: ISO C++ forbids in-class initialization of non-const static
member ‘a’
$ icl bj.cpp
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Ve
rsion 13.1.0.149 Build 20130118
Copyright (C) 1985-2013 Intel Corporation. All rights reserved.
bj.cpp
bj.cpp(3): error: data member initializer is not allowed
int a = 10;
^
compilation aborted for bj.cpp (code 2)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's C++11 feature.
Please, try with -std=c++0x and /Qstd=c++0x.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Since we have only partially implemented c++11 non static data member initialization (i.e. we only allow scalar iniitialization) I think the example code is initialized correctly and therefore no error is needed or issued.
Judy

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page