[Boost-bugs] [Boost C++ Libraries] #13423: boost log misses user-defined operator<< in MSVC 2017 1.12.111.1002

Subject: [Boost-bugs] [Boost C++ Libraries] #13423: boost log misses user-defined operator<< in MSVC 2017 1.12.111.1002
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2018-01-28 10:24:49


#13423: boost log misses user-defined operator<< in MSVC 2017 1.12.111.1002
---------------------------------+-----------------------------
 Reporter: matthew.malcomson@… | Owner: Andrey Semashev
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: log
  Version: Boost 1.65.0 | Severity: Problem
 Keywords: |
---------------------------------+-----------------------------
 Defining an `operator<<` on `std::ostream` for an enum that is used as the
 severity attribute in the `severity_logger_mt` source usually means that
 printing the severity attribute of a record in a custom formatter uses
 that override.

 With some particular optimisation options in MSVC (see below), and a setup
 where the function using the logging is not in the same translation unit
 but takes an argument of the severity enum type this behaviour goes away
 and instead the logging prints out the integer cast of that enum.

 {{{
 # Table of when the problem occurs under MSVC.
 # the "get INFO?" column is "NO" when the problem occurs
 # | Optimise References | Inline Function Expansion | Whole Program
 Optimisation | get INFO? |
 #
 |---------------------+---------------------------+----------------------------+-----------|
 # | false | disabled | false
 | NO |
 # | true | disabled | false
 | NO |
 # | false | only explicit inline | false
 | YES |
 # | true | only explicit inline | false
 | YES |
 # | false | disabled | true
 | ERROR |
 # | true | disabled | true
 | NO |
 # | false | only explicit inline | true
 | ERROR |
 # | true | only explicit inline | true
 | NO |
 }}}

 I haven't been able to reproduce this behaviour on Linux under either
 clang or gcc.

 A zip file of the smallest problematic example I've managed to find is
 attached.
 In the example, most of the code is in a file called `logger.cpp`.
 There are two functions in `example_project.cpp`, on is there for the
 executable to see, while the other that is simply there to

 On linux unzip, then make and run for both `gcc` and `clang` with `make
 all`.
 You can see that the severity is printed out as `INFO`.

 On Windows open the `temp_solution.sln` file with MSVC, click `Build all`,
 then run the resulting `example_project.exe` binary.
 You can see that the severity (and some other printouts of the enum) are
 printed out as `1`.
 If I define an override on the `basic_record_ostream` template, then
 placing an enum instance onto the logging stream picks up the override,
 while the severity argument doesn't.

 You can allow `Inline function expansion` under project properties ->
 C/C++ -> Optimization , this then picks up the user-defined override.

 In `example_project.cpp` there is a function `LogLevelFun()` that takes a
 `LogLevelEnum` as an argument.
 I do nothing with this function, but if it takes an integer as argument
 instead of the enum then the problem goes away.

-- 
Ticket URL: <https://svn.boost.org/trac10/ticket/13423>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2018-01-28 10:29:41 UTC