Avoid clang 21/22 C++26-mode frontend crash in StringLiteral's variadic constructor#688
Avoid clang 21/22 C++26-mode frontend crash in StringLiteral's variadic constructor#688aruisdante wants to merge 1 commit into
Conversation
Clang 21.1+, 22.1.x, and current trunk crash (SIGSEGV in CheckParameterPacksForExpansion; assertion builds fail in LocalInstantiationScope::findInstantiationOf) when compiling any translation unit that includes reflect-cpp headers at -std=c++26, because StringLiteral's variadic constructor constrains itself with a requires-fold over decltype of its own parameter pack — a pattern that hits an open clang regression from the CWG2369 reapplication (llvm/llvm-project#198052; reported against reflect-cpp specifically in llvm/llvm-project#205000, where a minimized reproducer is attached). Constraining via template type parameters instead is semantically equivalent (each argument must still be exactly char) and compiles cleanly at -std=c++20/23/26 on all clang versions tested, including the affected ones. Authored with an AI assistant (Claude Code), reviewed and submitted by the account owner.
There was a problem hiding this comment.
Code Review
This pull request updates StringLiteral.hpp to constrain the StringLiteral constructor using template type parameters (std::same_as<char>...) instead of a requires-fold over decltype of the function parameter pack. This change, along with the addition of the <concepts> header, prevents compiler crashes in Clang 21/22 when compiling in C++26 mode. There are no review comments, and I have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Problem
Any translation unit that includes reflect-cpp headers fails to compile at
-std=c++26on clang 21.1+, 22.1.x, and current trunk: the compiler itself crashes (SIGSEGV inCheckParameterPacksForExpansion; assertion builds fail with"declaration not instantiated in this scope"inLocalInstantiationScope::findInstantiationOf) while parsingusingaliases toLiteral<...>/NamedTuple<...>types — e.g.parsing/Parser_duration.hppandparsing/Parser_result.hppare the first two headers hit.-std=c++23and earlier are unaffected.Root cause is an open clang regression from the CWG2369 reapplication, not a reflect-cpp bug: llvm/llvm-project#198052, reported against reflect-cpp specifically in llvm/llvm-project#205000 (an 11-line minimized reproducer, reduced from
rfl::internal::StringLiteral, is attached there). The trigger isStringLiteral's variadic constructor constraining itself with arequires-fold overdecltypeof its own function parameter pack, alongside the competingconst char (&)[N]constructor.Change
Constrain via template type parameters instead:
Semantically equivalent — each argument must still be exactly
char— and it sidesteps the clang bug on every version tested. Since the crash fires at parse time, this one constructor is the only change needed to make the whole library usable at C++26 on affected clangs; it can be reverted freely once fixed clang releases are common.Testing
Verified with clang 22.1.7 (libc++,
-fsyntax-onlyand full builds): with this change, includingrfl/json.hpp/rfl/cbor.hppcompiles cleanly at-std=c++20/23/26, and CBOR + JSON round-trips exercisingLiteral,Field,TaggedUnion, enums, optionals, and containers pass, including under ASan/UBSan. Please let your CI run the full suite to confirm.Disclosure
This fix was authored with an AI assistant (Claude Code) and reviewed/submitted by the account owner.