[Bug c++/46382] New: constexpr vs. static_assert in constexpr ctors
bkoz at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Nov 8 22:08:00 GMT 2010
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46382
Summary: constexpr vs. static_assert in constexpr ctors
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: bkoz@gcc.gnu.org
The current implementation has the nice feature that in addition to a return
statement, a constexpr function can also contain the following:
1) typedefs
2) static_asserts
Both make sense. Hurray! However, this is different for member functions and
so-called "special member functions." In particular, constructors. Here's an
example of something that would be nice if it worked.
---
#include <type_traits>
template<typename _Tp>
struct A
{
int _M_i;
constexpr A(int i) : _M_i(i)
{
#if BUT_WE_WANT_IT_HERE_TOO
static_assert(std::is_fundamental<_Tp>::value, "no"); // not really
#endif
}
constexpr bool notwhatyouwant()
{
typedef _Tp type; // ok
static_assert(std::is_fundamental<_Tp>::value, "no"); // ok
return _M_i == 0;
}
};
int main()
{
constexpr A<int> obj(5);
constexpr bool b = obj.notwhatyouwant();
return 0;
}
More information about the Gcc-bugs
mailing list