ETLCPP / etl

Embedded Template Library
https://www.etlcpp.com
MIT License
2.05k stars 373 forks source link

etl::message_broker does not compile, problem in span.h #788

Closed tunguskar closed 2 months ago

tunguskar commented 7 months ago

Hi there, used the test code from your repo and had the minimal example with the message router which works so far. But when I add the class (and header) for the message_broker from your test code like this:

  class Broker : public etl::message_broker
  {
  public:

    Broker()
      : message_broker()
    {
    }

    Broker(etl::message_router_id_t id)
      : message_broker(id)
    {
    }

    using etl::message_broker::receive;

    // Hook incoming messages and translate Message5 to Message4.
    void receive(const etl::imessage& msg) override
    {
      etl::message_broker::receive(msg);
    }
  };

I get a synstax error from the compiler from etl::span.h

image

tunguskar commented 7 months ago

I saw that already this failed

image

the error message says on the enum that on the enum there is a missing tag name. Currently Im using the last version of clang. When I remove the header the message is gone.

tunguskar commented 7 months ago

When I do it like this my example compiles image

jwellbelove commented 7 months ago

Does this compile OK for you?

#include "etl/message_broker.h"

enum
{
  MESSAGE0,
  MESSAGE1,
  MESSAGE2,
  MESSAGE3,
  MESSAGE4,
  MESSAGE5
};

class Broker : public etl::message_broker
{
public:

  Broker()
    : message_broker()
  {
  }

  Broker(etl::message_router_id_t id)
    : message_broker(id)
  {
  }

  using etl::message_broker::receive;

  // Hook incoming messages and translate Message5 to Message4.
  void receive(const etl::imessage& msg) override
  {
    etl::message_broker::receive(msg);
  }
};

int main()
{
  Broker broker;
}
tunguskar commented 7 months ago

Broker broker;

No, the first error is this image

tunguskar commented 7 months ago

Broker broker;

No, the first error is this image

Sorry for the German, it says Syntax error

tunguskar commented 7 months ago

Broker broker;

No, the first error is this image

Sorry for the German, it says Syntax error

image

jwellbelove commented 7 months ago

What version of the ETL are you using?

jwellbelove commented 7 months ago

What version of clang are you using?

jwellbelove commented 7 months ago

From the error lines it look like you are compiling for C++11 or above.

It seems to be having a problem with the template function definition:-

template <size_t OFFSET, size_t COUNT = etl::dynamic_extent>
ETL_NODISCARD ETL_CONSTEXPR
etl::span<element_type, COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET> subspan() const ETL_NOEXCEPT
jwellbelove commented 7 months ago

If you have created an etl::profile.h or set compiler ETL constants, what are they set to?

tunguskar commented 7 months ago

From the error lines it look like you are compiling for C++11 or above.

It seems to be having a problem with the template function definition:-

template <size_t OFFSET, size_t COUNT = etl::dynamic_extent>
ETL_NODISCARD ETL_CONSTEXPR
etl::span<element_type, COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET> subspan() const ETL_NOEXCEPT

Clang is 17.0.3 ETL is 20.38.5

I have no profile.h created in my test main I just use: #define ETL_CPP17_SUPPORTED 1

jwellbelove commented 7 months ago

Ubuntu 22.04 clang version 15.0.7

I've tried to run the complete unit test set for ETL 20.38.5, and the demo code above, but I get no errors.

tunguskar commented 7 months ago

Ubuntu 22.04 clang version 15.0.7

I've tried to run the complete unit test set for ETL 20.38.5, and the demo code above, but I get no errors.

Ok I tried to check if the cpp17 is activated in cmake environment. This seems ok so far. Have you set the profile.h file? If yes could I get it for a try?

jwellbelove commented 7 months ago

Ubuntu 22.04 clang version 15.0.7 ETL 20.38.5

Demo.cpp

#include <iostream>

#include "etl/message_broker.h"

enum
{
  MESSAGE0,
  MESSAGE1, 
  MESSAGE2,
  MESSAGE3,
  MESSAGE4,
  MESSAGE5
};

class Broker : public etl::message_broker
{
public:

  Broker()
    : message_broker()
  {
  }

  Broker(etl::message_router_id_t id)
    : message_broker(id)
  {
  }

  using etl::message_broker::receive;

  void receive(const etl::imessage& msg) override
  {
    etl::message_broker::receive(msg);
  }
};

int main()
{
  std::cout << "Demo\n";

  Broker broker;
}

Compiles without errors using this command line.

clang -I etl/include -lstdc++ -std=c++17 Demo.cpp -o Demo

jwellbelove commented 7 months ago

etl/platform.h will automatically determine many of the compiler and language properties.

jwellbelove commented 7 months ago

CMakeLists.txt

cmake_minimum_required(VERSION 3.5.0)
project(etl_demo_code LANGUAGES CXX)

add_executable(etl_demo
    Demo.cpp
  )

message(STATUS "Compiling for C++17")    
set_property(TARGET etl_demo PROPERTY CXX_STANDARD 17)

if ((CMAKE_CXX_COMPILER_ID MATCHES "MSVC"))
    message(STATUS "Using MSVC compiler")
    target_compile_options(etl_tests
            PRIVATE
            /Zc:__cplusplus
            )
endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
    message(STATUS "Using GCC compiler")
endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    message(STATUS "Using Clang compiler")
endif ()

target_include_directories(etl_demo
        PRIVATE
        ${PROJECT_SOURCE_DIR}/etl/include)

Invoke with:- cmake -DCMAKE_CXX_COMPILER="clang++" ./ cmake --build .

Output

-- Compiling for C++17
-- Using Clang compiler
-- Configuring done
-- Generating done
[ 50%] Building CXX object CMakeFiles/etl_demo.dir/Demo.cpp.o
[100%] Linking CXX executable etl_demo
[100%] Built target etl_demo
tunguskar commented 5 months ago

CMakeLists.txt

cmake_minimum_required(VERSION 3.5.0)
project(etl_demo_code LANGUAGES CXX)

add_executable(etl_demo
  Demo.cpp
  )

message(STATUS "Compiling for C++17")    
set_property(TARGET etl_demo PROPERTY CXX_STANDARD 17)

if ((CMAKE_CXX_COMPILER_ID MATCHES "MSVC"))
  message(STATUS "Using MSVC compiler")
  target_compile_options(etl_tests
          PRIVATE
          /Zc:__cplusplus
          )
endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
  message(STATUS "Using GCC compiler")
endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    message(STATUS "Using Clang compiler")
endif ()

target_include_directories(etl_demo
      PRIVATE
      ${PROJECT_SOURCE_DIR}/etl/include)

Invoke with:- cmake -DCMAKE_CXX_COMPILER="clang++" ./ cmake --build .

Output

-- Compiling for C++17
-- Using Clang compiler
-- Configuring done
-- Generating done
[ 50%] Building CXX object CMakeFiles/etl_demo.dir/Demo.cpp.o
[100%] Linking CXX executable etl_demo
[100%] Built target etl_demo

On which machine do you build the code? Is it a windows machine? I thought clang uses in the back the microsoft compiler on a windows machine. And there are some problems I think.

jwellbelove commented 5 months ago

I'm using clang on Ubuntu 22.04