[BUILD] Ignore deprecated warning#3845
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request aims to fix deprecated warning (C4996) in MSVC when including opentelemetry/logs/provider.h. The issue reported that users including this header for legitimate APIs (GetLoggerProvider/SetLoggerProvider) were encountering build failures due to deprecation warnings from internal implementation details involving the deprecated EventLogger APIs.
Changes:
- Adjusted pragma warning scopes to suppress deprecation warnings around internal uses of deprecated EventLogger/EventLoggerProvider types in both the Provider class and noop implementations
- Added explicit destructors to NoopEventLogger and NoopEventLoggerProvider classes
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| api/include/opentelemetry/logs/provider.h | Moved pragma warning suppressions to wrap public deprecated methods and private GetEventProvider() method that instantiates deprecated types |
| api/include/opentelemetry/logs/noop.h | Expanded pragma warning scope to cover entire NoopEventLogger and NoopEventLoggerProvider class definitions, added explicit destructors |
| # elif defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__) | ||
| # pragma GCC diagnostic push | ||
| # pragma GCC diagnostic ignored "-Wdeprecated-declarations" | ||
| # pragma GCC diagnostic warning "-Wdeprecated-declarations" |
There was a problem hiding this comment.
The pragma directive #pragma GCC diagnostic warning "-Wdeprecated-declarations" will cause deprecation warnings to be emitted as warnings for GCC, which contradicts the intent of suppressing these internal implementation warnings. This should be #pragma GCC diagnostic ignored "-Wdeprecated-declarations" to suppress the warnings like it was before, matching the behavior for MSVC which uses disable : 4996.
| # elif defined(__clang__) || defined(__apple_build_version__) | ||
| # pragma clang diagnostic push | ||
| # pragma clang diagnostic ignored "-Wdeprecated-declarations" | ||
| # pragma clang diagnostic warning "-Wdeprecated-declarations" |
There was a problem hiding this comment.
The pragma directive #pragma clang diagnostic warning "-Wdeprecated-declarations" will cause deprecation warnings to be emitted as warnings for Clang, which contradicts the intent of suppressing these internal implementation warnings. This should be #pragma clang diagnostic ignored "-Wdeprecated-declarations" to suppress the warnings like it was before, matching the behavior for MSVC which uses disable : 4996.
| # pragma GCC diagnostic warning "-Wdeprecated-declarations" | ||
| # elif defined(__clang__) || defined(__apple_build_version__) | ||
| # pragma clang diagnostic push | ||
| # pragma clang diagnostic warning "-Wdeprecated-declarations" |
There was a problem hiding this comment.
The pragma directive #pragma GCC diagnostic warning "-Wdeprecated-declarations" will cause deprecation warnings to be emitted as warnings for GCC, which contradicts the intent of suppressing these internal implementation warnings. This should be #pragma GCC diagnostic ignored "-Wdeprecated-declarations" to suppress the warnings like it was before, matching the behavior for MSVC which uses disable : 4996.
| # pragma GCC diagnostic warning "-Wdeprecated-declarations" | |
| # elif defined(__clang__) || defined(__apple_build_version__) | |
| # pragma clang diagnostic push | |
| # pragma clang diagnostic warning "-Wdeprecated-declarations" | |
| # pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
| # elif defined(__clang__) || defined(__apple_build_version__) | |
| # pragma clang diagnostic push | |
| # pragma clang diagnostic ignored "-Wdeprecated-declarations" |
| # pragma GCC diagnostic warning "-Wdeprecated-declarations" | ||
| # elif defined(__clang__) || defined(__apple_build_version__) | ||
| # pragma clang diagnostic push | ||
| # pragma clang diagnostic warning "-Wdeprecated-declarations" |
There was a problem hiding this comment.
The pragma directive #pragma clang diagnostic warning "-Wdeprecated-declarations" will cause deprecation warnings to be emitted as warnings for Clang, which contradicts the intent of suppressing these internal implementation warnings. This should be #pragma clang diagnostic ignored "-Wdeprecated-declarations" to suppress the warnings like it was before, matching the behavior for MSVC which uses disable : 4996.
| # pragma GCC diagnostic warning "-Wdeprecated-declarations" | |
| # elif defined(__clang__) || defined(__apple_build_version__) | |
| # pragma clang diagnostic push | |
| # pragma clang diagnostic warning "-Wdeprecated-declarations" | |
| # pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
| # elif defined(__clang__) || defined(__apple_build_version__) | |
| # pragma clang diagnostic push | |
| # pragma clang diagnostic ignored "-Wdeprecated-declarations" |
| # pragma GCC diagnostic warning "-Wdeprecated-declarations" | ||
| # elif defined(__clang__) || defined(__apple_build_version__) | ||
| # pragma clang diagnostic push | ||
| # pragma clang diagnostic warning "-Wdeprecated-declarations" |
There was a problem hiding this comment.
The pragma directive #pragma GCC diagnostic warning "-Wdeprecated-declarations" will cause deprecation warnings to be emitted as warnings for GCC, which contradicts the intent of suppressing these internal implementation warnings. This should be #pragma GCC diagnostic ignored "-Wdeprecated-declarations" to suppress the warnings like it was before, matching the behavior for MSVC which uses disable : 4996.
| # pragma GCC diagnostic warning "-Wdeprecated-declarations" | |
| # elif defined(__clang__) || defined(__apple_build_version__) | |
| # pragma clang diagnostic push | |
| # pragma clang diagnostic warning "-Wdeprecated-declarations" | |
| # pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
| # elif defined(__clang__) || defined(__apple_build_version__) | |
| # pragma clang diagnostic push | |
| # pragma clang diagnostic ignored "-Wdeprecated-declarations" |
| # pragma GCC diagnostic warning "-Wdeprecated-declarations" | ||
| # elif defined(__clang__) || defined(__apple_build_version__) | ||
| # pragma clang diagnostic push | ||
| # pragma clang diagnostic warning "-Wdeprecated-declarations" |
There was a problem hiding this comment.
The pragma directive #pragma clang diagnostic warning "-Wdeprecated-declarations" will cause deprecation warnings to be emitted as warnings for Clang, which contradicts the intent of suppressing these internal implementation warnings. This should be #pragma clang diagnostic ignored "-Wdeprecated-declarations" to suppress the warnings like it was before, matching the behavior for MSVC which uses disable : 4996.
| # pragma GCC diagnostic warning "-Wdeprecated-declarations" | |
| # elif defined(__clang__) || defined(__apple_build_version__) | |
| # pragma clang diagnostic push | |
| # pragma clang diagnostic warning "-Wdeprecated-declarations" | |
| # pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
| # elif defined(__clang__) || defined(__apple_build_version__) | |
| # pragma clang diagnostic push | |
| # pragma clang diagnostic ignored "-Wdeprecated-declarations" |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3845 +/- ##
==========================================
+ Coverage 89.99% 89.99% +0.01%
==========================================
Files 225 225
Lines 7168 7170 +2
==========================================
+ Hits 6450 6452 +2
Misses 718 718
🚀 New features to boost your workflow:
|
|
Could a test be tested for validation? |
Yes, tests are added. |
| list(REMOVE_ITEM COMMON_LOGS_FOO_COMPILE_OPTS | ||
| -Wno-error=deprecated-declarations) | ||
| set_target_properties( | ||
| common_logs_foo_library PROPERTIES COMPILE_OPTIONS |
There was a problem hiding this comment.
Would remove the option from the target property work? The option -Wno-error=deprecated-declarations seems added to the directory level at
opentelemetry-cpp/CMakeLists.txt
Line 197 in bb5fff0
There was a problem hiding this comment.
The code already builds in CI in maintainer mode, why do we need extra changes in CMakeLists.txt ?
|
CHANGELOG needs to be updated. |
| # if defined(_MSC_VER) | ||
| # pragma warning(push) | ||
| # pragma warning(disable : 4996) | ||
| # elif defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__) | ||
| # pragma GCC diagnostic push | ||
| # pragma GCC diagnostic ignored "-Wdeprecated-declarations" | ||
| # elif defined(__clang__) || defined(__apple_build_version__) | ||
| # pragma clang diagnostic push | ||
| # pragma clang diagnostic ignored "-Wdeprecated-declarations" | ||
| # endif | ||
|
|
There was a problem hiding this comment.
This header file declares a deprecated class:
class OPENTELEMETRY_DEPRECATED EventLogger
Not tested on windows, but I in my understanding:
- DECLARING a deprecated code does not raise a warning
- USING a deprecated code does raise a warning
so there should be no changes in file event_logger.h and event_logger_provider.h.
There was a problem hiding this comment.
I think this is different for MSVC. MSVC with /sdl fires C4996 at declaration sites too, not just usage, in that case the suppression here is needed.
There was a problem hiding this comment.
With this change, code is deprecated and the deprecation warning is always suppressed and ignored, due to the pragma added.
This makes no sense to me, why deprecating in the first place then ?
Given that this patch is already approved by two maintainers, and given how it unblocks an issue downstream in opentelemetry-cpp-contribs (geneva), I am not blocking this merge it so it can be part of the 1.25 release, but I don't agree with this change.
If we don't want deprecation warnings at all, why not remove the OPENTELEMETRY_DEPRECATED tag, and remove all the pragma pilled up on top, to achieve exactly the same effect ?
This area should be simplified in a follow up PR, in my opinion.
Preparing the 1.25 release with warnings disabled for now, again, to unblock downstream.
| # elif defined(__clang__) || defined(__apple_build_version__) | ||
| # pragma clang diagnostic push | ||
| # pragma clang diagnostic ignored "-Wdeprecated-declarations" | ||
| # endif |
There was a problem hiding this comment.
nit - not blocker, can be done in subsequent PR - this suppression block is repeated quite often in code. Probably we can use the macros
OTEL_INTERNAL_SUPPRESS_WARNING_PUSH
OTEL_INTERNAL_SUPPRESS_DEPRECATED
// ... code referencing deprecated types ...
OTEL_INTERNAL_SUPPRESS_WARNING_POP
lalitb
left a comment
There was a problem hiding this comment.
LGTM. Good to include in the new release if rest of the reviewers agree.
Fixes #3835
Changes
For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes