lf-lang / lingua-franca

Intuitive concurrent programming in any language
https://www.lf-lang.org
Other
231 stars 62 forks source link

Multiport compilation issue with minimal program #2100

Open erlingrj opened 10 months ago

erlingrj commented 10 months ago

This program:

target Cpp
reactor R1 {
  timer t(10 msec)
  output [2] out: int
  reaction(t) -> out {= =}
}
reactor R2{
  input in: int
  reaction(in) {= =}
}
main reactor {
  r1 = new R1()
  r2 = new[2] R2()
  r1.out -> r2.in
}

Fails to compile with nightly compiler. The error given is:

/home/erling/dev/examples-lingua-franca/Cpp/src-gen/Bank/Bank/R1.cc: In member function ‘void R1::Inner::reaction_1(const reactor::Timer&, reactor::Multiport<reactor::Output<int> >&)’:
/home/erling/dev/examples-lingua-franca/Cpp/src-gen/Bank/Bank/R1.cc:81:45: warning: unused parameter ‘out’ [-Wunused-parameter]
   81 |   reactor::Multiport<reactor::Output<int>>& out)  {
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /home/erling/dev/examples-lingua-franca/Cpp/src-gen/reactor-cpp-default/include/reactor-cpp/port.hh:18,
                 from /home/erling/dev/examples-lingua-franca/Cpp/src-gen/reactor-cpp-default/include/reactor-cpp/connection.hh:18,
                 from /home/erling/dev/examples-lingua-franca/Cpp/src-gen/reactor-cpp-default/include/reactor-cpp/reactor-cpp.hh:14,
                 from /home/erling/dev/examples-lingua-franca/Cpp/src-gen/Bank/Bank/R1.hh:9,
                 from /home/erling/dev/examples-lingua-franca/Cpp/src-gen/Bank/Bank/R1.cc:7:
/home/erling/dev/examples-lingua-franca/Cpp/src-gen/reactor-cpp-default/include/reactor-cpp/multiport.hh: In instantiation of ‘reactor::ModifableMultiport<T, A>::ModifableMultiport() [with T = reactor::Output<int>; A = std::allocator<reactor::Output<int> >]’:
/home/erling/dev/examples-lingua-franca/Cpp/src-gen/Bank/Bank/R1.cc:19:49:   required from here
/home/erling/dev/examples-lingua-franca/Cpp/src-gen/reactor-cpp-default/include/reactor-cpp/multiport.hh:99:22: error: use of deleted function ‘constexpr reactor::Multiport<T, A>::Multiport() [with T = reactor::Output<int>; A = std::allocator<reactor::Output<int> >]’
   99 |       : Multiport<T>() {} // NOLINT
      |                      ^
/home/erling/dev/examples-lingua-franca/Cpp/src-gen/reactor-cpp-default/include/reactor-cpp/multiport.hh:65:3: note: ‘constexpr reactor::Multiport<T, A>::Multiport() noexcept [with T = reactor::Output<int>; A = std::allocator<reactor::Output<int> >]’ is implicitly deleted because its exception-specification does not match the implicit exception-specification ‘noexcept (false)’
   65 |   Multiport() noexcept = default;
      |   ^~~~~~~~~
make[3]: *** [Bank/CMakeFiles/Bank.dir/build.make:90: Bank/CMakeFiles/Bank.dir/Bank/R1.cc.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [CMakeFiles/Makefile2:157: Bank/CMakeFiles/Bank.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:164: Bank/CMakeFiles/Bank.dir/rule] Error 2
make: *** [Makefile:182: Bank] Error 2

I am able to get around the error by removing the noexcept annotations on the Multiport constructor. But I don't exactly understand why.

cmnrd commented 10 months ago

Which compiler are you using, and what is its version?

erlingrj commented 10 months ago

I am using cmake 3.25.2 and g++ 9.4.0

cmnrd commented 10 months ago

Your compiler might be too old... This seems to be an issue with the C++ standard. The rules regarding noexcept on the constructor initially were relatively strict, but then they have been relaxed in subsequent releases of the standard. So technically, the generated code is correct, but an old compiler might disagree... Could you try with a newer compiler version?