Trying to fix -Wshadow warnings - some help needed.

Folks I have a large amount of code that generates warnings of the kind: t.cpp:6: warning: shadowing built-in function `double std::acos(double)' Actually many thousands of these warnings when building with g++ -Wshadow :-( Normally I would just fix the code, but in this case I don't see how, I have code that looks like: #include <cmath> template <class T> T f(T v) { // We want acos found via ADL in case T is a class type: using std::acos; return acos(v); } int main() { f(2.0); return 0; } Which just on it's own produces: $ g++ -I. -Wall -Wshadow -c t.cpp 2>&1 | less t.cpp: In function `void f(T)': t.cpp:6: warning: shadowing built-in function `double std::acos(double)' t.cpp: In function `void f(T) [with T = double]': t.cpp:12: instantiated from here t.cpp:6: warning: shadowing built-in function `double std::acos(double)' t.cpp:12: instantiated from here But I can't see any other way to code this... certainly using a "using namespace std;" in place of the "using std::functionname;" is *not* a valid fix (it can lead to lookup ambiguities). Any ideas folks? Thanks, John.

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 05 August 2008 11:26 am, John Maddock wrote:
$ g++ -I. -Wall -Wshadow -c t.cpp 2>&1 | less
t.cpp: In function `void f(T)': t.cpp:6: warning: shadowing built-in function `double std::acos(double)' t.cpp: In function `void f(T) [with T = double]': t.cpp:12: instantiated from here t.cpp:6: warning: shadowing built-in function `double std::acos(double)' t.cpp:12: instantiated from here
I don't get any warnings with g++ 4.1.2. What version of gcc are you using? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFImHYQ5vihyNWuA4URAntzAJ4jumKo5rIhyQ54JTBeOj5vOTeJgwCgzFPY NfRdZi4JRE6U1VhiBBo+upM= =Ua27 -----END PGP SIGNATURE-----

Frank Mori Hess wrote:
I don't get any warnings with g++ 4.1.2. What version of gcc are you using?
MinGW G++ 3.4, if this is fixed in the compiler from 4.x onwards then I'm happy to stop worrying about it, I'll give the MinGW g++ 4.2 alpha a try and see how that fairs, Thanks, John.

Hi John, I get no warnings whatsoever for this code with gcc 4.3.1 on an OpenSUSE 11 / 64 bit box. Best, Ruediger John Maddock wrote:
Folks I have a large amount of code that generates warnings of the kind:
t.cpp:6: warning: shadowing built-in function `double std::acos(double)'
Actually many thousands of these warnings when building with g++ -Wshadow :-(
Normally I would just fix the code, but in this case I don't see how, I have code that looks like:
#include <cmath>
template <class T> T f(T v) { // We want acos found via ADL in case T is a class type: using std::acos; return acos(v); }
int main() { f(2.0); return 0; }
Which just on it's own produces:
$ g++ -I. -Wall -Wshadow -c t.cpp 2>&1 | less
t.cpp: In function `void f(T)': t.cpp:6: warning: shadowing built-in function `double std::acos(double)' t.cpp: In function `void f(T) [with T = double]': t.cpp:12: instantiated from here t.cpp:6: warning: shadowing built-in function `double std::acos(double)' t.cpp:12: instantiated from here
But I can't see any other way to code this... certainly using a "using namespace std;" in place of the "using std::functionname;" is *not* a valid fix (it can lead to lookup ambiguities).
Any ideas folks?
Thanks, John.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hello, I reproduce it with gcc 3.4.0 and gcc 3.4.6, but not with gcc 3.3.6 (all that on linux). So the problem is really related to that precise minor version... Bruno
participants (4)
-
Bruno Lalande
-
Frank Mori Hess
-
John Maddock
-
Ruediger Berlich