There is a constraint 6.7.4(p3):
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.
Consider the following example:
static const int i = 10;
void do_print(void);
inline void do_print(void){
printf("%d/n", i); //Reference to an identifier with internal linkage
//constraint violation
}
Here the inline definition of a function with external linkage uses an identifier with internal linkage. So according to 5.1.1.3(p1):
A conforming implementation shall produce at least one diagnostic message (identified in an implementation-defined manner) if a preprocessing translation unit or translation unit contains a violation of any syntax rule or constraint, even if the behavior is also explicitly specified as undefined or implementation-defined.
I expected the violation of this constraint is reported by the compiler somehow (some warning). But the code compiles just fine with no warnings or some other message produced.
The question is: Why is no diagnostic message produced in case of the constraint violation above?
-pedantic: “warning: static variable 'i' is used in an inline function with external linkage [-Wstatic-in-inline]”. - Eric Postpischilinlinewhile no file-scope declaration in the translation unit hasexternor does not haveinline.) And it says “An inline definition provides an alternative to an external definition, which a translator may use to implement any call to the function in the same translation unit. It is unspecified whether a call to the function uses the inline definition or the external definition.” - Eric Postpischil