Skip to content

constexpr value in a lambda #26001

Open
Open
@llvmbot

Description

@llvmbot
Bugzilla Link 25627
Version unspecified
OS Linux
Attachments as explained
Reporter LLVM Bugzilla Contributor
CC @DaemonSnake

Extended Description

If I am correct the following code should be valid c++14:

template<int j> void g() {}
int main()
{
  constexpr int i = 0;
  auto f = []{ g<i>(); };
  return 0;
}

However, clang does not compile this code.
It does compile with when capturing [=], [i] or [&].
It also compiles if the i is made static.

This is related to a stackoverflow-question:
http://stackoverflow.com/questions/33873788/how-can-i-use-a-constexpr-value-in-a-lambda

clang version:
Debian clang version 3.8.0-svn247818-1~exp1 (trunk) (based on LLVM 3.8.0)
compile command:

clang++-3.8 -std=c++14 capture_constexpr.cpp

compiler error:
capture_constexpr.cpp:11:7: error: variable 'i' cannot be implicitly captured in a lambda with no capture-default specified
    g<i>();
      ^
capture_constexpr.cpp:7:17: note: 'i' declared here
  constexpr int i = 0;
                ^
capture_constexpr.cpp:10:12: note: lambda expression begins here
  auto f = []{ // compiles with gcc 4.9.1, not with clang 3.8
           ^
1 error generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++14clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions