Skip to content

Windows VS 2017 compiler complains about constexpr construct #7357

@wrowe

Description

@wrowe

Commit b41ba59 introduces the following construct;

constexpr absl::string_view NotReadyReason{"TLS error: Secret is not supplied by SDS"};

// This SslSocket will be used when SSL secret is not fetched from SDS server.
class NotReadySslSocket : public Network::TransportSocket {
public:
  // Network::TransportSocket
  void setTransportSocketCallbacks(Network::TransportSocketCallbacks&) override {}
  std::string protocol() const override { return EMPTY_STRING; }
  absl::string_view failureReason() const override { return NotReadyReason; }

which results in the following error compiling with on cl.exe 19.16.27031.0;

source/extensions/transport_sockets/tls/ssl_socket.cc(25): error C2131: expression did not evaluate to a constant
C:\_eb\execroot\envoy\external\com_google_absl\absl/strings/string_view.h(187): note: failure was caused by call
of undefined function or one not declared 'constexpr'
C:\_eb\execroot\envoy\external\com_google_absl\absl/strings/string_view.h(187): note: see usage of 'strlen'

The following dirt stupid hack results in clean compilation. I'll profess my ignorance, and ask if there is a better workaround?

--- a/source/extensions/transport_sockets/tls/ssl_socket.cc
+++ b/source/extensions/transport_sockets/tls/ssl_socket.cc
@@ -22,7 +22,7 @@ namespace TransportSockets {

 namespace {
 
-constexpr absl::string_view NotReadyReason{"TLS error: Secret is not supplied by SDS"};
+const char* NotReadyReason = "TLS error: Secret is not supplied by SDS";

 // This SslSocket will be used when SSL secret is not fetched from SDS server.
 class NotReadySslSocket : public Network::TransportSocket {
@@ -30,7 +30,7 @@ public:
   // Network::TransportSocket
   void setTransportSocketCallbacks(Network::TransportSocketCallbacks&) override {}
   std::string protocol() const override { return EMPTY_STRING; }
-  absl::string_view failureReason() const override { return NotReadyReason; }
+  absl::string_view failureReason() const override { return constexpr absl::string_view(NotReadyReason); }
   bool canFlushClose() override { return true; }
   void closeSocket(Network::ConnectionEvent) override {}
   Network::IoResult doRead(Buffer::Instance&) override { return {PostIoAction::Close, 0, false}; }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions