Opened 8 years ago

Last modified 5 years ago

#10830 new Bugs

Clang static analyzer warns about <boost/graph/named_function_params.hpp>

Reported by: anonymous Owned by: Jeremiah Willcock
Milestone: To Be Determined Component: graph
Version: Boost 1.57.0 Severity: Problem
Keywords: Cc:

Description

When running the clang static analyzer (v3.4.1) on some code of mine that uses boost graph, it reports this warning about boost/graph/named_function_params.hpp:

/usr/local/include/boost/graph/named_function_params.hpp:240:5: warning: Address of stack memory associated with temporary object of type 'boost::param_not_found' returned to caller

return lookup_named_param_def<Tag, Args, param_not_found>::get(p, param_not_found()); ~

1 warning generated.

I believe that's a genuine error.

Attachments (1)

param_not_found_static_instance.patch (868 bytes ) - added by Diego Barrios Romero <eldruin@…> 6 years ago.
Workaround on boost 1.62 sources to get MSVC14 to compile

Download all attachments as: .zip

Change History (6)

comment:1 by anonymous, 7 years ago

vs2015 generates an error for this in x64 release build:

c:\boost\boost_1_59_0_vs2015\x64\boost\graph\named_function_params.hpp(240): error C4172: returning address of local variable or temporary

return lookup_named_param_def<Tag, Args, param_not_found>::get(p, param_not_found());

see also http: connect.microsoft.com/VisualStudio/feedback/details/1425276/false-positive-error-c4172-returning-address-of-local-variable-or-temporary

by Diego Barrios Romero <eldruin@…>, 6 years ago

Workaround on boost 1.62 sources to get MSVC14 to compile

comment:2 by Diego Barrios Romero <eldruin@…>, 6 years ago

This also affects boost 1.62 which cannot be compiled with VS2015 (MSVC14). I attached a patch with an ugly workaround.

It adds a static instance of the param_not_found structure. A reference to this "singleton" object will be returned if necessary. As the structure itself is empty, wrong code could not do much with it. Furthermore, I imagine the whole param_not_found is just a construct to get the whole named-parameter system to work and the actual object returned will never be used in this case.

I would be happy if someone reports a nicer solution. I would also be happy to submit this as a PR in github if you want.

comment:3 by fmilano@…, 5 years ago

This also affects boost 1.64 in VS2015 (MSVC14)

comment:4 by Petr Kmoch <petr.kmoch@…>, 5 years ago

I am getting the same in Boost 1.65.0 and VS 2017. It's quite annoying not to be able to use "warnings as errors" because of this.

comment:5 by aaron@…, 5 years ago

I get the same with Clang-5.0 on ubuntu 16.04

Note: See TracTickets for help on using tickets.