root-project / root

The official repository for ROOT: analyzing, storing and visualizing big data, scientifically
https://root.cern
Other
2.54k stars 1.23k forks source link

Error when using a specific pattern of conditional inclusion of <span> with C++17 #13032

Open pikacic opened 1 year ago

pikacic commented 1 year ago

Check duplicate issues.

Describe the bug

With ROOT v6-28-00-patches@v6-28-04-96-g9248a09 compiled with C++17 (not C++20) the code

#ifdef __has_include
#if __has_include(<span>)
#include <span>
#endif
#endif

(found in range/v3/range/access.hpp) causes an error in the interpreter:

/cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev4/Thu/ROOT/v6-28-00-patches/x86_64-centos7-gcc12-dbg/etc/cling/std.modulemap:312:10: error: module 'std.span' requires feature 'cplusplus20'
  module "span" {

Meaning that the interpreter thinks the header <span> exists, but it cannot be loaded.

What I find very surprising too, is that (still without C++20) I can do:

❯ root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.28/05                        https://root.cern |
  | (c) 1995-2023, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Jun 13 2023, 00:22:00                 |
  | From heads/v6-28-00-patches@v6-28-04-96-g9248a09                 |
  | With g++ (GCC) 12.1.0                                            |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

root [0] std::span<int> s
(std::span<int> &) {}
root [1] 

which looks wrong to me.

What is the expected behaviour?

__has_include(<span>) should evaluate to false in C++17 builds.

How to reproduce?

from lxplus.cern.ch

❯ . /cvmfs/sft-nightlies.cern.ch/lcg/views/dev4/Thu/x86_64-centos7-gcc12-dbg/setup.sh
❯ root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.28/05                        https://root.cern |
  | (c) 1995-2023, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Jun 13 2023, 00:22:00                 |
  | From heads/v6-28-00-patches@v6-28-04-96-g9248a09                 |
  | With g++ (GCC) 12.1.0                                            |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

root [0] #include <range/v3/range/access.hpp>
/cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev4/Thu/ROOT/v6-28-00-patches/x86_64-centos7-gcc12-dbg/etc/cling/std.modulemap:312:10: error: module 'std.span' requires feature 'cplusplus20'
  module "span" {
         ^
/cvmfs/sft-nightlies.cern.ch/lcg/views/dev4/Thu/x86_64-centos7-gcc12-dbg/include/range/v3/range/access.hpp:25:10: note: submodule of top-level module 'std' implicitly imported here
#include <span>
         ^
root.exe: /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-28-00-patches/src/ROOT/v6-28-00-patches/interpreter/llvm/src/tools/clang/lib/AST/DeclBase.cpp:1517: void clang::DeclContext::removeDecl(clang::Decl*): Assertion `Pos != Map->end() && "no lookup entry for decl"' failed.

ROOT version

v6-28-00-patches@v6-28-04-96-g9248a09

How did you install ROOT?

LCG nightly builds in /cvmfs/sft-nightlies.cern.ch

Which operating system are you using?

Linux CentOS 7

Additional context

No response

RoyBellingan commented 1 year ago

This is because they did that https://github.com/root-project/root/blob/05c2b9ef3ff35b9023eb7b9e20db412f5f8dd89b/core/foundation/inc/ROOT/span.hxx#L153

IE inject in the std namespace they own span implementation which is just asking for trouble

Axel-Naumann commented 1 year ago

@RoyBellingan I cannot follow yet, this header should only be found as ROOT/span.hxx, not as span?

I think I agree with @pikacic implicit verdict that this is a modules design issue...