[LLVMbugs] [Bug 6418] New: Narrowing conversion missed by -Wconversion in template defined in system header

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Feb 24 14:21:53 PST 2010


http://llvm.org/bugs/show_bug.cgi?id=6418

           Summary: Narrowing conversion missed by -Wconversion in
                    template defined in system header
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: minor
          Priority: P5
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: jyasskin at google.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


The following function narrows from int64_t to int, losing data, but
-Wconversion doesn't warn because the template was defined in a system header.
Clang should be paying attention to where the template was instantiated
instead.

$ cat test.cc
#include <vector>
#include <numeric>
#include <inttypes.h>

int64_t sum(const std::vector<int64_t>& values) {
  return std::accumulate(values.begin(), values.end(), 0);
}
$ clang++ -c test.cc -Wconversion
$ 

I expect a warning like:

In file included from test.cc:2:
In file included from /usr/include/c++/4.0.0/numeric:68:
/usr/include/c++/4.0.0/bits/stl_numeric.h:89:11: warning: implicit cast loses
integer precision: 'long long' to 'int' [-Wshorten-64-to-32]
        __init = __init + *__first;
                 ^~~~~~~~~~~~~~~~~
test.cc:6:10: note: in instantiation of function template specialization
'std::accumulate<class __gnu_cxx::__normal_iterator<long long const *, class
std::vector<long long, class std::allocator<long long> > >, int>' requested
      here
  return std::accumulate(values.begin(), values.end(), 0);
         ^


Which I copied out of the output of
$ clang++ -c test.cc -Wconversion -Wsystem-headers

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list