Repository navigation
Description
Problem
#4830 fixed the libc ambiguity from #4827 by making every fl:: copy of a libc function a template that loses ties to libc. Each wrapper looks like this:
template <typename FlLibcTag = void>
FASTLED_FORCE_INLINE void* memcpy(void* d, const void* s, size_t n) FL_NO_EXCEPT { return libc_impl::memcpy(d, s, n); }Nothing enforces that pattern. If someone adds a plain, non-template fl::strdup (or any other libc name), an unqualified strdup(...) call with a CRGB* or other fl type argument is ambiguous again. tests/fl/stl/adl_barrier.cpp only covers names that exist today.
#4833 (the -76 B follow-up) also showed that the wrapper must be FASTLED_FORCE_INLINE. With plain inline, GCC on ESP32-S3 emitted out-of-line clones (+98 B).
Goal
Add a lint rule that fails whenever the pattern is broken, for any libc name. Once it lands, #4832 (rename to fl_memcpy) is superseded and can be closed.
Requirements
-
A complete, fixed list of reserved names, kept as a table in
ci/lint_cpp_rs/src/lint_core/:- every function in C11
<string.h>,<stdlib.h>and<strings.h>; - POSIX and newlib/glibc extras:
strdup,strndup,strnlen,strcasecmp,strncasecmp,memccpy,mempcpy,bzero,bcopy,bcmp,index,rindex,strlcpy,strlcat,strtok_r,strerror_r,posix_memalign,memalign,reallocarray,strtoll,strtoull,strtof,strtold,atoll,abort,exit,setenv,unsetenv,srand,bsearch, etc.
The list must not be derived from the names
flcurrently has. - every function in C11
-
Declaration check (new checker in
ci/lint_cpp_rs/src/checkers/, modelled onbare_legacy.rs):- Applies to every function declared or defined inside
namespace flor any sub-namespace, insrc/**. - If the name is on the list, it must be preceded by
template <typename FlLibcTag = void>and declaredFASTLED_FORCE_INLINE. - The checker must handle multi-line signatures, attribute and inline macros,
static,constexpr, andextern "C"blocks.
- Applies to every function declared or defined inside
-
Exemptions:
- the implementation namespace
fl::libc_impl(declarations in the headers, definitions in*.cpp.hpp); - global-scope platform shims (newlib stubs and the like), because they are not in
fl.
There is no per-file allowlist: an exemption has to be a namespace rule, not a path.
- the implementation namespace
-
Compile back-stop: extend
tests/fl/stl/adl_barrier.cppto call every wrapper infl/stl/cstring.h,malloc.handcstdlib.hunqualified, with aCRGB*orfl::type argument, under no using-directive and under a using-directive forfl. That catches anything the text-based linter misses. -
Red-to-green evidence: linter tests (
lint_core/tests_checkers.rs) that fail on:- a plain
inlinemirror; - a template wrapper missing
FASTLED_FORCE_INLINE; - a mirror in a sub-namespace such as
fl::detail; - a multi-line declaration.
They must also pass on the current headers and on
libc_impl. - a plain
Out of scope
- Math functions (
abs,sqrt,sin, …) take arithmetic types, so argument-dependent lookup never reachesfl. printfandsnprintftakeconst char*, so the same applies.std::-colliding generics (swap,sort,move,begin, …) are handled byfl::adl_barrierfrom fix: CRGB and other fl types no longer make libc/std calls ambiguous (#4827) #4830. A matching rule that requires each overload of a barrier name to stay inside the barrier could be a follow-up.
Done when
bash lintenforces the rule on master with no allowlist entries.- The negative tests above fail as expected.
- glibc lint for c++ #4832 is closed as superseded.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
lint: exhaustive libc_mirror rule for fl:: libc-named functions (#4834)…