Modify

Ticket #5127 (closed Patches: fixed)

Opened 3 years ago

Last modified 20 months ago

Incorrect result_of usage in transform_iterator

Reported by: mimomorin@… Owned by: dave
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

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

Change History

Changed 3 years ago by mimomorin@…

A patch for transform_iterator.hpp (against trunk)

Changed 3 years ago by mimomorin@…

A patch for transform_iterator_test.cpp (against trunk)

Changed 3 years ago by mimomorin@…

A patch for transform_iterator_test's documents (against trunk)

comment:1 Changed 3 years ago by mimomorin@…

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 Changed 3 years ago by mimomorin@…

  • Milestone changed from To Be Determined to Boost 1.47.0

comment:3 Changed 3 years ago by mimomorin@…

  • Summary changed from Documentation of transform_iterator is incorrect to Incorrect result_of usage in transform_iterator

comment:4 Changed 3 years ago by Michel Morin <mimomorin@…>

Ping?

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

comment:5 Changed 2 years ago by jeffrey.hellrung

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

comment:6 Changed 2 years ago by jeffrey.hellrung

  • Status changed from new to closed
  • Resolution set to fixed

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

comment:7 follow-up: ↓ 9 Changed 20 months ago by TLBettens@…

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 Changed 20 months ago by dave

I support the latter change

comment:9 in reply to: ↑ 7 ; follow-up: ↓ 10 Changed 20 months ago by 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?

comment:10 in reply to: ↑ 9 ; follow-up: ↓ 12 Changed 20 months ago by anonymous

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 Changed 20 months ago by michel

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.

comment:12 in reply to: ↑ 10 Changed 20 months ago by TLBettens@…

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 Changed 20 months ago by TLBettens@…

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.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.