Opened 11 years ago

#6365 new Bugs

Compiler warnings when running static code analysis after build on MSVC 10

Reported by: seppe.de.clercq@… Owned by: Emil Dotchevski
Milestone: To Be Determined Component: exception
Version: Boost 1.48.0 Severity: Cosmetic
Keywords: Cc:

Description

As the title says I'm getting several compiler warnings when running static code analysis in Visual Studio 10 (attached the list to the ticket).

The reported warnings are harmless (are only triggered by the static analyzer and not when compiling with warning level 4), but could you fix them if you have the time?

I'm getting two type of warnings.

Warning type 1

warning C6246: Local declaration of 'l' hides declaration of the same name in outer scope. For additional information, see previous declaration at line '131' of 'c:\users\seppe\boost_1_48_0\boost\exception\diagnostic_information.hpp': Lines: 131 c:\users\seppe\boost_1_48_0\boost\exception\diagnostic_information.hpp 140

warning C6246: Local declaration of 'fn' hides declaration of the same name in outer scope. For additional information, see previous declaration at line '132' of 'c:\users\seppe\boost_1_48_0\boost\exception\diagnostic_information.hpp': Lines: 132 c:\users\seppe\boost_1_48_0\boost\exception\diagnostic_information.hpp 144

and the affected code:

130: char const * const * f=get_error_info<throw_file>(*be);
131: int const * l=get_error_info<throw_line>(*be);
132: char const * const * fn=get_error_info<throw_function>(*be);
133: if( !f && !l && !fn )
134:    tmp << "Throw location unknown (consider using BOOST_THROW_EXCEPTION)\n";
135: else
136: {
137:    if( f )
138:    {
139:       tmp << *f;
140:       if( int const * l=get_error_info<throw_line>(*be) )
141:          tmp << '(' << *l << "): ";
142:    }
143:    tmp << "Throw in function ";
144:    if( char const * const * fn=get_error_info<throw_function>(*be) )
145:       tmp << *fn;
146:    else
147:       tmp << "(unknown)";
148:    tmp << '\n';
149: }

Both warnings can be fixed by:

  • line 140: replacing if( int const * l=get_error_info<throw_line>(*be) ) with if( l )
  • line 144: replacing if( char const * const * fn=get_error_info<throw_function>(*be) ) with if( fn )

Warning type 2

Only displaying the first warning.

warning C6246: Local declaration of 'e' hides declaration of the same name in outer scope. For additional information, see previous declaration at line '300' of 'c:\users\seppe\boost_1_48_0\boost\exception\detail\exception_ptr.hpp': Lines: 300 c:\users\seppe\boost_1_48_0\boost\exception\detail\exception_ptr.hpp 332

and the affected code:

296: inline
297: exception_ptr
298: current_exception_impl()
299:     {
300:     exception_detail::clone_base const * e=0;

<<snip>>

328:         try
329:             {
330:             throw;
331:             }
332:         catch(
333:         exception_detail::clone_base & e )
334:             {
335:             return exception_ptr(shared_ptr<exception_detail::clone_base const>(e.clone()));
336:             }

...

Well this is more of a false positive of the static analyzer, but can be avoided by changing the variable name of the caught exception.

Remark: A warning is generated for each caught exception in the method (see attached list).

Attachments (1)

warnings.txt (6.1 KB ) - added by seppe.de.clercq@… 11 years ago.
List of warnings

Download all attachments as: .zip

Change History (1)

by seppe.de.clercq@…, 11 years ago

Attachment: warnings.txt added

List of warnings

Note: See TracTickets for help on using tickets.