public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54021] New: [c++0x] __builtin_constant_p should be constexpr
@ 2012-07-18 19:52 luto at mit dot edu
  2012-07-19  6:53 ` [Bug c++/54021] " jakub at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: luto at mit dot edu @ 2012-07-18 19:52 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54021

             Bug #: 54021
           Summary: [c++0x] __builtin_constant_p should be constexpr
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: luto@mit.edu


It's hard to tell how __builtin_constant_p works right now, due to PR54020.

// Preliminaries.
extern int nonconst_func(int);
constexpr int identity(int x) { return x; }
constexpr int zero() { return identity(0); }
constexpr int one() { return identity(1); }

// These are the same.  Only the latter is accepted, though.
// I suspect that the acceptance of the latter is due to the bug above.
constexpr int rejected_const_4(int x) { return __builtin_constant_p(x) ? 4 :
nonconst_func(x); }
constexpr int accepted_const_4(int x) { return
identity(__builtin_constant_p(x)) ? 4 : nonconst_func(x); }

// This is rejected.  I would like it to work.
constexpr int four = accepted_const_4(1);

The ability to use the construction __builtin_constant_p(x) ? const_func(x) :
nonconst_func(x) in constexpr context would be quite powerful.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-09-09 16:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-18 19:52 [Bug c++/54021] New: [c++0x] __builtin_constant_p should be constexpr luto at mit dot edu
2012-07-19  6:53 ` [Bug c++/54021] " jakub at gcc dot gnu.org
2012-07-19  7:12 ` jakub at gcc dot gnu.org
2012-07-19 20:02 ` jason at gcc dot gnu.org
2012-07-19 20:57 ` jason at gcc dot gnu.org
2012-09-08 21:36 ` david at doublewise dot net
2012-09-08 22:29 ` luto at mit dot edu
2012-09-09  6:00 ` david at doublewise dot net
2012-09-09  6:05 ` luto at mit dot edu
2012-09-09 16:48 ` jason 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).