Opened 9 years ago

Closed 9 years ago

#8813 closed Bugs (invalid)

compiler errors with gcc in c++11 mode

Reported by: oleg.alexandrov@… Owned by: Peter Dimov
Milestone: To Be Determined Component: smart_ptr
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc:

Description

This is related to ticket: https://svn.boost.org/trac/boost/ticket/7809

It shows up in both boost 1.54 and 1.53. It is missing in 1.52.

With g++ 4.7.0 (on SuSE 11, Linux 2.6.32.54, x86_64) using the options:

-O2 -g -Iinclude/boost-1_54 -std=gnu++0x -Wstrict-overflow=0 -Wall

I am getting:

error: no type named 'unspecified_bool_type' in 'class boost::shared_array<unsigned int>'

If I get rid of the option -std=gnu++0x then the error disappears.

Change History (6)

comment:1 by Peter Dimov, 9 years ago

Where are you getting this error?

comment:2 by oleg.alexandrov@…, 9 years ago

I am getting this error in compilation. I have a class which has a member function which does the following:

typedef typename boost::shared_array<T>::unspecified_bool_type unspecified_bool_type; operator unspecified_bool_type() const {

return m_data.size() > 0;

}

As per above, the error is triggered only by Boost 1.53 and 1.54 and only if -std=gnu++0x is on.

comment:3 by Peter Dimov, 9 years ago

unspecified_bool_type is not a documented part of shared_array and is not present when explicit operators are supported. You should either use

#if !defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS )

    explicit operator bool () const
    {
        return m_data.size() > 0;
    }

#else
    // your current definition
#endif

or define your own unspecified_bool_type.

Incidentally, your code above doesn't seem to compile, because m_data.size() > 0 returns a bool, which is not convertible to unspecified_bool_type.

comment:4 by oleg.alexandrov@…, 9 years ago

I had more time to study this in more detail. The problem is real, but apparently it is also compiler version dependent. Here's the exact way to reproduce it. It shows up with gcc 4.7.0 but it does not show up with gcc 4.4.4.

#include <boost/shared_array.hpp>

template <class T> class MyClass{

boost::shared_array<T> m_data;

typedef typename boost::shared_array<T>::unspecified_bool_type unspecified_bool_type; operator unspecified_bool_type() const {

return m_data;

}

public:

int get(){ return 2; }

};

int main(){

MyClass<int> M; std::cout << "value is " << M.get() << std::endl; return 0;

}

/shared/gcc/4.7.0/bin/g++ -c -std=gnu++0x -Iinclude/boost-1_54 bug.cc bug.cc: In instantiation of 'class MyClass<int>': bug.cc:20:16: required from here bug.cc:7:66: error: no type named 'unspecified_bool_type' in 'class boost::shared_array<int>'

If I remove the -std=gnu++0x or switch to gcc 4.4.4 then it works.

comment:5 by oleg.alexandrov@…, 9 years ago

But I see your point above, presumably this code should never work, I guess what you are saying some compilers are more lenient than what they should be.

comment:6 by Peter Dimov, 9 years ago

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