llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.05k stars 11.58k forks source link

clang-cl /MDd fails to compile vector with a custom allocator #34831

Open llvmbot opened 6 years ago

llvmbot commented 6 years ago
Bugzilla Link 35483
Version trunk
OS other
Reporter LLVM Bugzilla Contributor
CC @rnk

Extended Description

clang-cl.exe fails to compile std::vector with a custom allocator when /MDd is provided as an argument. The issue seems to be triggered by the _DEBUG define.

Code sample to reproduce the issue:

include

template class fuzzer_allocator: public std::allocator { public: template struct rebind { typedef fuzzer_allocator other; }; }; int some_func() { std::vector<int, fuzzer_allocator> v; return v.size(); }

"clang-cl.exe /MDd repro.cc" gives the following output:

In file included from .\repro.cc:2: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\include\vector(555,12): error: no matching constructor for initialization of 'std::_Vector_alloc<std::_Vec_base_types<int, (anonymous namespace)::fuzzer_allocator > >::_Alproxy' (aka '(anonymous namespace)::fuzzer_allocator') _Alproxy _Proxy_allocator(_Getal()); ^ ~~~~ C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\include\vector(506,3): note: in instantiation of member function 'std::_Vector_alloc<std::_Vec_base_types<int, (anonymous namespace)::fuzzer_allocator > >::_Free_proxy' requested here _Free_proxy(); ^ C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\include\vector(683,2): note: in instantiation of member function 'std::_Vector_alloc<std::_Vec_base_types<int, (anonymous namespace)::fuzzer_allocator > >::~_Vector_alloc' requested here vector() _NOEXCEPT_COND(is_nothrow_default_constructible<_Alty>::value) ^ .\repro.cc(15,43): note: in instantiation of member function 'std::vector<int, (anonymous namespace)::fuzzer_allocator >::vector' requested here std::vector<int, fuzzer_allocator> v; ^ .\repro.cc(7,9): note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'fuzzer_allocator' to 'const fuzzer_allocator' for 1st argument class fuzzer_allocator: public std::allocator { ^ .\repro.cc(7,9): note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'fuzzer_allocator' to 'fuzzer_allocator' for 1st argument .\repro.cc(7,9): note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided

The same code compiles fine when /MDd is not provided.

OS version: Windows 10 Enterprise 1607 MSVC C++ version: 14.11.25503 clang version 6.0.0 (trunk 318667)

rnk commented 6 years ago

I think this is a bug or peculiarity of the Visual C++ debug iterator implementation, and not something clang is doing anything about. If I compile that program with MSVC, this is what I get:

$ cl -MDd -c t.cpp Microsoft (R) C/C++ Optimizing Compiler Version 19.11.25508.2 for x64 Copyright (C) Microsoft Corporation. All rights reserved.

t.cpp C:/PROGRA~2/MICROS~1/2017/PROFES~1/VC/Tools/MSVC/14.11.25503/include\vector(555): error C2664: 'fuzzer_allocator::fuzzer_allocator(fuzzer_allocator &&)': cannot convert argument 1 from 'fuzzer_allocator' to 'const fuzzer_allocator &' with [ Other=std::_Container_proxy ] C:/PROGRA~2/MICROS~1/2017/PROFES~1/VC/Tools/MSVC/14.11.25503/include\vector(555): note: Reason: cannot convert from 'fuzzer_allocator' to 'const fuzzer_allocator' with [ Other=std::_Container_proxy ] C:/PROGRA~2/MICROS~1/2017/PROFES~1/VC/Tools/MSVC/14.11.25503/include\vector(555): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called C:/PROGRA~2/MICROS~1/2017/PROFES~1/VC/Tools/MSVC/14.11.25503/include\vector(554): note: while compiling class template member function 'void std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Free_proxy(void)' with [ _Ty=int, _Alloc=fuzzer_allocator ] C:/PROGRA~2/MICROS~1/2017/PROFES~1/VC/Tools/MSVC/14.11.25503/include\vector(506): note: see reference to function template instantiation 'void std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Free_proxy(void)' being compiled with [ _Ty=int, _Alloc=fuzzer_allocator ] C:/PROGRA~2/MICROS~1/2017/PROFES~1/VC/Tools/MSVC/14.11.25503/include\vector(660): note: see reference to class template instantiation 'std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>' being compiled with [ _Ty=int, _Alloc=fuzzer_allocator ] t.cpp(9): note: see reference to class template instantiation 'std::vector<int,fuzzer_allocator>' being compiled