Take the 2-minute tour ×

I have written the following code to test noexcept propagation across function calls, and it seems that it doesn't work as I would have thought. In GCC 4.7.2, A function can effectively be tested against being noexcept only directly or when passed as a template specialization argument; but not when passed as an argument to a templated function, or as a function pointer to a normal function -- even when that function declares its formal parameter as being noexcept. Here's the code:

#include <iostream>

#define test(f) \
    std::cout << __func__ << ": " #f " is " \
              << (noexcept(f()) ? "" : "not ") \
              << "noexcept\n";

template <void(*f)()>
static inline void test0() {

template <typename F>
static inline void test1(F f) {

static inline void test2(void(*f)()) {

static inline void test3(void(*f)()noexcept) {

void f1() {}
void f2() noexcept {}

int main() {
    return 0;

And here's output:

main: f1 is not noexcept
main: f2 is noexcept
test0: f is not noexcept
test0: f is noexcept
test1: f is not noexcept
test1: f is not noexcept
test2: f is not noexcept
test2: f is not noexcept
test3: f is not noexcept
test3: f is not noexcept

Why is noexceptness not propagated in other cases? In case of test1, the whole function is "instantiated" with the proper type of F, the compiler surely knows at that time whether F is a noexcept function. Why is it possible to write test3 the way I wrote it, when the noexceptness declaration is completely ignored?

Does the standard have to say something specific about this?

share|improve this question

1 Answer 1

Section 15.4.13 of the C++11 standard states that "an exception-specification is not considered part of a function's type".

share|improve this answer

Your Answer


