Opened 10 years ago

Closed 10 years ago

#8405 closed Support Requests (fixed)

VC++ 2012 compiler warning C4189: '...' : local variable is initialized but not referenced

Reported by: Volker Schöch <vschoech@…> Owned by: Barend Gehrels
Milestone: Boost 1.54.0 Component: geometry
Version: Boost 1.52.0 Severity: Cosmetic
Keywords: VC++ 2012, warning, C4189, local variable is initialized but not referenced Cc:

Description

I'm using Microsoft Visual Studio 2012 to compile boost 1.52.0. I use compiler flag /W4. The following warnings (which we declared errors for our project) occur in geometry, regardless whether I'm compiling for x64 or x86:

\boost_1_52_0\boost\geometry\algorithms\detail\overlay\get_turns.hpp(140): error C4189: 'n' : local variable is initialized but not referenced
int const n = int(section.range_count);
\boost_1_52_0\boost\geometry\strategies\cartesian\distance_projected_point.hpp(161): error C4189: 'fp_strategy' : local variable is initialized but not referenced
fp_strategy_type fp_strategy
            = strategy::distance::services::get_similar
                <
                    Strategy, Point, fp_point_type
                >::apply(strategy);

Maybe it's possible to eliminate these warnings for the next boost version?

Change History (6)

comment:1 by Barend Gehrels, 10 years ago

Severity: ProblemNot Applicable
Type: BugsSupport Requests

The code is:

int const n = int(section.range_count); return boost::is_same

<

typename tag_cast

<

typename geometry::point_type<Geometry1>::type, areal_tag

::type,

areal_tag

::value

&& index1 == 0 && index2 >= n - 2

;

As you can see the variable n is referenced.

However, if is_same returns false, the variable is (at compiletime) indeed not referenced.

This can be solved by using another (and more complex) construction, not by just removing n.

This has currently no priority.

The advice is to check with /W3.

The same for fp_strategy, this strategy is used, be it sometimes only the static functions, but that is not known at that specific location.

I change the classification from "Bug" to "Support Request"

comment:2 by Barend Gehrels, 10 years ago

Severity: Not ApplicableCosmetic

comment:3 by Volker Schöch <vschoech@…>, 10 years ago

Thank you for looking into this. I have no issue with the code as it is. However, I do have an issue with the warning being triggered. If you know that the warning is triggered even though the code is fine, why not locally suppress the warning with #pragma warning(disable:4189)?

Compiling with /W3 is not an option for me; I will continue to suppress this warning specifically for boost::geometry. That's not a practical problem, I just think suppressing it locally in your code, with an appropriate comment, would be a better solution.

comment:4 by Barend Gehrels, 10 years ago

Yes, disabling might be an option. However, we get the chance then that gcc or clang still complain (did not check).

Another option is adding boost::ignore_unused_variable_warning(n); that is quite easy to do ;-) This is valid for all compilers, and is not taking runtime. I did that earlier for some strategies, so it can also be done for fp_strategy.

This might be done for most (but probably not all) your reported warning problems.

comment:5 by Barend Gehrels, 10 years ago

Milestone: To Be DeterminedBoost 1.54.0

comment:6 by Barend Gehrels, 10 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.