[LLVMbugs] [Bug 20209] New: Lambda not allowed in a constant expression
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Fri Jul 4 15:47:34 PDT 2014
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: unassignedclangbugs at nondot.org
Reporter: dyp-cpp at gmx.net
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140704/824bfdb1/attachment.html>
More information about the llvm-bugs
mailing list