Skip to content
This repository was archived by the owner on Aug 20, 2026. It is now read-only.
This repository was archived by the owner on Aug 20, 2026. It is now read-only.

restrict.h calls index2sub<D> without including batch.h — g++ rejects the whole header #77

Description

@balbasty

Found while standing up the ASan/UBSan CI lane for fastfields-cpu-lib (#75). Not a runtime bug — a portability one, and a cheap fix.

What happens

restrict.h line 68 calls index2sub<D>:

offset_t sub[D]; index2sub<D>(j, isize, sub);

but its include list is only

#include"cuda_switch.h"
#include"spline.h"
#include"bounds.h"

index2sub lives in batch.h. The sibling resize.h, which makes the identical call at its line 78, does include it — with a comment naming exactly this dependency:

#include"utils.h"// prod
#include"batch.h"// index2sub

So restrict.h compiles today only because fastfields-cpu-impl/restrict.h happens to include kernels/batch.h — and, in fact, only under clang: cpu-impl includes kernels/restrict.hbeforekernels/batch.h, so at the point restrict.h is parsed the name is not yet declared.

Evidence

clang++ -std=c++11 (every CI job today) is happy. g++ 13.3 is not:

$ g++ -std=c++11 -O1 -DFF_STATIC_BOUNDS=0 -DFF_STATIC_SPLINES=0 -DFF_TEST_SPARSE -I. -c restrict.cpp
In file included from impl/restrict.h:4,
from restrict.cpp:8:
impl/kernels/restrict.h: In static member function 'static void ff::cpu::restrict::Multiscale<D, U, IX, IY, IZ>::restrict(...)':
impl/kernels/restrict.h:68:30: error: 'index2sub' was not declared in this scope
68 | offset_t sub[D]; index2sub<D>(j, isize, sub);
| ^~~~~~~~~

gcc's two-phase lookup binds the non-dependent template-name at definition context; clang is more forgiving here. Only restrict.cpp fails — the other eight modules build clean under g++.

Why it matters

It is one line, but it costs a real option: a sanitizer CI lane built with g++ needs no extra packages (libasan/libubsan ship with the compiler), whereas the clang equivalent needs a release-numbered libclang-rt-<N>-dev on top of clang. The lane added in fastfields-cpu-lib#84 went with clang + that extra package for exactly this reason.

Fix

 #include "cuda_switch.h"
#include "spline.h"
#include "bounds.h"
+#include "batch.h" // index2sub

mirroring resize.h. Worth a quick audit of the other module headers for the same include-what-you-use gap while in there.

🤖 Generated with Claude Code

https://claude.ai/code/session_016AjQcY78NgbagPSbPJRr6Z

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions