Opened 15 years ago

Closed 9 years ago

#1097 closed Bugs (fixed)

keyword.hpp generates many warnings C4180: qualifier applied to function type has no meaning; ignored

Reported by: Paul A. Bristow Owned by: Daniel Wallin
Milestone: To Be Determined Component: parameter
Version: Boost 1.34.0 Severity: Problem
Keywords: parameter keyword c4180 Cc:

Description

KEYWORD_050328_HPP

template <class Tag> struct keyword {

template <class T> typename aux::tag<Tag, T>::type const

this const is said to be meaningless

and could be commented out.

operator=(T& x) const {

typedef typename aux::tag<Tag, T>::type result; return result(x);

}

there are several others similar.

This creates a blizzard of warnings, even at normal warning level 3. (4180 is a level 1 warning).

#ifdef _MSC_VER # pragma warning(disable: 4127) conditional expression is constant. # pragma warning(disable: 4512) assignment operator could not be generated. # pragma warning(disable: 4180) qualifier applied to function type has no meaning; ignored #endif

produced a quiet compilation.

So I suggest either commenting out the const,

AND push the above disables, and popping at the end.

Change History (8)

comment:1 by Daniel Wallin, 15 years ago

Which compiler version is this? The const is in fact not meaningless. It's there so that:

template <class T>
void f(T&);
f(_x = 0);

can work.

comment:2 by anonymous, 15 years ago

I get a similar problem, this is the simplest code to reproduce it (in msvc-8.0)

#include <boost/bind.hpp>

template<typename T>
struct Foo
{
   Foo(T const& t_) : t(t_) {}
   T t;
};

typedef Foo<int> BarT;
//typedef int Bar;

class Moo
{
public:
   BarT GetBar () 
   {
      return BarT(42);
   }
};

int main()
{
   Moo moo;
   boost::bind(&Moo::GetBar, moo);
}

and the warning:

1>boost\boost.1.34.1\boost\boost\bind.hpp(1575) : warning C4180: qualifier applied to function type has no meaning; ignored
1>        boost\boost.1.34.1\boost\boost\bind.hpp(1609) : see reference to class template instantiation 'boost::_bi::add_cref<Pm,I>' being compiled
1>        with
1>        [
1>            Pm=Foo<int> (__thiscall Moo::* )(void),
1>            I=1
1>        ]
1>        test1\test1.cpp(25) : see reference to class template instantiation 'boost::_bi::dm_result<Pm,A1>' being compiled
1>        with
1>        [
1>            Pm=BarT (__thiscall Moo::* )(void),
1>            A1=Moo
1>        ]

The compiler seems to be choosing the member specialisation of add_cref:

template< class M, class T > struct add_cref< M T::*, 1 >
{
    typedef M const & type; // line 1575
};

rather than the member function specialisation:

template< class R, class T > struct add_cref< R (T::*) (), 1 >
{
    typedef void type; // line 1580
};

If you change the typedef of Bar to the int, all is well.

comment:3 by gregory.petrosyan@…, 14 years ago

this is still true for msvc-9 sp1

are there any plans to "fix" this issue?

comment:4 by Marshall Clow, 12 years ago

Both gcc 4.2.1 and clang (post 2.8 TOT) compile the sample code above w/o errors or warnings (-Wall, with boost 1.45.0).

Is this a msvc-only problem?

comment:5 by Paul A. Bristow, 12 years ago

If I remember right, this is a MS compiler error - that will not be fixed.

(But the push and pop method may not work - a limit of 50 or so push'n'pops!)

I'm not clear what the const does that is useful, so perhaps removing try it?

in reply to:  2 comment:6 by Mateusz Loskot, 9 years ago

Replying to anonymous:

I get a similar problem, this is the simplest code to reproduce it (in msvc-8.0) ...

1>boost\boost.1.34.1\boost\boost\bind.hpp(1575) : warning C4180: qualifier applied to function type has no meaning; ignored
1>        boost\boost.1.34.1\boost\boost\bind.hpp(1609) : see reference to class template instantiation 'boost::_bi::add_cref<Pm,I>' being compiled

FYI, this warning has been suppressed already by John Maddock in r57542 as part of fix for #3601.

Presumably, similar fix could be applied wherever it is necessary to close this report.

comment:7 by Paul A. Bristow, 9 years ago

Since MSVC 8 is now well obsolete, I suggest that we just close this ticket. If nobody disagrees, I will close it in a weeks time.

comment:8 by Paul A. Bristow, 9 years ago

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