https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85662
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jason at gcc dot gnu.org --- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> --- In any case, I think the problem is related to the delayed folding, C++ constexpr handling not liking pointer constants and fold_offsetof_1 done as pointer addition rather than integer addition. With delayed folding and fold_build_pointer_plus called by fold_offsetof_1 the nested expressions aren't really folded. We could easily fix it up by doing a cp_fold (together with recursive cp_fold_r though, because cp_fold isn't fully recursive) on the result of fold_offsetof in the C++ FE, that way we'd get a constant whenever possible. On the other side, we wouldn't then reject __builtin_offsetof used with not valid constexpr expressions in the second argument (say out of bound array access etc. subtracted from itself). Say: constexpr int a[5]; struct S { int b, c[5]; }; constexpr int d = __builtin_offsetof (S, c[(&a[6] - &a[6]) + 2]); Another possibility is in fold_offsetof_1, if we detect the TREE_CONSTANT base, if it is a pointer typed INTEGER_CST, build corresponding sizetype INTEGER_CST instead and use normal PLUS_EXPR folding (or do we actually want any folding at all?) instead of fold_build_pointer_plus.