------- Comment #21 from hjl dot tools at gmail dot com 2008-12-11 17:57 ------- Here is a new testcase:
[...@gnu-6 37144]$ cat y.cc #include <stdlib.h> #include <stdio.h> struct T1 { int i; T1 () { i = 0; } T1 (int x) { i = x; } T1 (const T1 &x) { i = x.i; } T1& operator=(T1 & __p) { i = __p.i; return *this; } }; template<class T1, class T2> struct pair { T1 first; T2 second; pair() : first(), second() { } pair(const T1 & __a, const T1 & __b) : first(__a), second(__b) { } template<class _U1, class _U2> pair(const pair<_U1, _U2>& a) : first(a.first), second(a.second) { } pair& operator=(pair& __p) { first = __p.first; second = __p.second; return *this; } }; typedef const T1& const_T1_reference; #ifdef BAD typedef const pair<const T1, T1>& const_pair_reference; #else typedef const pair<T1, T1>& const_pair_reference; #endif const_T1_reference extract_key_imp(const_pair_reference r_val) { return r_val.first; } const_T1_reference extract_key_imp(const_T1_reference r_val) { return r_val; } int main () { T1 t1 (21), t2 (3); pair<T1, T1> p (t1, t2); const_T1_reference x = extract_key_imp (p); const_T1_reference y = extract_key_imp (t1); if (y.i != t1.i) abort (); if (&y.i != &t1.i) abort (); if (x.i != p.first.i) abort (); if (&x.i != &p.first.i) { printf ("&x.i != &p.first.i\n"); abort (); } return 0; } [...@gnu-6 37144]$ g++ y.cc [...@gnu-6 37144]$ ./a.out [...@gnu-6 37144]$ g++ y.cc -DBAD [...@gnu-6 37144]$ ./a.out &x.i != &p.first.i Aborted [...@gnu-6 37144]$ -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37144