함수 호출을 통해 noexcept
전파를 테스트하기 위해 다음 코드를 작성했으며 생각했던 것처럼 작동하지 않는 것으로 보입니다. GCC 4.7.2에서 함수는 직접 또는 템플릿 전문화 인수로 전달 될 때 noexcept
인 경우에만 효과적으로 테스트 할 수 있습니다. 이 아니며이 템플릿 함수의 인수로 전달되거나 함수가 정상 함수의 함수 포인터 인 경우 - 해당 함수가 형식 매개 변수를 noexcept
으로 선언하는 경우에도 마찬가지입니다. 여기에 코드입니다 :함수 포인터를 전달할 때 noexcept-ness에 대한 정보가 전달되어야한다고 생각합니까?
#include <iostream>
#define test(f) \
std::cout << __func__ << ": " #f " is " \
<< (noexcept(f()) ? "" : "not ") \
<< "noexcept\n";
template <void(*f)()>
static inline void test0() {
test(f);
}
template <typename F>
static inline void test1(F f) {
test(f);
}
static inline void test2(void(*f)()) {
test(f);
}
static inline void test3(void(*f)()noexcept) {
test(f);
}
void f1() {}
void f2() noexcept {}
int main() {
test(f1);
test(f2);
test0<f1>();
test0<f2>();
test1(f1);
test1(f2);
test2(f1);
test2(f2);
test3(f1);
test3(f2);
return 0;
}
그리고 여기에 출력입니다 :
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
왜 noexcept
가 다른 경우에는 전파되지 다움입니까? test1
의 경우 전체 함수가 F
의 적절한 유형으로 "인스턴스화"됩니다. 컴파일러는 F가 noexcept
함수인지 여부를 확실히 알고 있습니다. noexcept
네스 선언을 완전히 무시했을 때 내가 작성한 방식으로 test3
을 쓸 수 있습니까?
표준이 이에 대해 구체적인 내용을 말해야합니까?