Skip to content

Compiling etw_logger_exporter.h with c++latest fails #3237

@jeremicmilan

Description

@jeremicmilan

Issue description

Otel does not compile with c++latest. More specifically, file etw_logger_exporter.h is causing issues.

Repro steps

Extract the attached zip file. Open the folder in latest Visual Studio 2022. Configure should run automatically. After that build all with Ctrl+Shift+B. The build should fail if Clang preset is selected. MSVC preset works fine.

Example error output

>------ Build All started: Project: otel_repro, Configuration: windows-ninja-clang-x64-windows-ninja-clang-x64-debug ------
  [1/2] Building CXX object CMakeFiles\otel_repro.dir\Debug\otel_repro.cpp.obj
  FAILED: CMakeFiles/otel_repro.dir/Debug/otel_repro.cpp.obj 
  C:\PROGRA~1\MIB055~1\2022\ENTERP~1\VC\Tools\Llvm\x64\bin\clang-cl.exe  /nologo -TP -DABSL_CONSUME_DLL -DHAVE_ABSEIL -DHAVE_MSGPACK -DOPENTELEMETRY_ABI_VERSION_NO=1 -DCMAKE_INTDIR=\"Debug\" -imsvcC:\otel_repro\out\build\windows-ninja-clang-x64\vcpkg_installed\x64-windows\include --target=amd64-pc-windows-msvc -fdiagnostics-absolute-paths  /DWIN32 /D_WINDOWS /EHsc /Ob0 /Od /RTC1 -MDd -Zi -std:c++latest /showIncludes /FoCMakeFiles\otel_repro.dir\Debug\otel_repro.cpp.obj /FdCMakeFiles\otel_repro.dir\Debug\otel_repro.pdb -c -- C:\otel_repro\otel_repro.cpp
  In file included from C:\otel_repro\otel_repro.cpp:1:
  In file included from C:\otel_repro\out\build\windows-ninja-clang-x64\vcpkg_installed\x64-windows\include\opentelemetry\exporters\etw\etw_logger_exporter.h:23:
  In file included from C:\otel_repro\out\build\windows-ninja-clang-x64\vcpkg_installed\x64-windows\include\opentelemetry\exporters\etw\etw_config.h:13:
  In file included from C:\otel_repro\out\build\windows-ninja-clang-x64\vcpkg_installed\x64-windows\include\opentelemetry\exporters\etw\etw_provider.h:36:
  In file included from C:\otel_repro\out\build\windows-ninja-clang-x64\vcpkg_installed\x64-windows\include\opentelemetry\exporters\etw\etw_traceloggingdynamic.h:8:
C:\otel_repro\out\build\windows-ninja-clang-x64\vcpkg_installed\x64-windows\include\opentelemetry\exporters\etw\TraceLoggingDynamic.h(2144,31): error : invalid bitwise operation between different enumeration types ('Type' and 'tld::InType')
   2144 |             _tld_ASSERT((type & InTypeMask) == (type & 0xff), "InType out of range");
        |                          ~~~~ ^ ~~~~~~~~~~
  C:\otel_repro\out\build\windows-ninja-clang-x64\vcpkg_installed\x64-windows\include\opentelemetry\exporters\etw\TraceLoggingDynamic.h(653,45): note: expanded from macro '_tld_ASSERT'
    653 |     #define _tld_ASSERT(exp, str) ((void)(!(exp) ? (__annotation(L"Debug", L"AssertFail", L"TraceLogging: " L#exp L" : " L##str), DbgRaiseAssertionFailure(), 0) : 0))
        |                                             ^~~
C:\otel_repro\out\build\windows-ninja-clang-x64\vcpkg_installed\x64-windows\include\opentelemetry\exporters\etw\TraceLoggingDynamic.h(2144,31): error : invalid bitwise operation between different enumeration types ('Type' and 'tld::InType')
   2144 |             _tld_ASSERT((type & InTypeMask) == (type & 0xff), "InType out of range");
        |                          ~~~~ ^ ~~~~~~~~~~
  C:\otel_repro\out\build\windows-ninja-clang-x64\vcpkg_installed\x64-windows\include\opentelemetry\exporters\etw\TraceLoggingDynamic.h(653,45): note: expanded from macro '_tld_ASSERT'
    653 |     #define _tld_ASSERT(exp, str) ((void)(!(exp) ? (__annotation(L"Debug", L"AssertFail", L"TraceLogging: " L#exp L" : " L##str), DbgRaiseAssertionFailure(), 0) : 0))
        |                                             ^~~
  C:\otel_repro\out\build\windows-ninja-clang-x64\vcpkg_installed\x64-windows\include\opentelemetry\exporters\etw\TraceLoggingDynamic.h(2289,13): note: in instantiation of member function 'tld::EventMetadataBuilder<std::vector<unsigned char>>::AddFieldInfo' requested here
   2289 |             AddFieldInfo(InMetaScalar, type, fieldTags);
        |             ^
  C:\otel_repro\out\build\windows-ninja-clang-x64\vcpkg_installed\x64-windows\include\opentelemetry\exporters\etw\etw_provider.h(483,19): note: in instantiation of function template specialization 'tld::EventMetadataBuilder<std::vector<unsigned char>>::AddField<char>' requested here
    483 |           builder.AddField(name, tld::TypeBool8);
        |                   ^
  2 errors generated.
  ninja: build stopped: subcommand failed.

Build All failed.

Proposed fix

Do appropriate cast of different integer/enum types in first line of AddFieldInfo.

Current line:

_tld_ASSERT((type & InTypeMask) == (type & 0xff), "InType out of range");

Potential fix:

_tld_ASSERT((type & (Type)InTypeMask) == (type & 0xff), "InType out of range");

Metadata

Metadata

Labels

bugSomething isn't workingtriage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions