Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

[C++11] An assignment of a lambda expression to a pointer to function ignores exception specification. #21010

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR21011
Status NEW
Importance P normal
Reported by Mitsuru Kariya (kariya_mitsuru@hotmail.com)
Reported on 2014-09-20 07:14:01 -0700
Last modified on 2014-09-25 20:04:56 -0700
Version trunk
Hardware All All
CC dgregor@apple.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
A sample code below should cause a compilation error but it is compiled
successfully by clang.
=================================
int main()
{
    void(*fp)() noexcept = []{};
    fp();
}
=================================
cf. http://melpon.org/wandbox/permlink/kS5AxGICzzglWBTW

According to C++11 standard [expr.prim.lambda] 5.1.2/5, "[]{}" has a conversion
function to pointer to function "void(*)()".
C++11 standard [except.spec] 15.4/5 also says that "the target entity shall
allow at least the exceptions allowed by the source value in the assignment or
initialization."

So, I think that the sample code above is ill-formed.

I don't know whether a sample code below should be compiled successfully or not
because any struct cannot have a conversion function to pointer to function
"void(*)() noexcept".
=================================
int main()
{
    void(*fp)() noexcept = []() noexcept {};
    fp();
}
=================================
Quuxplusone commented 10 years ago
This issue is unrelated to lambdas; here's a reduced testcase:

  struct S { typedef void (*p)(); operator p(); };
  void (*p)() noexcept = S();

The question is, is this ill-formed? It's not possible for a conversion-type-id
to have an exception-specification, so checking the exception-specification for
this initialization seems unhelpful. In practice, EDG, GCC, and Clang accept
this, but MSVC rejects.

More generally, does "the target entity shall allow at least the exceptions
allowed by the source value in the assignment or initialization." apply when
there is no source value that could have an exception-specification?

I've mailed CWG for clarification.