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

            Bug ID: 86230
           Summary: missing exception specification
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code sample is as follow:

#include <vector>
#include <cassert>
#define VERIFY assert

struct T { int i; };

int swap_calls;

namespace std
{
 // Should be most specialized.
#if 1
 template<> 
#endif
 inline void 
 swap(vector<T, allocator<T> >&, vector<T, allocator<T> >&) 
 { ++swap_calls; }
}

void test01()
{
 bool test __attribute__((unused)) = true;
 std::vector<T> A;
 std::vector<T> B;
 swap_calls = 0;
 std::swap(A, B);
 VERIFY(1 == swap_calls); // XXX fails
}

void test02()
{
 bool test __attribute__((unused)) = true;
 using namespace std;
 vector<T> A;
 vector<T> B;
 swap_calls = 0;
 swap(A, B);
 VERIFY(1 == swap_calls);
}

int main()
{
 test01();
 test02();
 return 0;
}

g++ accepts the code, but clang++ rejects it with an error message:

error: 'swap<T, std::allocator<T> >' is missing exception specification
'noexcept(noexcept(__x.swap(__y)))'
     swap(vector<T, allocator<T> >&, vector<T, allocator<T> >&) 

Is this a piece of ill-formed code?

Reply via email to