http://llvm.org/bugs/show_bug.cgi?id=20209

            Bug ID: 20209
           Summary: Lambda not allowed in a constant expression
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

Lambdas are allowed in constant expression if they are not evaluated. This
allows the trick PYTHY uses (allegedly by Richard Smith, see
http://pfultz2.github.io/Pythy/ ):


template<class T>
T* address(T&& t)
{ return &t; }

//template<class T>
struct c
{
    static constexpr auto* x = false ? address([]{}) : nullptr;
};

int main()
{
    (*c::x)();
    //(*c<int>::x)();
}


While this codes compiles with trunk 212348, replacing the class with a class
template results in the following error message:


error: a lambda expression may not appear inside of a constant expression
    static constexpr auto* x = false ? address([]{}) : nullptr;
                                               ^
note: in instantiation of template class 'c<int>' requested here
    (*c<int>::x)();
      ^
1 error generated.


It is not clear to me why using a class template should make a difference in
this case.

This bug might be related to #16501 and CWG DR 1607
http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1607

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to