Bug 60873 - C++11: template class with const member and default ctor should fail to compile?
Summary: C++11: template class with const member and default ctor should fail to compile?
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-17 13:00 UTC by sebastian.hegler
Modified: 2014-04-17 14:09 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sebastian.hegler 2014-04-17 13:00:52 UTC
Consider this minimal example:

template <typename T>
struct A {
	const T s_;
	A() = default;
	A(const T& s) : s_(s) {};
};


int main() {
	A<bool> b(true);
};

Now, A has a default ctor which isn't used, but AFAIK simply defining it as default violates the standard, so clearly, my code is buggy. 

I wonder, however, if gcc should reject the code, as ICC 2013 does:
error #409: "A<T>::A() [with T=bool]" provides no initializer for:
            const member "A<T>::s_ [with T=bool]"
  	A<bool> b(true);


Thanks!
Comment 1 Jonathan Wakely 2014-04-17 13:55:27 UTC
ICC is wrong to reject the code, the defaulted default constructor should be defined as deleted according to [class.ctor]/5, so there should only be a diagnostic if you try to use that default constructor.
Comment 2 sebastian.hegler 2014-04-17 14:09:17 UTC
Thanks!