public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/46382] New: constexpr vs. static_assert in constexpr ctors @ 2010-11-08 22:08 bkoz at gcc dot gnu.org 2010-11-09 3:54 ` [Bug c++/46382] " jason at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: bkoz at gcc dot gnu.org @ 2010-11-08 22:08 UTC (permalink / raw) To: gcc-bugs 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; } ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/46382] constexpr vs. static_assert in constexpr ctors 2010-11-08 22:08 [Bug c++/46382] New: constexpr vs. static_assert in constexpr ctors bkoz at gcc dot gnu.org @ 2010-11-09 3:54 ` jason at gcc dot gnu.org 2010-11-09 10:14 ` redi at gcc dot gnu.org ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: jason at gcc dot gnu.org @ 2010-11-09 3:54 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46382 --- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> 2010-11-09 03:54:29 UTC --- Author: jason Date: Tue Nov 9 03:54:24 2010 New Revision: 166471 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=166471 Log: PR c++/46382 * semantics.c (check_constexpr_ctor_body): New fn. * parser.c (cp_parser_ctor_initializer_opt_and_function_body): Call it. * cp-tree.h: Declare it. Added: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-sassert.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/cp-tree.h trunk/gcc/cp/parser.c trunk/gcc/cp/semantics.c trunk/gcc/testsuite/ChangeLog ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/46382] constexpr vs. static_assert in constexpr ctors 2010-11-08 22:08 [Bug c++/46382] New: constexpr vs. static_assert in constexpr ctors bkoz at gcc dot gnu.org 2010-11-09 3:54 ` [Bug c++/46382] " jason at gcc dot gnu.org @ 2010-11-09 10:14 ` redi at gcc dot gnu.org 2010-11-09 13:46 ` jason at gcc dot gnu.org 2010-11-09 15:47 ` bkoz at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: redi at gcc dot gnu.org @ 2010-11-09 10:14 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46382 --- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-09 10:14:02 UTC --- Thanks very much, Jason. I'll make use of this in the library today. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/46382] constexpr vs. static_assert in constexpr ctors 2010-11-08 22:08 [Bug c++/46382] New: constexpr vs. static_assert in constexpr ctors bkoz at gcc dot gnu.org 2010-11-09 3:54 ` [Bug c++/46382] " jason at gcc dot gnu.org 2010-11-09 10:14 ` redi at gcc dot gnu.org @ 2010-11-09 13:46 ` jason at gcc dot gnu.org 2010-11-09 15:47 ` bkoz at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: jason at gcc dot gnu.org @ 2010-11-09 13:46 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46382 Jason Merrill <jason at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |FIXED --- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2010-11-09 13:46:09 UTC --- Done. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/46382] constexpr vs. static_assert in constexpr ctors 2010-11-08 22:08 [Bug c++/46382] New: constexpr vs. static_assert in constexpr ctors bkoz at gcc dot gnu.org ` (2 preceding siblings ...) 2010-11-09 13:46 ` jason at gcc dot gnu.org @ 2010-11-09 15:47 ` bkoz at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: bkoz at gcc dot gnu.org @ 2010-11-09 15:47 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46382 --- Comment #4 from Benjamin Kosnik <bkoz at gcc dot gnu.org> 2010-11-09 15:47:23 UTC --- Nice! Thanks. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-11-09 15:47 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-11-08 22:08 [Bug c++/46382] New: constexpr vs. static_assert in constexpr ctors bkoz at gcc dot gnu.org 2010-11-09 3:54 ` [Bug c++/46382] " jason at gcc dot gnu.org 2010-11-09 10:14 ` redi at gcc dot gnu.org 2010-11-09 13:46 ` jason at gcc dot gnu.org 2010-11-09 15:47 ` bkoz at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).