Boost logo

Boost Users :

Subject: [Boost-users] [config] TI compiler warning "static local variables of extern inline function are not resolved to single copy"
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2011-11-04 10:28:19


Hello,

I use some boost libraries with a TI compiler. One of it's defects
is "static local variables of extern inline function are not resolved to
single copy". It emits a warning about it.

My typical workaround for this is making such a function non-inline. This
may require to move such a function definition out of a header file, if it
isn't a template function.

When I need a non-template function to be defined inside a header file, and
return an instance of a static variable, i can't just make that function
static (or put it into an unnamed namespace), because there will no longer
be a single instance of the returned variable.Therefore I came up with the
following:

instead of:

inline int& get_single_int()
{
  static int i = 0;
  return i;
}

I need:

template < class >
// not inline
int& get_single_int_impl()
{
  static int i = 0;
  return i;
}

inline int& get_single_int()
{
  return get_single_int_impl<void>();
}

I needed to make modifications in two places in boost to work around this
defect. I'll be happy to share those modifications, but first I wanted to
ask if anyone can think of a better/simpler workaround.

What comes into my mind, that could make this workaround more general, is
replacing the line "// not inline" with some macro BOOST_INLINE_STATIC_VAR
defined conditionally to 'inline' or nothing.

Thoughts?

Regards,
Kris



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net