xinguai / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

warning: declaration of 'c_str' shadows a member of 'this' #220

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

In my project, #include <gtest/gtest.h> will trigger the following compiler 
warnings:

../Lib/gtest/include/gtest/internal/gtest-string.h:193:0 
../Lib/gtest/include/gtest/internal/gtest-string.h:193: warning: declaration of 
'c_str' shadows a 
member of 'this'
../Lib/gtest/include/gtest/internal/gtest-string.h:206:0 
../Lib/gtest/include/gtest/internal/gtest-string.h:206: warning: declaration of 
'length' shadows 
a member of 'this'
../Lib/gtest/include/gtest/internal/gtest-string.h:250:0 
../Lib/gtest/include/gtest/internal/gtest-string.h:250: warning: declaration of 
'c_str' shadows a 
member of 'this'
../Lib/gtest/include/gtest/internal/gtest-string.h:258:0 
../Lib/gtest/include/gtest/internal/gtest-string.h:258: warning: declaration of 
'c_str' shadows a 
member of 'this'
../Lib/gtest/include/gtest/internal/gtest-string.h:278:0 
../Lib/gtest/include/gtest/internal/gtest-string.h:278: warning: declaration of 
'c_str' shadows a 
member of 'this'
../Lib/gtest/include/gtest/internal/gtest-string.h:300:0 
../Lib/gtest/include/gtest/internal/gtest-string.h:300: warning: declaration of 
'length' shadows 
a member of 'this'
../Lib/gtest/include/gtest/internal/gtest-death-test-internal.h:196:0 
../Lib/gtest/include/gtest/internal/gtest-death-test-internal.h:196: warning: 
declaration of 
'write_fd' shadows a member of 'this'
../Lib/gtest/include/gtest/internal/gtest-death-test-internal.h:196:0 
../Lib/gtest/include/gtest/internal/gtest-death-test-internal.h:196: warning: 
declaration of 
'index' shadows a member of 'this'
../Lib/gtest/include/gtest/internal/gtest-death-test-internal.h:196:0 
../Lib/gtest/include/gtest/internal/gtest-death-test-internal.h:196: warning: 
declaration of 
'line' shadows a member of 'this'
../Lib/gtest/include/gtest/internal/gtest-death-test-internal.h:196:0 
../Lib/gtest/include/gtest/internal/gtest-death-test-internal.h:196: warning: 
declaration of 'file' 
shadows a member of 'this'
../Lib/gtest/include/gtest/internal/gtest-param-util.h:547:0 
../Lib/gtest/include/gtest/internal/gtest-param-util.h:547: warning: 
declaration of 
'test_meta_factory' shadows a member of 'this'
../Lib/gtest/include/gtest/internal/gtest-param-util.h:547:0 
../Lib/gtest/include/gtest/internal/gtest-param-util.h:547: warning: 
declaration of 
'test_base_name' shadows a member of 'this'
../Lib/gtest/include/gtest/internal/gtest-param-util.h:547:0 
../Lib/gtest/include/gtest/internal/gtest-param-util.h:547: warning: 
declaration of 
'test_case_base_name' shadows a member of 'this'
../Lib/gtest/include/gtest/gtest-test-part.h:63:0 
../Lib/gtest/include/gtest/gtest-test-
part.h:63: warning: declaration of 'message' shadows a member of 'this'
../Lib/gtest/include/gtest/gtest-test-part.h:63:0 
../Lib/gtest/include/gtest/gtest-test-
part.h:63: warning: declaration of 'line_number' shadows a member of 'this'
../Lib/gtest/include/gtest/gtest-test-part.h:63:0 
../Lib/gtest/include/gtest/gtest-test-
part.h:63: warning: declaration of 'file_name' shadows a member of 'this'
../Lib/gtest/include/gtest/gtest-test-part.h:63:0 
../Lib/gtest/include/gtest/gtest-test-
part.h:63: warning: declaration of 'type' shadows a member of 'this'
../Lib/gtest/include/gtest/gtest.h:378:0 
../Lib/gtest/include/gtest/gtest.h:378: warning: 
declaration of 'value' shadows a member of 'this'
../Lib/gtest/include/gtest/gtest.h:378:0 
../Lib/gtest/include/gtest/gtest.h:378: warning: 
declaration of 'key' shadows a member of 'this' 

What is the expected output? What do you see instead?

It would be better for gtest to not use argument names that trigger these 
warnings. Thank you!

What version of the product are you using? On what operating system?

Xcode 3.2, Mac OS X 10.6, 10.4u SDK.

Please provide any additional information below, such as a code snippet.

Original issue reported on code.google.com by fdej...@gmail.com on 9 Nov 2009 at 3:08

GoogleCodeExporter commented 9 years ago
Preston - is there a way to disable this warning in xcode? I prefer to leave 
the 
parameter names as is as their current names convey their meanings  very well.

Original comment by vladlosev on 12 Nov 2009 at 7:31

GoogleCodeExporter commented 9 years ago
Probably. I'll take a look.

Original comment by preston....@gmail.com on 13 Nov 2009 at 12:17

GoogleCodeExporter commented 9 years ago
This might help:

http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html

-Wno-shadow is the warning you want to disable. Thank you!

Original comment by fdej...@gmail.com on 13 Nov 2009 at 12:44

GoogleCodeExporter commented 9 years ago
Hi fdejako,

We do not build with -Wshadow enabled, and hence, we do not get the warnings 
you listed when building the 
Google Test Framework. I created a sample project using the framework and 
couldn't reproduce the warning 
UNTIL I specifically enable -Wshadow. I believe, please correct me if I'm 
wrong, that the appropriate course 
here would be for you to disable the -Wshadow warning option in your project or 
target. It also goes by the 
name "Hidden Local Variables" under the GCC Warnings tab.

Let me know if this resolves the issue for you,
Preston

Original comment by preston....@gmail.com on 16 Nov 2009 at 11:15

GoogleCodeExporter commented 9 years ago
While it is something I can live with, it's not ideal. I find this warning quite
useful, switching it off explicitly for certain files is possible, however. 
Thanks
for looking into this.

Original comment by fdej...@gmail.com on 16 Nov 2009 at 11:21

GoogleCodeExporter commented 9 years ago
I'll look into this further. We'd like for you to be able to enable this 
warning.

Original comment by preston....@gmail.com on 16 Nov 2009 at 11:42

GoogleCodeExporter commented 9 years ago
As this affects settings in users' projects, I think we should fix this. But it 
is
not a high priority issue.

Original comment by vladlosev on 16 Nov 2009 at 11:43

GoogleCodeExporter commented 9 years ago
Fixed by Preston in r350.

Original comment by w...@google.com on 16 Dec 2009 at 7:54

GoogleCodeExporter commented 9 years ago

Original comment by w...@google.com on 23 Dec 2009 at 7:07