User account creation filtered due to spam.

Bug 11400 - std::search_n() makes assumptions about Size parameter
Summary: std::search_n() makes assumptions about Size parameter
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.3.2
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-02 00:07 UTC by Martin Sebor
Modified: 2003-09-30 14:39 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-07-02 17:32:26


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2003-07-02 00:07:52 UTC
The only requirement on the Size template parameter of the std::search_n()
template is that it be convertible to integral type (25.1.9, p4). The converse
is not required to hold. The program below fails to compile due to unwarranted
assumptions in the libstdc++ implementation of the algorithm.

Regards
Martin

$ cat t.cpp; g++ -c t.cpp   
#include <algorithm>

struct Integral { operator int() const; };

namespace std {

template int* search_n (int*, int*, Integral, const int&);

}

/build/contrib/gcc-3.2/include/c++/3.2/bits/stl_algo.h: In function 
   `_ForwardIter std::search_n(_ForwardIter, _ForwardIter, _Integer, const 
   _Tp&) [with _ForwardIter = int*, _Integer = Integral, _Tp = int]':
t.cpp:7:   instantiated from here
/build/contrib/gcc-3.2/include/c++/3.2/bits/stl_algo.h:612: conversion from `
   int' to non-scalar type `Integral' requested
/build/contrib/gcc-3.2/include/c++/3.2/bits/stl_algo.h:617: no match for `-- 
   Integral&' operator
Comment 1 CVS Commits 2003-09-29 17:36:27 UTC
Subject: Bug 11400

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	paolo@gcc.gnu.org	2003-09-29 17:36:18

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: istream.tcc stl_algo.h 
Added files:
	libstdc++-v3/testsuite/27_io/basic_istream/peek/char: 12296.cc 
	libstdc++-v3/testsuite/25_algorithms/search_n: 11400.cc 

Log message:
	2003-09-29  Paolo Carlini  <pcarlini@unitus.it>
	
	PR libstdc++/12296
	* include/bits/istream.tcc (peek): Set eofbit if sgetc
	returns eof.
	* testsuite/27_io/basic_istream/peek/char/12296.cc:
	New, from the PR.
	
	2003-09-29  Nathan Myers  <ncm@cantrip.org>
	Paolo Carlini  <pcarlini@unitus.it>
	
	PR libstdc++/11400
	* include/bits/stl_algo.h (search_n):
	Use iterator_traits<>::difference_type for __n.
	* testsuite/25_algorithms/search_n/11400.cc: New, from the PR.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.1973&r2=1.1974
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/istream.tcc.diff?cvsroot=gcc&r1=1.50&r2=1.51
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_algo.h.diff?cvsroot=gcc&r1=1.35&r2=1.36
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/25_algorithms/search_n/11400.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 2 Paolo Carlini 2003-09-29 17:50:50 UTC
Fixed.
Comment 3 CVS Commits 2003-09-30 14:37:44 UTC
Subject: Bug 11400

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	paolo@gcc.gnu.org	2003-09-30 14:37:40

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: istream.tcc stl_algo.h 

Log message:
	2003-09-30  Paolo Carlini  <pcarlini@unitus.it>
	
	PR libstdc++/12296
	* include/bits/istream.tcc (peek): Set eofbit if sgetc
	returns eof.
	
	2003-09-30  Nathan Myers  <ncm@cantrip.org>
	Paolo Carlini  <pcarlini@unitus.it>
	
	PR libstdc++/11400
	* include/bits/stl_algo.h (search_n):
	Use iterator_traits<>::difference_type for __n.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.1464.2.147&r2=1.1464.2.148
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/istream.tcc.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.36.4.6&r2=1.36.4.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_algo.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.27&r2=1.27.20.1