Opened 5 years ago
Closed 5 years ago
#13423 closed Bugs (wontfix)
boost log misses user-defined operator<< in MSVC 2017 1.12.111.1002
Reported by: | Owned by: | Andrey Semashev | |
---|---|---|---|
Milestone: | To Be Determined | Component: | log |
Version: | Boost 1.65.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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.
Attachments (1)
Change History (2)
by , 5 years ago
Attachment: | example.zip added |
---|
comment:1 by , 5 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I have been able to reproduce this with Visual Studio 2017 v15.5.5, compiler version 19.12.25835. The program fails to use the custom operator<<
when compiled with this command line:
cl /Od /MD /EHsc /I <Boost root> -c <source file>
and succeeds when /Ob1 is added.
Unfortunately, this is a compiler bug that I cannot work around in the library. Turning optimizations on or off definitely should not influence function lookup rules. I recommend you report this to Microsoft.
minimal example