rstan icon indicating copy to clipboard operation
rstan copied to clipboard

Not compiling with clang19

Open bgoodri opened this issue 1 year ago • 8 comments
trafficstars

Summary:

Models do not compile with clang19. @SteveBronder or @WardBrian do you know what this means?

Description:

From https://www.stats.ox.ac.uk/pub/bdr/clang19/AovBay.log , which like rstanarm depends on rstan, StanHeaders, etc.

In file included from stanExports_onewaymodel.cc:5:
In file included from ./stanExports_onewaymodel.h:25:
In file included from /data/gannet/ripley/R/test-clang/StanHeaders/include/src/stan/model/model_header.hpp:11:
/data/gannet/ripley/R/test-clang/StanHeaders/include/src/stan/model/model_base_crtp.hpp:140:50: error: a template argument list is expected after a name prefixed by the template keyword [-Wmissing-template-arg-list-after-template-kw]
  140 |     return static_cast<const M*>(this)->template write_array(
      |                                                  ^
/data/gannet/ripley/R/test-clang/StanHeaders/include/src/stan/model/model_base_crtp.hpp:209:50: error: a template argument list is expected after a name prefixed by the template keyword [-Wmissing-template-arg-list-after-template-kw]
  209 |     return static_cast<const M*>(this)->template write_array(
      |                                                  ^

Reproducible Steps:

Try to compile a model with clang19

Current Output:

None

Expected Output:

A compiled stanmodel object

RStan Version:

2.31.x

R Version:

4.4.x

Operating System:

Linux

bgoodri avatar Jun 15 '24 12:06 bgoodri

From the error message, it looks like Clang 19 wants the empty template args <>, so it would look like this: (this)->template<> write_array(....

bob-carpenter avatar Jun 15 '24 13:06 bob-carpenter

Clang19 isn’t actually released yet, correct?

WardBrian avatar Jun 15 '24 13:06 WardBrian

I believe Bob is correct: https://github.com/llvm/llvm-project/pull/80801

WardBrian avatar Jun 15 '24 13:06 WardBrian

Just in case it might help with CI - the RHub project has a variety of docker containers with setups including clang19

andrjohns avatar Jun 15 '24 14:06 andrjohns

OK. Does the code need to test for clang version 19 or later or would making those lines be like Bob says be fine for other compilers too?

bgoodri avatar Jun 15 '24 15:06 bgoodri

When we open a PR to change model base our CI should tell us whether or not it’s a problem on older clang and GCC

WardBrian avatar Jun 15 '24 15:06 WardBrian

We should just be able to update. The syntax with the explicit <> should work on earlier compilers. But as @WardBrian says, the proof is in the CI.

bob-carpenter avatar Jun 16 '24 10:06 bob-carpenter

Ah, upstream resolved this in https://github.com/stan-dev/stan/pull/3228 (part of 2.34) by removing the template keyword in this case. I think adding the <> is equivalent, but removing the keyword seemed more direct

WardBrian avatar Jun 17 '24 13:06 WardBrian