[Bug c++/17763] New: Wrong context in error message for template parameter
solodon at mail dot com
gcc-bugzilla@gcc.gnu.org
Fri Oct 1 02:10:00 GMT 2004
It seems that in some cases g++ reports in diagnostic messages type names of
template parameters based on the names used in the first instantiation of the
template and not those that appear in the context of the error. Roughly if A,B,X
and Y are all typedef-ed to int, then g++ can report error about incorrect usage
of class T<X,Y> where it has to report incorrect usage of class T<A,B>. Here is
a small application that reproduces this problem in G++ 3.2 and accordingly to
my professor in 3.4:
#include <map>
int main()
{
typedef int X;
typedef int Y;
typedef std::map<X,Y> XYMap; // X and Y happen to be int
XYMap xy; // This will instantiate std::map<int,int>
xy[0] = 1;
typedef int A;
typedef int B;
typedef std::map<A,B> ABMap; // A and B also happen to be int
typedef std::pair<A,B> ABPair;
ABMap ab; // Code for this was already instantiated higher!
ABPair p(0,1); // Pair of A B. Not relevant, required to generate error
ab[0] = 1;
ABMap::iterator q = ab.begin();
// Here we get an error message, because map's value_type is pair<const A, B>
// and not pair<A, B> as we try to compare it to.
// BUT: Look which types are reported as types of map's value_type:
// they are X and Y which are completely irrelevant to ABMap!
// It seems g++ just peeks the type names of the first instantiation with such
// actual types, which actually generates code for both maps.
assert(*q == p);
return 0;
}
Here is what compiler gives when I run it as: gcc -v -save-temps err_rep.cpp
==8<=========================================================================
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/cpp0 -lang-c++ -D__GNUG__=3
-D__DEPRECATED -D__EXCEPTIONS -v -D__GNUC__=3 -D__GNUC_MINOR__=2
-D__GNUC_PATCHLEVEL__=2 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -D__gnu_linux__
-Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -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_i386__ err_rep.cpp err_rep.ii
GNU CPP version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/3.2.2
/usr/include/c++/3.2.2/i386-redhat-linux
/usr/include/c++/3.2.2/backward
/usr/local/include
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/cc1plus -fpreprocessed err_rep.ii
-quiet -dumpbase err_rep.cpp -version -o err_rep.s
GNU CPP version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) (i386-redhat-linux)
compiled by GNU C version 3.2.2 20030222 (Red Hat Linux 3.2.2-5).
err_rep.cpp: In function `int main()':
err_rep.cpp:30: no match for `std::pair<const X, Y>& == main()::ABPair&'
operator
==8<=========================================================================
Line 30 corresponds to line with assert.
--
Summary: Wrong context in error message for template parameter
Product: gcc
Version: 3.2.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: solodon at mail dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: Configured with: ../configure --prefix=/usr --
mandir=/usr/share/
GCC host triplet: gcc version 3.2.2 20030222
GCC target triplet: Red Hat Linux 3.2.2-5
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17763
More information about the Gcc-bugs
mailing list