https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127592

            Bug ID: 127592
           Summary: : [17 Regression] [reflection] -fsanitize=null rejects
                    template for over enumerators_of after P4101
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: philip at pobox dot com
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu
             Build: x86_64-pc-linux-gnu

Since r17-4197-g127bd0f40827 (P4101), compiling the testcase below with
  g++ -std=c++26 -freflection -fsanitize=null -c pr.cc
fails with "consteval-only value outside an immediate function context"
at the closing brace of enum_to_string (also with -fsanitize=vptr, and
therefore -fsanitize=undefined). It compiles without the sanitizer flag.
Bisected: r17-4197 rejects it with the flag; its parent
(e3457d211e27) accepts it. Still reproduces with the 2026-09-20
snapshot (549ec717abb7).
--- pr.cc ---
#include <meta>
#include <string>
template <typename E>
  requires std::is_enum_v<E>
std::string enum_to_string(E value) {
  template for (constexpr std::meta::info e :
                std::define_static_array(std::meta::enumerators_of(^^E))) {
    if (value == [:e:]) return std::string(std::meta::identifier_of(e));
  }
  return "<unknown>";
}
enum class Suit { Clubs, Diamonds, Hearts, Spades };
int main() { return enum_to_string(Suit::Clubs) == "Clubs" ? 0 : 1; }
--- end ---
Found in https://github.com/jbcoe/cc-protocol (tutorials/03_reflection.cc).
See also PR126017, the LTO regression from the same commit.

Reply via email to