This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/58753] New: Brace-initializing a vector with a direct-initialization NSDMI doesn't work in a template
- From: "ville.voutilainen at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 16 Oct 2013 18:39:28 +0000
- Subject: [Bug c++/58753] New: Brace-initializing a vector with a direct-initialization NSDMI doesn't work in a template
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58753
Bug ID: 58753
Summary: Brace-initializing a vector with a
direct-initialization NSDMI doesn't work in a template
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ville.voutilainen at gmail dot com
This snippet doesn't work:
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
template <class zomg>
class T {
vector<int> v{2,6,4,1,7,1}; // #1, fails
static int comp(int x, int y)
{return x < y;}
public:
void sort_me() {sort(v.begin(), v.end(), comp);}
void print_me() {for (auto x : v) cout << x << endl;}
};
int main()
{
T<int> t;
t.sort_me();
t.print_me();
}
It works if T is not a class template. It also works if the line
marked #1 is written as
vector<int> v = {2,6,4,1,7,1};
both in a class template and in a normal class. Fails the same
way with 4.7.2, 4.8 and 4.9 trunk.
Full diagnostics:
plaatti.cpp: In constructor âconstexpr T<int>::T()â:
plaatti.cpp:8:7: error: no matching function for call to
âstd::vector<int>::vector(<brace-enclosed initializer list>)â
class T {
^
plaatti.cpp:8:7: note: candidates are:
In file included from /usr/local/include/c++/4.9.0/vector:64:0,
from plaatti.cpp:1:
/usr/local/include/c++/4.9.0/bits/stl_vector.h:386:9: note: template<class
_InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator,
_InputIterator, const allocator_type&)
vector(_InputIterator __first, _InputIterator __last,
^
/usr/local/include/c++/4.9.0/bits/stl_vector.h:386:9: note: template argument
deduction/substitution failed:
plaatti.cpp:8:7: note: cannot convert â4â (type âintâ) to type âconst
allocator_type& {aka const std::allocator<int>&}â
class T {
^
In file included from /usr/local/include/c++/4.9.0/vector:64:0,
from plaatti.cpp:1:
/usr/local/include/c++/4.9.0/bits/stl_vector.h:358:7: note: std::vector<_Tp,
_Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp =
int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type =
std::allocator<int>]
vector(initializer_list<value_type> __l,
^
/usr/local/include/c++/4.9.0/bits/stl_vector.h:358:7: note: candidate expects
2 arguments, 6 provided
In file included from /usr/local/include/c++/4.9.0/vector:64:0,
from plaatti.cpp:1:
/usr/local/include/c++/4.9.0/bits/stl_vector.h:334:7: note: std::vector<_Tp,
_Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&) [with _Tp =
int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type =
std::allocator<int>]
vector(vector&& __rv, const allocator_type& __m)
^
/usr/local/include/c++/4.9.0/bits/stl_vector.h:334:7: note: candidate expects
2 arguments, 6 provided
/usr/local/include/c++/4.9.0/bits/stl_vector.h:325:7: note: std::vector<_Tp,
_Alloc>::vector(const std::vector<_Tp, _Alloc>&, const allocator_type&) [with
_Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp,
_Alloc>::allocator_type = std::allocator<int>]
vector(const vector& __x, const allocator_type& __a)
^
/usr/local/include/c++/4.9.0/bits/stl_vector.h:325:7: note: candidate expects
2 arguments, 6 provided
/usr/local/include/c++/4.9.0/bits/stl_vector.h:321:7: note: std::vector<_Tp,
_Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc =
std::allocator<int>]
vector(vector&& __x) noexcept
^
/usr/local/include/c++/4.9.0/bits/stl_vector.h:321:7: note: candidate expects
1 argument, 6 provided
In file included from /usr/local/include/c++/4.9.0/vector:64:0,
from plaatti.cpp:1:
/usr/local/include/c++/4.9.0/bits/stl_vector.h:304:7: note: std::vector<_Tp,
_Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc =
std::allocator<int>]
vector(const vector& __x)
^
/usr/local/include/c++/4.9.0/bits/stl_vector.h:304:7: note: candidate expects
1 argument, 6 provided
In file included from /usr/local/include/c++/4.9.0/vector:64:0,
from plaatti.cpp:1:
/usr/local/include/c++/4.9.0/bits/stl_vector.h:275:7: note: std::vector<_Tp,
_Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const value_type&, const
allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>;
std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp,
_Alloc>::value_type = int; std::vector<_Tp, _Alloc>::allocator_type =
std::allocator<int>]
vector(size_type __n, const value_type& __value,
^
/usr/local/include/c++/4.9.0/bits/stl_vector.h:275:7: note: candidate expects
3 arguments, 6 provided
In file included from /usr/local/include/c++/4.9.0/vector:64:0,
from plaatti.cpp:1:
/usr/local/include/c++/4.9.0/bits/stl_vector.h:263:7: note: std::vector<_Tp,
_Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&)
[with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp,
_Alloc>::size_type = long unsigned int; std::vector<_Tp,
_Alloc>::allocator_type = std::allocator<int>]
vector(size_type __n, const allocator_type& __a = allocator_type())
^
/usr/local/include/c++/4.9.0/bits/stl_vector.h:263:7: note: candidate expects
2 arguments, 6 provided
In file included from /usr/local/include/c++/4.9.0/vector:64:0,
from plaatti.cpp:1:
/usr/local/include/c++/4.9.0/bits/stl_vector.h:250:7: note: std::vector<_Tp,
_Alloc>::vector(const allocator_type&) [with _Tp = int; _Alloc =
std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type =
std::allocator<int>]
vector(const allocator_type& __a = allocator_type()) _GLIBCXX_NOEXCEPT
^
/usr/local/include/c++/4.9.0/bits/stl_vector.h:250:7: note: candidate expects
1 argument, 6 provided
plaatti.cpp: In function âint main()â:
plaatti.cpp:20:10: note: synthesized method âconstexpr T<int>::T()â first
required here
T<int> t;
^