public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55250] New: [C++0x][constexpr] enum declarations within constexpr function are allowed, constexpr declarations are not
@ 2012-11-09 12:28 bisqwit at iki dot fi
  2012-11-09 12:52 ` [Bug c++/55250] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: bisqwit at iki dot fi @ 2012-11-09 12:28 UTC (permalink / raw)
  To: gcc-bugs


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: unassigned@gcc.gnu.org
        ReportedBy: bisqwit@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.]


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

* [Bug c++/55250] [C++0x][constexpr] enum declarations within constexpr function are allowed, constexpr declarations are not
  2012-11-09 12:28 [Bug c++/55250] New: [C++0x][constexpr] enum declarations within constexpr function are allowed, constexpr declarations are not bisqwit at iki dot fi
@ 2012-11-09 12:52 ` redi at gcc dot gnu.org
  2014-10-06 16:14 ` [Bug c++/55250] [C++0x] " paolo at gcc dot gnu.org
  2014-10-06 16:16 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-09 12:52 UTC (permalink / raw)
  To: gcc-bugs


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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-11-09
     Ever Confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-09 12:51:52 UTC ---
(In reply to comment #0)
> Now, reading http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2235.pdf
> , it is not entirely unambiguous which behavior is correct.

That paper is five years old, so not relevant to what C++11 allows.

The standard says:

The definition of a constexpr function shall satisfy the following constraints:
[...]
— its function-body shall be = delete, = default, or a compound-statement that
contains only
— null statements,
— static_assert-declarations
— typedef declarations and alias-declarations that do not define classes or
enumerations,
[...]

so it's ill-formed to declare an enumeration.


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

* [Bug c++/55250] [C++0x] enum declarations within constexpr function are allowed, constexpr declarations are not
  2012-11-09 12:28 [Bug c++/55250] New: [C++0x][constexpr] enum declarations within constexpr function are allowed, constexpr declarations are not bisqwit at iki dot fi
  2012-11-09 12:52 ` [Bug c++/55250] " redi at gcc dot gnu.org
@ 2014-10-06 16:14 ` paolo at gcc dot gnu.org
  2014-10-06 16:16 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo at gcc dot gnu.org @ 2014-10-06 16:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Mon Oct  6 16:13:41 2014
New Revision: 215954

URL: https://gcc.gnu.org/viewcvs?rev=215954&root=gcc&view=rev
Log:
/cp
2014-10-06  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/55250
    * semantics.c (check_constexpr_bind_expr_vars): New.
    (check_constexpr_ctor_body, massage_constexpr_body): Use it.
    (build_constexpr_constructor_member_initializers): Handle
    BIND_EXPR in the main conditional.

/testsuite
2014-10-06  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/55250
    * g++.dg/cpp0x/constexpr-type-decl1.C: New.
    * g++.dg/cpp0x/constexpr-type-def1.C: Likewise.
    * g++.dg/cpp1y/constexpr-type-def1.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-type-decl1.C
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-type-def1.C
    trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-type-def1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/55250] [C++0x] enum declarations within constexpr function are allowed, constexpr declarations are not
  2012-11-09 12:28 [Bug c++/55250] New: [C++0x][constexpr] enum declarations within constexpr function are allowed, constexpr declarations are not bisqwit at iki dot fi
  2012-11-09 12:52 ` [Bug c++/55250] " redi at gcc dot gnu.org
  2014-10-06 16:14 ` [Bug c++/55250] [C++0x] " paolo at gcc dot gnu.org
@ 2014-10-06 16:16 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-10-06 16:16 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |5.0

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Fixed.


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

end of thread, other threads:[~2014-10-06 16:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-09 12:28 [Bug c++/55250] New: [C++0x][constexpr] enum declarations within constexpr function are allowed, constexpr declarations are not bisqwit at iki dot fi
2012-11-09 12:52 ` [Bug c++/55250] " redi at gcc dot gnu.org
2014-10-06 16:14 ` [Bug c++/55250] [C++0x] " paolo at gcc dot gnu.org
2014-10-06 16:16 ` paolo.carlini at oracle dot com

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).