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

Warning: Multiple assignment operators specified for SpinLockMutex #2500

Closed
SaiHarshaK opened this issue Jan 22, 2024 · 3 comments · Fixed by #2501
Closed

Warning: Multiple assignment operators specified for SpinLockMutex #2500

SaiHarshaK opened this issue Jan 22, 2024 · 3 comments · Fixed by #2501
Assignees
Labels
bug Something isn't working

Comments

@SaiHarshaK
Copy link
Contributor

Describe your environment Describe any aspect of your environment relevant to the problem, including your platform, build system, version numbers of installed dependencies, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on main branch.

Issue exists in the main branch too, when building we see this warning pop up on using otlp metrics related code;

17>c:\work\ic3\d_nsshe_lcsminedgetmp\en-us\amd64chk\packages\opentelemetry.cpp.geneva.1.0.2300\api\include\opentelemetry\common\spin_lock_mutex.h(132) : error C4522: 'opentelemetry::v1::common::SpinLockMutex': multiple assignment operators specified

Steps to reproduce
Describe exactly how to reproduce the error. Include a code sample if applicable.
Build with this sample code:

#include "opentelemetry/exporters/etw/etw_tracer_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h"
#include "opentelemetry/metrics/provider.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h"
#include "opentelemetry/sdk/metrics/meter.h"
#include "opentelemetry/sdk/metrics/meter_provider.h"

using namespace OPENTELEMETRY_NAMESPACE;
using namespace opentelemetry::exporter::etw;
namespace otlp_exporter = opentelemetry::exporter::otlp;
namespace metrics_sdk = opentelemetry::sdk::metrics;
namespace metrics_api = opentelemetry::metrics;
namespace resource_ns = opentelemetry::sdk::resource;

    void InitOTelMetrics() 
    {
        // Initialize exporter
        otlp_exporter::OtlpGrpcMetricExporterOptions options;
        options.aggregation_temporality = static_cast<opentelemetry::v1::exporter::otlp::PreferredAggregationTemporality>(opentelemetry::v1::sdk::metrics::AggregationTemporality::kDelta);
        options.endpoint = "http://localhost:4317";
        auto exporter = otlp_exporter::OtlpGrpcMetricExporterFactory::Create(options);

        // Initialize metric reader
        metrics_sdk::PeriodicExportingMetricReaderOptions reader_options;
        reader_options.export_interval_millis = std::chrono::milliseconds(60 * 1000); // 1 min
        reader_options.export_timeout_millis  = std::chrono::milliseconds(500);
        std::unique_ptr<metrics_sdk::MetricReader> reader{
            new metrics_sdk::PeriodicExportingMetricReader(std::move(exporter), reader_options)};

        // Initialize MeterProvider
        resource_ns::ResourceAttributes attributes = {
            {"service", ServiceName}, {"_microsoft_metrics_account", "account"}, {"_microsoft_metrics_namespace", "counter"}
        };
        auto resource = resource_ns::Resource::Create(attributes);
        auto views = std::unique_ptr<metrics_sdk::ViewRegistry>(new metrics_sdk::ViewRegistry());
        auto provider = std::shared_ptr<metrics_api::MeterProvider>(new metrics_sdk::MeterProvider(std::move(views), resource));
        auto p = std::static_pointer_cast<metrics_sdk::MeterProvider>(provider);
        p->AddMetricReader(std::move(reader));
        metrics_api::Provider::SetMeterProvider(provider);
    }

What is the expected behavior?
No such warning is thrown

What is the actual behavior?
Warning C4522 is thrown.

Additional context
Add any other context about the problem here.

@SaiHarshaK SaiHarshaK added the bug Something isn't working label Jan 22, 2024
@github-actions github-actions bot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jan 22, 2024
@SaiHarshaK SaiHarshaK changed the title Multiple assignment operators specified for SpinLockMutex Warning: Multiple assignment operators specified for SpinLockMutex Jan 22, 2024
@marcalff
Copy link
Member

There are indeed two assignment operators in the code:

  SpinLockMutex &operator=(const SpinLockMutex &) = delete;
  SpinLockMutex &operator=(const SpinLockMutex &) volatile = delete;

What is surprising is that both are present since 2020-10-12, which is not recent, and this somehow builds.

The fix is to remove the volatile version.

@SaiHarshaK Could you confirm if the issue is resolved by removing the second line ?

Thanks.

@marcalff marcalff self-assigned this Jan 22, 2024
@lalitb
Copy link
Member

lalitb commented Jan 22, 2024

Which MSVC compiler version, as this seems to be a false warning for perfectly legal code? However, we may also discuss whether we really need a volatile specifier for the synchronization mechanism. One use-case could be to prevent the use/creation of synchronization object outside the scope of program flow.

@SaiHarshaK
Copy link
Contributor Author

Raised a PR if that helps.

Adding version info here.

C:\Work\IC3\nsshe\minedgetmp>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.15.26726 for x64

@marcalff marcalff removed the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants