How to declare noexcept unless the attribute member function is an exception?

#include <vector> class A { std::vector<int> vec; void swap( A & other) noexcept(noexcept(vec.swap(other.vec))) { vec.swap(other.vec); } }; int main() { } 

This code compiles under clang (3.4), but not under gcc (4.7.1). Can anyone tell me what I'm doing wrong?

EDIT

Gcc error message:

 error: invalid use of incomplete type 'class A' error: forward declaration of 'class A' 
0
c ++ gcc c ++ 11 noexcept clang
source share
1 answer

As a job, you can use (which works for gcc 4.7.1, gcc 4.8.1 and clang 3.4):

 void swap(A& other) noexcept(noexcept(std::declval<decltype(A::vec)&>().swap(std::declval<decltype(A::vec)&>()))) 

or

 void swap(A& other) noexcept(noexcept(vec.swap(vec))) 

I think the problem is other.vec ...

+3
source share

All Articles