eclipse-paho / paho.mqtt.c

An Eclipse Paho C client library for MQTT for Windows, Linux and MacOS. API documentation: https://eclipse.github.io/paho.mqtt.c/
https://eclipse.org/paho
Other
1.98k stars 1.1k forks source link

Error building when using MQTTProperties.h: ISO C++ prohibits anonymous structs #1249

Open jsrivaya opened 2 years ago

jsrivaya commented 2 years ago

Describe the bug ISO C++ prohibits anonymous structs. There are anonymous struct definitions in MQTTProperties header

/**
 * Structure to hold an MQTT version 5 property of any type
 */
typedef struct
{
  enum MQTTPropertyCodes identifier; /**<  The MQTT V5 property id. A multi-byte integer. */
  /** The value of the property, as a union of the different possible types. */
  union {
    unsigned char byte;       /**< holds the value of a byte property type */
    unsigned short integer2;  /**< holds the value of a 2 byte integer property type */
    unsigned int integer4;    /**< holds the value of a 4 byte integer property type */
    struct {
      MQTTLenString data;  /**< The value of a string property, or the name of a user property. */
      MQTTLenString value; /**< The value of a user property. */
    };
  } value;
} MQTTProperty;

It can be fixed by giving it a type and name

/**
 * Structure to hold an MQTT version 5 property of any type
 */
typedef struct
{
  enum MQTTPropertyCodes identifier; /**<  The MQTT V5 property id. A multi-byte integer. */
  /** The value of the property, as a union of the different possible types. */
  union {
    unsigned char byte;       /**< holds the value of a byte property type */
    unsigned short integer2;  /**< holds the value of a 2 byte integer property type */
    unsigned int integer4;    /**< holds the value of a 4 byte integer property type */
    struct string_type {
      MQTTLenString data;  /**< The value of a string property, or the name of a user property. */
      MQTTLenString value; /**< The value of a user property. */
    } string_type;
  } value;
} MQTTProperty;

It can be silent by using -fms-extensions flag, but this is probably not the right thing to do.

To Reproduce Take a library trace as outlined in the README, and/or have a program or describe the steps to reproduce the behavior: Build your application source using -Werror=pedantic

~/.conan/data/paho-mqtt-c/1.3.10/_/_/package/5d725c629ca6508685c6dcfeb3cae54a8ba144f2/include/MQTTProperties.h:105:5: error: ISO C++ prohibits anonymous structs [-Werror=pedantic]

Expected behavior I would expect ISO C++ and avoid this Warnings which can be errors for some of us

Screenshots If applicable, add screenshots to help explain your problem.

Log files Please try to attach log files rather than pasting the log contents. It makes the issues easier to read.

Environment (please complete the following information):

Additional context Add any other context about the problem here.

icraggs commented 2 years ago

Unfortunately no-one has raised the issue before since 2017 when it was created.

To make the change you suggest now would be an interface change - application programs which used the header would have to change. I wouldn't want to do that without a major version update.

An alternative would be to change the union to a struct and remove the anonymous struct, but that would introduce a binary backward incompatiblity.