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



             Bug #: 55250

           Summary: [C++0x][constexpr] enum declarations within constexpr

                    function are allowed, constexpr declarations are not

    Classification: Unclassified

           Product: gcc

           Version: 4.7.1

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: c++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: bisq...@iki.fi





The following code compiles in GCC without warnings on -Wall -W -pedantic:

  constexpr int Test1(int x)   { enum { y = 1 };       return x+y; }



The following one does not:

  constexpr int Test2(int x)   { constexpr int y = 1;  return x+y; }



For the second code, GCC gives "error: body of constexpr function 'constexpr

int Test2(int)' not a return-statement"



In comparison, Clang++ gives an error for Test1: "error: types cannot be

defined in a constexpr function", and for Test2: "error: variables cannot be

declared in a constexpr function" for Test2.



Now, reading http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2235.pdf

, it is not entirely unambiguous which behavior is correct.



While I would like that both samples worked without warnings, I suggest that

attempting to declare an enum within a constexpr function will be made a

-pedantic warning.



[Tested on GCC 4.6.3 through 4.7.2. On GCC 4.5.3, both functions compiled

without warnings.]

Reply via email to