Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compile with clang 16 and libc++ #2242

Merged
merged 2 commits into from
Jul 21, 2023

Conversation

owent
Copy link
Member

@owent owent commented Jul 20, 2023

Fixes #2241

Changes

  • Move destructor of SimpleLogRecordProcessor into .cc .
  • Use std::vector::assign to replace std::fill .

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@owent owent requested a review from a team July 20, 2023 14:21
Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the first issue:

I think the root cause is the forward declaration of LogRecordExporter.

Because of std::unique_ptr<LogRecordExporter>, the compiler needs to see the LogRecordExporter destructor, and the header file that declares it.

Please try to include the header file for LogRecordExporter instead.

@marcalff
Copy link
Member

Per build logs in this PR:

2023-07-20T14:35:30.4501309Z Warning: include-what-you-use reported diagnostics:
2023-07-20T14:35:30.4501835Z 
2023-07-20T14:35:30.4502487Z /home/runner/work/opentelemetry-cpp/opentelemetry-cpp/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h should add these lines:
2023-07-20T14:35:30.4503155Z #include <bits/chrono.h>                           // for microseconds
2023-07-20T14:35:30.4503659Z #include "opentelemetry/sdk/logs/exporter.h"       // for LogRecordExporter
2023-07-20T14:35:30.4504200Z #include "opentelemetry/sdk/logs/recordable.h"     // for Recordable
2023-07-20T14:35:30.4504529Z 
2023-07-20T14:35:30.4505149Z /home/runner/work/opentelemetry-cpp/opentelemetry-cpp/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h should remove these lines:
2023-07-20T14:35:30.4505824Z - #include <chrono>  // lines 8-8
2023-07-20T14:35:30.4506531Z - namespace opentelemetry { namespace v1 { namespace sdk { namespace logs { class LogRecordExporter; } } } }  // lines 20-20
2023-07-20T14:35:30.4507384Z - namespace opentelemetry { namespace v1 { namespace sdk { namespace logs { class Recordable; } } } }  // lines 21-21

Please add the following two lines:

#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/sdk/logs/recordable.h"

and remove the matching forward declarations,
in file sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h

Looks like unique_ptr is preventing to use forward declarations.

@owent
Copy link
Member Author

owent commented Jul 21, 2023

About the first issue:

I think the root cause is the forward declaration of LogRecordExporter.

Because of std::unique_ptr<LogRecordExporter>, the compiler needs to see the LogRecordExporter destructor, and the header file that declares it.

Please try to include the header file for LogRecordExporter instead.

The problem is ~SimpleLogRecordProcessor() override = default; need the definition of LogRecordExporter, because it's a member of SimpleLogRecordProcessor.

BatchLogRecordProcessor, BatchSpanProcessor have the similar declarations, do you think it's better to keep the similar includes here?

@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Merging #2242 (37f3dac) into main (a15a9b8) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2242   +/-   ##
=======================================
  Coverage   87.34%   87.34%           
=======================================
  Files         169      169           
  Lines        4902     4902           
=======================================
  Hits         4281     4281           
  Misses        621      621           
Impacted Files Coverage Δ
sdk/src/metrics/data/circular_buffer.cc 100.00% <100.00%> (ø)

@marcalff
Copy link
Member

About the first issue:
I think the root cause is the forward declaration of LogRecordExporter.
Because of std::unique_ptr<LogRecordExporter>, the compiler needs to see the LogRecordExporter destructor, and the header file that declares it.
Please try to include the header file for LogRecordExporter instead.

The problem is ~SimpleLogRecordProcessor() override = default; need the definition of LogRecordExporter, because it's a member of SimpleLogRecordProcessor.

BatchLogRecordProcessor, BatchSpanProcessor have the similar declarations, do you think it's better to keep the similar includes here?

Independently of forwards, I agree that moving code from *.h to *.cc is a good change in general.

My concern is that, even when this fix the immediate issue, there might be more cases where the use of forward declarations with std::unique_ptr causes problems (this is specific to unique_ptr, shared_ptr is working properly and does not need to see the destructor of T).

Revising every forward used in every std::unique_ptr will be a separate change anyway, to analyze in more details, so approving this change.

Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@marcalff marcalff merged commit 92a8a54 into open-telemetry:main Jul 21, 2023
42 checks passed
@owent owent deleted the fix_compile_with_clang16_libcxx branch July 26, 2023 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can not compile with clang 16 and libc++
2 participants