On Sat, Dec 05, 2020 at 07:10:08PM +0100, Andrea Corallo via Gcc-help wrote: > "Stefan Franke" <s.franke@xxxxxxxxxxxx> writes: > > typedef struct { > > void (* const fun_ptr)(void); > > const long x; > > } x_t; > > > > Declares that fun_ptr and x both are const and cannot change. So these const value can safely be propagated out of loops if the pointer to is also const and can't change. The current compiler simply ignores that knowledge. > > > > I cannot judge if this is a bug or a not implemented feature. But in the current implementation only the c/c++ parser cares about const whereas the compiler passes do not check constness. > > You might be right if you change the code this way, but to begin with > how do you set 'fun_ptr' if the only way to access it is through a > pointer to const? I suspect this is not very much a realistic case. void f(void) { x_t x = { .x = 42; .fun_ptr = f; }; ... etc. The variable dies when the function returns, but other than that this works fine. Segher