[Bug libstdc++/10943] New: ext/hash_map causes namespace issues with abs
kenneth.simpson@ubsw.com
gcc-bugzilla@gcc.gnu.org
Thu May 22 19:30:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10943
Summary: ext/hash_map causes namespace issues with abs
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libstdc++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: kenneth.simpson@ubsw.com
CC: gcc-bugs@gcc.gnu.org,theonetruekenny@yahoo.com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
The following code on a RH7.2 machine will compile with gcc 3.2.2, but not 3.3.
#include <stdlib.h>
inline static double abs(double a) { return a>=0? a : -a; }
#include <ext/hash_map>
3.3 complains:
/include/c++/3.3/cmath: In function `double std::abs(double)':
/include/c++/3.3/cmath:172: error: `double std::abs(double)' conflicts with
previous using declaration `double abs(double)'
Weeding through the preprocessed output (g++ -E foo.cc | egrep -e "\babs\b"), I
see that 322 has the following declarations:
extern int abs (int __x) throw () __attribute__ ((__const__));
inline static double abs(double a) { return a>=0? a : -a; }
using ::abs;
abs(long __i) { return labs(__i); }
abs(long long __x) { return __x >= 0 ? __x : -__x; }
using __gnu_cxx::abs;
The first is from <stdlib.h>, the second is from foo.cc, and the last 4 result
from <ext/hash_map> pulling in <cstdlib>
Using this to whittle down the test case I get:
extern "C" {
extern int abs (int __x) throw () __attribute__ ((__const__));
extern long int labs (long int __x) throw () __attribute__ ((__const__));
}
inline static double abs(double a) { return a>=0? a : -a; }
namespace std {
using ::abs;
long abs(long __i) { return labs(__i); }
}
namespace __gnu_cxx {
long long abs(long long __x) { return __x >= 0 ? __x : -__x; }
}
namespace std {
using __gnu_cxx::abs;
}
Which compiles on both 3.2.2 and 3.3... however...
Looking at the preprocessed 3.3 out put I see:
extern int abs (int __x) throw () __attribute__ ((__const__));
inline static double abs(double a) { return a>=0? a : -a; }
using ::abs;
abs(long __i) { return labs(__i); }
abs(long long __x) { return __x >= 0 ? __x : -__x; }
using __gnu_cxx::abs;
abs(double __x)
abs(float __x)
abs(long double __x)
The three final lines are new and come from <cmath>.
Using this to produce a test case yields:
extern "C" {
extern int abs (int __x) throw () __attribute__ ((__const__));
extern long int labs (long int __x) throw () __attribute__ ((__const__));
}
inline static double abs(double a) { return a>=0? a : -a; }
namespace std {
using ::abs;
long abs(long __i) { return labs(__i); }
}
namespace __gnu_cxx {
long long abs(long long __x) { return __x >= 0 ? __x : -__x; }
}
namespace std {
using __gnu_cxx::abs;
}
// new part:
namespace std {
inline double abs(double __x) { return __builtin_fabs(__x); }
inline float abs(float __x) { return __builtin_fabs(__x); }
inline long double abs(long double __x) { return __builtin_fabs(__x); }
}
Which neither 3.2.2, nor 3.3 like, both complaining:
In function `double foo.cc:std::abs(double)':
foo.cc:32: error: `double std::abs(double)' conflicts with previous using
declaration `double abs(double)'
Another data point:
Just replacing <ext/hash_map> with <cmath> does not cause this.
Hope this was useful.
-Kenny
This was with "gcc version 3.3" and "gcc version 3.2.2"
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
More information about the Gcc-bugs
mailing list