Mysterious Warning in Visual Studio (4180)

1>c:\program files\microsoft visual studio 10.0\vc\include\map(229): warning C4180: qualifier applied to function type has no meaning; ignored 1> d:\...\gmproject.h(122) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled 1> with 1> [ 1> _Kty=GMProject::DuplicateTy, 1> _Ty=GMProject::DuplicateFn 1> ] 

Well, my class has these typedefs (pTree is a container):

 typedef void *DuplicateFn(pTree&, const pTree&); enum DuplicateTy { SKIP, OVERWRITE, ASK }; typedef std::map<DuplicateTy, DuplicateFn> DuplicateMapTy; 

And lines 122, 123:

 static const DuplicateMapTy DuplicateFns; static DuplicateMapTy DuplicateFns_INIT(); 

How can I indicate that this map cannot change - and makes it static for the class? My goal is to create a map so that I can "get" a pointer to a function from an enumeration. (The client code will provide an enumeration, then the class itself decides the enumeration of the function).

+4
source share
1 answer

The problem has nothing to do with a map, which is a constant: this is a warning because the returned version type const std::map::at() is equal to const mapped_type& . This code also gives a warning:

 typedef void *DuplicateFn(); typedef std::map< int, DuplicateFn > DuplicateMapTy; DuplicateMapTy DuplicateFns; 

Type of map re-display at here

 const DuplicateFn& 

Although this warning does occur (although I'm not sure about this particular situation, it is justified by the standard), in this case there should be no harm to localize it locally for the code using the map or if you do not like the pragma hassle, wrap the function pointer in simple structure.

change , as Gorpek points out in the comment below, it is actually generated in this particular place, although the function is not used. It seems that the VS compiler is aggressive when looking for warnings: it considers declarations.

 template< class T > struct CheckMe { const T& at() //warning C4180 pops up { //gets not instantiated hence no error for missing returntype } }; CheckMe< DuplicateFn > check; 
+3
source

Source: https://habr.com/ru/post/1382866/


All Articles