6.7.4 specifies as a constraint that:
An inline definition of a function with external linkage shall not contain a definition of a modifiable object with static or thread storage duration, and shall not contain a reference to an identifier with internal linkage.
So that would imply that in:
#if 1 /*OK*/
int const const_global=0;
inline int ret_const_global(void) { return const_global; }
int nonconst_global=0;
inline int ret_nonconst_global(void) { return nonconst_global; }
void noop(void) { static int const const_local_static = 42; }
#else
//constraint violations
static int const const_global=0;
inline int ret_const_global(void) { return const_global; }
static int nonconst_global=0;
inline int ret_nonconst_global(void) { return nonconst_global; }
#endif
the #if 1
block is OK, while the other isn't.
What I don't quite get is what the part about "a reference to an identifier with internal linkage" is supposed to mean.
Is mentioning an otherwise OK static "a reference to an identifier with internal linkage"?
inline int ret_const_local_static(void) {
static int const const_local_static = 42;
return const_local_static; //compiles but OK?
}
is taking an address of a static it?
inline int const* ret_ref_to_const_local_static(void) {
static int const const_local_static = 42;
static int const*const ref = &const_local_static;
return ref;
}
None of my compilers are issuing diagnostics for the last two examples (and I'd particularly like to use the last one, despite the fact that I might get different addresses in different compilation units if the inline version is used by the compiler) but are they conforming?
What is "a reference to an identifier with internal linkage" supposed to mean?
extern
." So I'd say the examples you want to use do not contain references to identifiers with internal linkage. – Ian Abbott