https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77369

            Bug ID: 77369
           Summary: incorrect noexcept specification deduction
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aaron.ballman+gcc at gmail dot com
  Target Milestone: ---

The following code produces "false, false" with Clang 3.8.0 and MSVC 2015, but
"true, true" with GCC 6.1.0 (and EDG).

#include <iostream>

template <typename Func>
int some_function(int param, Func fn) noexcept(noexcept(fn(param))) {
  return fn(param);
}

int noexcept_fn(int) noexcept(true) { return 0; }
int not_noexcept_fn(int) noexcept(false) { return 0; }

int main() {
  std::cout << std::boolalpha <<
    noexcept(some_function(0, noexcept_fn)) << ", " <<
    noexcept(some_function(0, not_noexcept_fn)) << std::endl;
}

This is dangerous because it means that if not_noexcept_fn() throws (as it is
allowed to do per its exception specification) when called from
some_function(), it results in std::terminate() being called due to
some_function() having the wrong exception specification.

This happens with -std=c++14, where exception specifications are not considered
part of the type system.

Reply via email to