Ticket #8405 (closed Support Requests: fixed)

Opened 2 years ago

Last modified 2 years ago

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

Reported by: Volker Schöch <vschoech@…> Owned by: barendgehrels
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:


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

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


Change History

comment:1 Changed 2 years ago by barendgehrels

  • Type changed from Bugs to Support Requests
  • Severity changed from Problem to Not Applicable

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




&& 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 Changed 2 years ago by barendgehrels

  • Severity changed from Not Applicable to Cosmetic

comment:3 Changed 2 years ago by Volker Schöch <vschoech@…>

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 Changed 2 years ago by barendgehrels

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 Changed 2 years ago by barendgehrels

  • Milestone changed from To Be Determined to Boost 1.54.0

comment:6 Changed 2 years ago by barendgehrels

  • Status changed from new to closed
  • Resolution set to fixed

Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.