[llvm-bugs] [Bug 37852] New: A tricky code sample

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 19 04:25:58 PDT 2018


            Bug ID: 37852
           Summary: A tricky code sample
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zhonghao at pku.org.cn
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The code is as follow:

 #include <vector>

 struct T { int i; };

 int swap_calls;

 namespace std
 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:

The programmers of gcc have a long discussion on whether the above code is

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
     vector<T, allocator<T> >::swap(vector<T, allocator<T> >&)
noexcept(noexcept(declval<std::__debug::vector<T, std::allocator<T> >::_Base
note: previous declaration is here
          swap(vector& __x)
    1 error generated.

You may have interests in reading the gcc bug report, and I am curious how you
consider the code sample. Is it buggy or not?

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180619/4f732b63/attachment.html>

More information about the llvm-bugs mailing list