[llvm-bugs] [Bug 46000] New: Diagnostic withholds number of line responsible for bad template instantiation

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 20 00:07:15 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46000

            Bug ID: 46000
           Summary: Diagnostic withholds number of line responsible for
                    bad template instantiation
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: tonyelewis at hotmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

This code has a function template that wraps emplace_back() for vector<int> and
then code that erroneously attempts to instantiate it to emplace_back a
nullptr:


#include <vector>

template <typename... Ts>
decltype(auto) int_vec_emplace_back_wrapper(std::vector<int> &vec, Ts
&&...values) {
  return vec.emplace_back(std::forward<Ts>(values)...);
}

void f(std::vector<int> &vec) {
  int_vec_emplace_back_wrapper(vec, nullptr);
}


GCC's diagnostic includes a mention the erroneous line 9 but Clang's diagnostic
doesn't:


In file included from a.cpp:1:
In file included from
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/vector:61:
In file included from
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/allocator.h:46:
In file included from
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8/bits/c++allocator.h:33:
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/ext/new_allocator.h:136:23:
error: cannot initialize a new value of type 'int' with an rvalue of type
'nullptr_t'
        { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
                             ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/alloc_traits.h:475:8:
note: in instantiation of function template specialization
'__gnu_cxx::new_allocator<int>::construct<int, nullptr_t>' requested here
        { __a.construct(__p, std::forward<_Args>(__args)...); }
              ^
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/vector.tcc:103:21:
note: in instantiation of function template specialization
'std::allocator_traits<std::allocator<int> >::construct<int, nullptr_t>'
requested here
            _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
                           ^
a.cpp:5:14: note: in instantiation of function template specialization
'std::vector<int, std::allocator<int> >::emplace_back<nullptr_t>' requested
here
  return vec.emplace_back(std::forward<Ts>(values)...);
             ^
1 error generated.


(Removing int_vec_emplace_back_wrapper()'s variadicity doesn't improve the
diagnostic but giving it an explicit void return type does)

https://bugs.llvm.org/show_bug.cgi?id=20452 touches similar issues but I don't
believe it subsumes this.

-- 
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/20200520/8c94ca92/attachment-0001.html>


More information about the llvm-bugs mailing list