This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/54020] New: [c++0x] incorrectly accepted constexpr functions


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

             Bug #: 54020
           Summary: [c++0x] incorrectly accepted constexpr functions
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: luto@mit.edu


Tested on a somewhat recent trunk build as well as 4.7-some branch version.

// 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); }

// Correctly accepted.
constexpr int three = one() ? 3 : nonconst_func(0);

// Incorrectly accepted.  See [dcl.constexpr] #5:
//   For a constexpr function, if no function argument values exist
//   such that the function invocation sub-stitution would produce a
//   constant expression (5.19), the program is ill-formed; no diagnostic
//   required.
constexpr int bogus() { return zero () ? 3 : nonconst_func(0); }

// Correctly rejected (not sure why).
constexpr int correct_error() { return nonconst_func(0); }

// Correctly rejected.
constexpr int z = bogus();

// This is also correctly rejected.
constexpr int correct_failure() { return 0 ? 3 : nonconst_func(0); }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]