- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I've run into a compile error with icpc 16.0.2 that I think is incorrect. If I have an anonymous union in a class the compiler only considers it intialized if I initialize the first data member of the union. That's too strict. The test case below demonstrates the error.
// Test file demostrating what I think is an invalid compile error.
//
//> icpc --version
//icpc (ICC) 16.0.2 20160204
//Copyright (C) 1985-2016 Intel Corporation. All rights reserved.
//
//> icpc -std=c++11 bar.cc
//bar.cc(20): error: constexpr constructor fails to initialize an anonymous union (defined at line 7)
// { }
// ^
class data_type
{
private:
// Reordering the data members so that m_index is first allows the
// constructor to initialize m_index without error, but then a constructor
// initializing m_data would have the same error.
union
{
void* m_data;
int m_index;
};
int m_epoch;
public:
constexpr data_type(void) noexcept
:
m_index(99), // this initialization results in error
// m_data(nullptr), // this initialization allows compilation to succeed
m_epoch(99)
{ }
};
int main()
{
data_type d;
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Timmie,
Thanks, this is a bug and I'll file the issue with the developers and will keep you updated on the progress of the issue as well, appreciate much.
Kittur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HI Timmie,
The issue is already being worked on by the product team and I'll let you know as soon as the release is out. Thanks for catching this and the obvious workaround is to initialize the first field instead, until the release with the fix is out - appreciate much.
Regards,
Kittur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the quick response and confirmation of the bug.
The workaround we employed in our code was to ifdef the constructor with __INTEL_COMPILER and if the intel compiler is being used we remove the constexpr qualifier from the constructor. The reason for this approach is that one of our classes has two constexpr constructors, each initializing a different field of the union, so no ordering of the union members was satisfactory.
I look forward to when the release with the bug fix is available.
Thanks again,
Timmie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Got it, thanks for letting me know Timmie. Sure, I'll update you as soon as the release with the fix is out. Appreciate your patience again, till then.
Regards,
Kittur
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page