This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/5908: Warning regression wrt. gcc 3.0
- From: Peter Schmid <schmid at snake dot iap dot physik dot tu-darmstadt dot de>
- To: gcc-gnats at gcc dot gnu dot org
- Date: Sun, 10 Mar 2002 17:02:59 +0100
- Subject: c++/5908: Warning regression wrt. gcc 3.0
>Number: 5908
>Category: c++
>Synopsis: Warning regression wrt. gcc 3.0
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Mar 10 07:06:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Peter Schmid
>Release: 3.1 20020306 (prerelease)
>Organization:
TU Darmstadt
>Environment:
System: Linux kiste 2.4.18 #8 Sat Mar 9 15:33:15 CET 2002 i686 unknown
Architecture: i686
SuSE 7.3
GNU ld version 020305 20020305
glibc 2.2.4 + patches
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --enable-shared --disable-nls --enable-threads --enable-languages=c,c++,f77,objc
>Description:
There is an IMHO bogus "value computed is not used" warning in the
following code re.C, a stripped down version of:
#include <map>
typedef std::map<std::int, std::int> previous_results_type;
previous_results_type read_previous_results()
{
previous_results_type result;
return result;
}
int main()
{
previous_results_type previous_results;
previous_results = read_previous_results();
}
gcc 2.95, 3.0 and gcc 3.1 older than two weeks do not issue this
warning. If my opinon is wrong the map and other container headers
from libstdc++ should be fixed. When the
template <class _Key, class _Value, class _KeyOfValue, class _Compare>
_Rb_tree<_Key,_Value,_KeyOfValue,_Compare>&
_Rb_tree<_Key,_Value,_KeyOfValue,_Compare>
::operator=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare>& __x)
method is removed, the warning disappers.
>How-To-Repeat:
Source code re.C
namespace std
{
template <class _T1, class _T2>
struct pair {
typedef _T1 first_type;
typedef _T2 second_type;
_T1 first;
_T2 second;
pair() : first(), second() {}
pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}
};
template <class _Tp>
struct less
{
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
};
template <class _Key, class _Value, class _KeyOfValue, class _Compare>
class _Rb_tree {
protected:
_Compare _M_key_compare;
public:
_Rb_tree(const _Compare& __comp)
: _M_key_compare(__comp)
{}
_Rb_tree<_Key,_Value,_KeyOfValue,_Compare>&
operator=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare>& __x);
};
template <class _Key, class _Value, class _KeyOfValue,
class _Compare>
_Rb_tree<_Key,_Value,_KeyOfValue,_Compare>&
_Rb_tree<_Key,_Value,_KeyOfValue,_Compare>
::operator=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare>& __x)
{
if (this != &__x) {
_M_key_compare = __x._M_key_compare;
}
return *this;
}
template <class _Key, class _Tp, class _Compare = less<_Key> >
class map
{
public:
typedef _Key key_type;
typedef pair<const _Key, _Tp> value_type;
typedef _Compare key_compare;
private:
typedef _Rb_tree<key_type, value_type,
const key_type, key_compare> _Rep_type;
_Rep_type _M_t;
public:
map() : _M_t(_Compare()) {}
map<_Key,_Tp,_Compare>&
operator=(const map<_Key, _Tp, _Compare>& __x)
{
_M_t = __x._M_t;
return *this;
}
};
}
typedef std::map<int, int> previous_results_type;
previous_results_type read_previous_results()
{
previous_results_type result;
return result;
}
int main()
{
previous_results_type previous_results;
previous_results = read_previous_results();
}
g++ -v -o re re.C -W -Wall -save-temps
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/specs
Configured with: ../gcc/configure --enable-shared --disable-nls --enable-threads --enable-languages=c,c++,f77,objc
Thread model: posix
gcc version 3.1 20020306 (prerelease)
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/cpp0 -lang-c++ -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -v -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ re.C -W -Wall re.ii
GNU CPP version 3.1 20020306 (prerelease) (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include/g++-v3
/usr/local/include/g++-v3/i686-pc-linux-gnu
/usr/local/include/g++-v3/backward
/usr/local/include
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/include
/usr/include
End of search list.
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/cc1plus -fpreprocessed re.ii -quiet -dumpbase re.C -W -Wall -version -o re.s
GNU CPP version 3.1 20020306 (prerelease) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.1 20020306 (prerelease) (i686-pc-linux-gnu)
compiled by GNU C version 3.1 20020306 (prerelease).
re.C: In member function `std::_Rb_tree<_Key, _Value, _KeyOfValue, _Compare>&
std::_Rb_tree<_Key, _Value, _KeyOfValue, _Compare>::operator=(const
std::_Rb_tree<_Key, _Value, _KeyOfValue, _Compare>&) [with _Key = int,
_Value = std::pair<const int, int>, _KeyOfValue = const int, _Compare =
std::less<int>]':
re.C:58: instantiated from `std::map<_Key, _Tp, _Compare>& std::map<_Key, _Tp, _Compare>::operator=(const std::map<_Key, _Tp, _Compare>&) [with _Key = int, _Tp = int, _Compare = std::less<int>]'
re.C:75: instantiated from here
re.C:37: warning: value computed is not used
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/../../../../i686-pc-linux-gnu/bin/as -V -Qy -o re.o re.s
GNU assembler version 020305 (i686-pc-linux-gnu) using BFD version 020305 20020305
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o re /usr/lib/crt1.o /usr/lib/crti.o /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/crtbegin.o -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1 -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/../../../../i686-pc-linux-gnu/lib -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/../../.. re.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/crtend.o /usr/lib/crtn.o
preprocessed source file re.ii
# 1 "re.C"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "re.C"
namespace std
{
template <class _T1, class _T2>
struct pair {
typedef _T1 first_type;
typedef _T2 second_type;
_T1 first;
_T2 second;
pair() : first(), second() {}
pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}
};
template <class _Tp>
struct less
{
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
};
template <class _Key, class _Value, class _KeyOfValue, class _Compare>
class _Rb_tree {
protected:
_Compare _M_key_compare;
public:
_Rb_tree(const _Compare& __comp)
: _M_key_compare(__comp)
{}
_Rb_tree<_Key,_Value,_KeyOfValue,_Compare>&
operator=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare>& __x);
};
template <class _Key, class _Value, class _KeyOfValue,
class _Compare>
_Rb_tree<_Key,_Value,_KeyOfValue,_Compare>&
_Rb_tree<_Key,_Value,_KeyOfValue,_Compare>
::operator=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare>& __x)
{
if (this != &__x) {
_M_key_compare = __x._M_key_compare;
}
return *this;
}
template <class _Key, class _Tp, class _Compare = less<_Key> >
class map
{
public:
typedef _Key key_type;
typedef pair<const _Key, _Tp> value_type;
typedef _Compare key_compare;
private:
typedef _Rb_tree<key_type, value_type,
const key_type, key_compare> _Rep_type;
_Rep_type _M_t;
public:
map() : _M_t(_Compare()) {}
map<_Key,_Tp,_Compare>&
operator=(const map<_Key, _Tp, _Compare>& __x)
{
_M_t = __x._M_t;
return *this;
}
};
}
typedef std::map<int, int> previous_results_type;
previous_results_type read_previous_results()
{
previous_results_type result;
return result;
}
int main()
{
previous_results_type previous_results;
previous_results = read_previous_results();
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: