Opened 12 years ago

Closed 10 years ago

Last modified 10 years ago

#5127 closed Patches (fixed)

Incorrect result_of usage in transform_iterator

Reported by: mimomorin@… Owned by: Dave Abrahams
Milestone: Boost 1.47.0 Component: iterator
Version: Boost Development Trunk Severity: Problem
Keywords: transform_iterator Cc:

Description

The documentation of transform_iterator says that boost::result_of<UnaryFunction(Iterator::reference)> is used to determine the functor return type. But this is incorrect; the correct one is boost::result_of<const UnaryFunction(Iterator::reference)>.

This is because

  1. The dereference operator of transform_iterator is a const member function.
  2. So, in the dereference operator, UnaryFunction is treated as a const object.

Accordingly, the code and the test need to be changed too. I will attach patches for the code, the test and the documentation.

Attachments (3)

transform_iterator.patch (614 bytes ) - added by mimomorin@… 12 years ago.
A patch for transform_iterator.hpp (against trunk)
transform_iterator_test.patch (1.5 KB ) - added by mimomorin@… 12 years ago.
A patch for transform_iterator_test.cpp (against trunk)
transform_iterator_doc.patch (4.1 KB ) - added by mimomorin@… 12 years ago.
A patch for transform_iterator_test's documents (against trunk)

Download all attachments as: .zip

Change History (16)

by mimomorin@…, 12 years ago

Attachment: transform_iterator.patch added

A patch for transform_iterator.hpp (against trunk)

by mimomorin@…, 12 years ago

A patch for transform_iterator_test.cpp (against trunk)

by mimomorin@…, 12 years ago

A patch for transform_iterator_test's documents (against trunk)

comment:1 by mimomorin@…, 12 years ago

The documentation patch (transform_iterator_doc.patch) fixes only .html and .rst files, and it doesn't touch .pdf file. Should libs/iterator/doc/transform_iterator.pdf be regenerated?

comment:2 by mimomorin@…, 12 years ago

Milestone: To Be DeterminedBoost 1.47.0

comment:3 by mimomorin@…, 12 years ago

Summary: Documentation of transform_iterator is incorrectIncorrect result_of usage in transform_iterator

comment:4 by Michel Morin <mimomorin@…>, 11 years ago

Ping?

The test runs successfully on gcc 4.2 - 4.6 and clang (trunk).

comment:5 by jeffrey.hellrung, 11 years ago

(In [78121]) refs #5127 applying Michael Morin's patch for transform_iterator to trunk

comment:6 by jeffrey.hellrung, 10 years ago

Resolution: fixed
Status: newclosed

(In [78184]) merging from trunk; fix #5127 from M. Morin; fix for refs #5697

comment:7 by TLBettens@…, 10 years ago

Warning message introduced into release 1_50_0

This change went into release 1-50_0 and now causes a warning message to be emitted in Visual C++ version 10, perhaps others versions as well.

Compiler warning message:

2>c:\boostbuilding\boost_1_50_0\boost\iterator\transform_iterator.hpp(49): warning C4180: qualifier applied to function type has no meaning; ignored
2>          c:\boostbuilding\boost_1_50_0\boost\iterator\transform_iterator.hpp(70) : see reference to class template instantiation 'boost::detail::transform_iterator_base<UnaryFunc,Iterator,Reference,Value>' being compiled

Workaround is to either revert back to release 1_49_0 by removing the const:

boost::result_of</*const*/ UnaryFunction(Iterator::reference)>

, or disable the warning message using something like:

        #if defined(BOOST_MSVC)
        #   pragma warning (push)
        #   pragma warning (disable:4180) // warning C4180: qualifier applied to function type has no meaning; ignored
        #endif
          typedef typename ia_dflt_help<
              Reference
            , result_of<const UnaryFunc(typename std::iterator_traits<Iterator>::reference)>
          >::type reference;
        #if defined(BOOST_MSVC)
        #   pragma warning (pop)
        #endif

comment:8 by Dave Abrahams, 10 years ago

I support the latter change

in reply to:  7 ; comment:9 by Michel Morin, 10 years ago

Replying to TLBettens@…:

This change went into release 1-50_0 and now causes a warning message to be emitted in Visual C++ version 10, perhaps others versions as well.

Compiler warning message:

c:\boostbuilding\boost_1_50_0\boost\iterator\transform_iterator.hpp(49): 
warning C4180: qualifier applied to function type has no meaning; ignored

Thanks for the report.

Hmm, it's strange... IIUC, UnaryFunc cannot be a function type. Could you post a (minimal) reproducible code for this problem?

in reply to:  9 ; comment:10 by anonymous, 10 years ago

Replying to michel:

Replying to TLBettens@…:

This change went into release 1-50_0 and now causes a warning message to be emitted in Visual C++ version 10, perhaps others versions as well.

Compiler warning message:

c:\boostbuilding\boost_1_50_0\boost\iterator\transform_iterator.hpp(49): 
warning C4180: qualifier applied to function type has no meaning; ignored

Thanks for the report.

Hmm, it's strange... IIUC, UnaryFunc cannot be a function type. Could you post a (minimal) reproducible code for this problem?

Thanks Michel for looking into it. I was able to reproduce the warning message with this code in main.cpp:

#include <boost/algorithm/string.hpp>

int main()
{
  return 0;
}

Although not too exciting but perhaps helpful, the build log (CPPRocksProject.log) capturing the compile switches and warning message looks like:

Build started 8/22/2012 7:04:55 PM.
     1>Project "D:\SAGR RIC v3\SAGR Development\MSVC++ Solution Space (2010)\CPPRocksProject\CPPRocksProject.vcxproj" on node 2 (build target(s)).
     1>InitializeBuildStatus:
         Creating "Win32\Debug\SAGR.unsuccessfulbuild" because "AlwaysCreate" was specified.
       MakeDirsForCl:
         Creating directory "D:\SAGR RIC v3\SAGR Development\MSVC++ Solution Space (2010)\CPPRocksProject\Win32\Debug\dumy\dumy\..\..\SourceCode".
       ClCompile:
         C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /I"D:\SAGR RIC v3\SAGR Development\MSVC++ Solution Space (2010)\..\SourceCode\\" /IC:\BoostBuilding\boost_1_50_0\ /ZI /nologo /W4 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _MBCS /Gm /EHsc /RTCc /RTC1 /MTd /GS /Gy /fp:precise /fp:except /Za /Zc:wchar_t /Zc:forScope /GR /Fo"Win32\Debug\dumy\dumy\..\..\SourceCode\\" /Fd"Win32\Debug\vc100.pdb" /FR"Win32\Debug\dumy\dumy\..\..\SourceCode\\" /Gd /TP /wd4290 /wd4224 /analyze- /errorReport:prompt ..\..\SourceCode\main.cpp
         main.cpp
     1>c:\boostbuilding\boost_1_50_0\boost\iterator\transform_iterator.hpp(49): warning C4180: qualifier applied to function type has no meaning; ignored
                 c:\boostbuilding\boost_1_50_0\boost\iterator\transform_iterator.hpp(70) : see reference to class template instantiation 'boost::detail::transform_iterator_base<UnaryFunc,Iterator,Reference,Value>' being compiled
       ManifestResourceCompile:
         c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\rc.exe /nologo /fo"Win32\Debug\SAGR-x86-Debug.exe.embed.manifest.res" Win32\Debug\SAGR-x86-Debug_manifest.rc 
       Link:
         C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"D:\SAGR RIC v3\SAGR Development\MSVC++ Solution Space (2010)\CPPRocksProject\Win32\Debug\SAGR-x86-Debug.exe" /INCREMENTAL /NOLOGO /LIBPATH:C:\BoostBuilding\boost_1_50_0\lib32\ kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /ManifestFile:"Win32\Debug\SAGR-x86-Debug.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\SAGR RIC v3\SAGR Development\MSVC++ Solution Space (2010)\CPPRocksProject\Win32\Debug\SAGR-x86-Debug.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:\SAGR RIC v3\SAGR Development\MSVC++ Solution Space (2010)\CPPRocksProject\Win32\Debug\SAGR-x86-Debug.lib" /MACHINE:X86 "Win32\Debug\SAGR-x86-Debug.exe.embed.manifest.res"
         Win32\Debug\dumy\dumy\..\..\SourceCode\main.obj
       Manifest:
         c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\mt.exe /nologo /verbose /out:"Win32\Debug\SAGR-x86-Debug.exe.embed.manifest" /manifest "Win32\Debug\SAGR-x86-Debug.exe.intermediate.manifest"
         c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\rc.exe /nologo /fo"Win32\Debug\SAGR-x86-Debug.exe.embed.manifest.res" Win32\Debug\SAGR-x86-Debug_manifest.rc 
       LinkEmbedManifest:
         C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"D:\SAGR RIC v3\SAGR Development\MSVC++ Solution Space (2010)\CPPRocksProject\Win32\Debug\SAGR-x86-Debug.exe" /INCREMENTAL /NOLOGO /LIBPATH:C:\BoostBuilding\boost_1_50_0\lib32\ kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /ManifestFile:"Win32\Debug\SAGR-x86-Debug.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\SAGR RIC v3\SAGR Development\MSVC++ Solution Space (2010)\CPPRocksProject\Win32\Debug\SAGR-x86-Debug.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:\SAGR RIC v3\SAGR Development\MSVC++ Solution Space (2010)\CPPRocksProject\Win32\Debug\SAGR-x86-Debug.lib" /MACHINE:X86 "Win32\Debug\SAGR-x86-Debug.exe.embed.manifest.res"
         Win32\Debug\dumy\dumy\..\..\SourceCode\main.obj
         CPPRocksProject.vcxproj -> D:\SAGR RIC v3\SAGR Development\MSVC++ Solution Space (2010)\CPPRocksProject\Win32\Debug\SAGR-x86-Debug.exe
       BscMake:
         C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\bscmake.exe /nologo /o"D:\SAGR RIC v3\SAGR Development\MSVC++ Solution Space (2010)\CPPRocksProject\Win32\Debug\SAGR-x86-Debug.bsc" Win32\Debug\dumy\dumy\..\..\SourceCode\main.sbr
       FinalizeBuildStatus:
         Deleting file "Win32\Debug\SAGR.unsuccessfulbuild".
         Touching "Win32\Debug\SAGR.lastbuildstate".
     1>Done Building Project "D:\SAGR RIC v3\SAGR Development\MSVC++ Solution Space (2010)\CPPRocksProject\CPPRocksProject.vcxproj" (build target(s)).

Build succeeded.

Time Elapsed 00:00:06.67

comment:11 by Michel Morin, 10 years ago

OK, I figured out what the problem is. The problem is caused by the /Za compiler option. The /Za option is buggy and its use is not recommended (or rather, you shouldn't use it). By removing /Za, the warning gets disappeared. There is nothing wrong with the code in transform_iterator.hpp, and I think this warning problem would be "won't fix".

The solution to this problem is

Don't use /Za.

See the posts from Stephan T. Lavavej (Visual C++ libraries developer) such as this and this. Also, Boost's warning guidelines might be useful for you.

in reply to:  10 comment:12 by TLBettens@…, 10 years ago

Thanks. but I have to disagree. Turning off strict ISO/IEC compliance, i.e. enabling Microsoft extensions beyond the standard, isn't an advisable option for portable code. Let's not rely on a particular vender's extensions. We, as a community, really should be using any help from a compiler that helps us understand when we drift away. It is what it is, and if it's unfix able okay, but really, disabling the warning message seems prudent. Either way, thanks for considering it.

comment:13 by TLBettens@…, 10 years ago

That said, if the /Za option is broken in VC 2010, it hard to argue with trying to use it. Thanks again!! Michel, I'll disable the extension.

Note: See TracTickets for help on using tickets.