https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86233
Bug ID: 86233 Summary: A tricky code sample 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: --- he code is as follow: #define _GLIBCXX_DEBUG #include <vector> struct T { int i; }; int swap_calls; namespace std { template<> void vector<T, allocator<T> >::swap(vector<T, allocator<T> >&) { ++swap_calls; } } // Should use vector specialization for swap. int main() { std::vector<T> A; std::vector<T> B; swap_calls = 0; std::swap(A, B); return swap_calls; } It comes from a gcc bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16021 I tried the latest g++, and it accepts the above code, but clang++ rejects it. The error message is as follow: code0.c.cpp:12:28: error: 'swap' is missing exception specification 'noexcept(noexcept(declval<std::__debug::vector<T, std::allocator<T> >::_Base &>().swap(__x)))' vector<T, allocator<T> >::swap(vector<T, allocator<T> >&) ^ noexcept(noexcept(declval<std::__debug::vector<T, std::allocator<T> >::_Base &>().swap(__x))) /usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.0.1/../../../../include/c++/8.0.1/debug/vector:688:7: note: previous declaration is here swap(vector& __x) ^ 1 error generated. I reported the difference as a bug to clang: https://bugs.llvm.org/show_bug.cgi?id=37852 Richard Smith believe that clang++ is correct. So, shall g++ reject the code?