3

I have included the reflect-cpp header into a source file. It compiles. However if I add:

-fsanitize=undefined

It no longer compiles and complains that:

/app/raw.githubusercontent.com/boost-ext/reflect/main/reflect:1442:35: error: non-constant condition for static assertion
 1442 |     static_assert(type_id_v<int>  != type_id_v<void>);
      |                   ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/app/raw.githubusercontent.com/boost-ext/reflect/main/reflect:1442:35: error: '(reflect::v1_2_5::<lambda()>::_FUN != reflect::v1_2_5::<lambda()>::_FUN)' is not a constant expression

You can see if you remove the -fsanitize=undefined it compiles again. This is a problem only on GCC, not on Clang.

5
  • Have you tested with multiple versions of GCC? Which version are you currently using? Commented Sep 25 at 17:57
  • 1
    I'm on GCC 14, and the same thing happened on GCC 15 in the link I placed on Compiler Explorer. Commented Sep 25 at 18:00
  • 1
    Reduced to void f(); void g(); static_assert(f != g);: godbolt.org/z/rYa6z7zMK . Appears to be a GCC bug. Commented Sep 25 at 18:34
  • 3
    GCC bug report gcc.gnu.org/bugzilla/show_bug.cgi?id=71962 Commented Sep 25 at 19:50
  • @cigien Oh my God, that's like two bugs I found in two compilers in like 30 minutes. ... Wait, that bug is from 2016? Hmm, so they're not going to fix it it seems. Commented Sep 25 at 20:33

1 Answer 1

3

As others have commented, this is a known bug in gcc and unlikely to get fixed anytime soon. There are workarounds to mitigate the issue:

  1. Annotate the function containing boost-ext/reflect/main/reflect:1442 with __attribute__((no_sanitize("undefined"))) See: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#id14
  2. Add the function to sanitizer ignorelist. See how to do that here: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#id16
  3. Pass -fno-sanitize for that specific file only

Commentary: I'm not sure why gcc can't simply re-route the checks to static_assert without instrumenting that path. static_assert will 'disappear' anyways so there is no point in instrumenting its inputs.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, it's been ten years and still no fix. Sad. I think I'll just disable fsanitize=memory for GCC.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.