[LLVMbugs] [Bug 17934] New: <iterator> C++14 cbegin/cend crbegin/crend definitions don't see all overloads of begin/end rbegin/rend
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Nov 14 12:49:40 PST 2013
http://llvm.org/bugs/show_bug.cgi?id=17934
Bug ID: 17934
Summary: <iterator> C++14 cbegin/cend crbegin/crend definitions
don't see all overloads of begin/end rbegin/rend
Product: libc++
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: hhinnant at apple.com
Reporter: peter.sommerlad at hsr.ch
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 11541
--> http://llvm.org/bugs/attachment.cgi?id=11541&action=edit
corrected <iterator> file
when using cbegin/cend or crbegin/crend with arrays the code doesn't compile.
The reason is that the template definitions don't see all defined overloads of
the functions they rely upon. the array overloads of begin/end rbegin/rend come
later in the file <iostream>
Because we are on namespace level sequencing of function definitions is
important and a template function relying on another function must have all
relevant overloads visisble before the template definition.
Moving the overloads of begin/end rbegin/rend for arrays in front of the
definitions of cbegin/cend crbegin/crend respecitvely fixes this issue.
I'll attach a fixed <iterator>
Example code demonstrating the bug:
#include <iostream>
#include <iterator>
using std::crbegin;
using std::crend;
template <typename CONT>
void reverse_printer(CONT &&c){
for (auto it=crbegin(c); it!=crend(c); ++it){
std::cout << *it << ", ";
}
std::cout << '\n';
}
int main(){
auto l={1,2,3,4,5};
reverse_printer(l);
int a[]={5,4,3,2,1};
reverse_printer(a); // fails to compile
}
--
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/20131114/cf3f91ee/attachment.html>
More information about the llvm-bugs
mailing list