निम्नलिखित कोड चलाता है static_assert
भले ही मुझे नहीं लगता कि यह करना चाहिए:अजीब व्यवहार
#include <type_traits>
template< typename T >
struct Tmp
{
~Tmp() noexcept(std::is_nothrow_destructible<T>::value) {}
};
struct Foo;
struct Bar
{
// Comment this out for the problem to go away
Tmp<Foo> xx;
// ..or this
Bar() {}
};
struct Foo {};
// This triggers
static_assert(std::is_nothrow_destructible<Foo>::value, "That's odd");
int main()
{
}
साथ जब संकलित:
g++-4.9 -std=c++11 nothrow_destructible_bug.cc
निम्न होता है:
nothrow_destructible_bug.cc:20:1: error: static assertion failed: That's odd
static_assert(std::is_nothrow_destructible<Foo>::value, "That's odd");
^
टेम्पलेट को तुरंत चालू करने के लिए केवल Foo
का उपयोग कैसे करें एक असंबंधित वर्ग में यह noexcept
स्थिति खो देता है? मैंने सोचा कि यह एक कंपाइलर बग था, लेकिन मैंने इसे जीसीसी और क्लैंग दोनों के सभी हाल के संस्करणों के साथ करने की कोशिश की और वे सभी एक ही त्रुटि देने लगते हैं।
क्या आपका मतलब 'is_nothrow_destructible < Bar >' '__othrow_destructible < Foo > 'की बजाय जांचना है? –