llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.68k stars 11.86k forks source link

noexcept for a class member function are missed when the function pass over template argument. #34724

Open llvmbot opened 6 years ago

llvmbot commented 6 years ago
Bugzilla Link 35376
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor

Extended Description

This happens only with -std=c++14 and -std=c++11 flags, but with -std=c++1z flag is all good.

Link to wandbox demonstration: https://wandbox.org/permlink/xHdPq2R0deTqQ6KG

struct foo { void boo() noexcept {} } foo_;

template < typename F > void should_be_noexcept(F f, foo& t) noexcept(noexcept((t.f)())) { (t.f)(); }

int main() { void (foo::f)() noexcept = &foo::boo; staticassert(noexcept((foo.f)()), "%-)"); // 1 safe noexcept static_assert(noexcept(should_benoexcept(&foo::boo, foo)), "no :-("); // 2 miss noexcept return 0; }

llvmbot commented 6 years ago

Also this problem affected on all standard library. Example:

include

struct foo { void boo() noexcept {} } foo_;

int main() { static_assert(noexcept(std::memfn(&foo::boo)(foo)), "it's bad"); return 0; }

frederick-vs-ja commented 2 weeks ago

I don't think this is a bug and Clang is perfectly conforming here. This is a design change in C++17, see P0012R1.