[Bug c++/70979] New: [C++14] g++ falsely accepts constexpr function returning a lambda

felix.morgner at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri May 6 12:25:00 GMT 2016


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

            Bug ID: 70979
           Summary: [C++14] g++ falsely accepts constexpr function
                    returning a lambda
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: felix.morgner at gmail dot com
  Target Milestone: ---

Created attachment 38427
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38427&action=edit
The example code

g++ accepts the following code as valid:

constexpr auto make()
  {
  return []{};
  }

int main()
  {
  make()();
  }

However, according to ISO14882:2014 [dcl.constexpr] requires:

    The definition of a constexpr function shall satisfy the following
constraints:
    [...]
    - its return type shall be a literal type;
    [...]

While it states in [expr.prim.lambda]:

    The type of the lambda-expression (which is also the type of the closure
object) is a unique, unnamed non-union class type - called the closure type -
whose properties are described below. This class type is neither an aggregate
(8.5.1) nor a literal type (3.9) [...]

clang++ reports the following error:

    lambda.cpp:1:16: error: constexpr function's return type '(lambda at
lambda.cpp:3:10)' is not a literal type
      constexpr auto make()
               ^
    lambda.cpp:3:10: note: '' is not literal because it is not an aggregate and
has no constexpr constructors other than copy or move constructors
      return []{};
         ^
    1 error generated.

which would be the expected behavior.


More information about the Gcc-bugs mailing list