gcc/ChangeLog: * doc/extend.texi (attribute alias, weak, weakref): Mention that the target of an alias must have the same type as the alias itself. diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index ec99c38a607..6f602140bfa 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -2558,7 +2558,9 @@ __attribute__ ((access (write_only, 1, 2), access (read_write, 3))) int fgets (c @item alias ("@var{target}") @cindex @code{alias} function attribute The @code{alias} attribute causes the declaration to be emitted as an -alias for another symbol, which must be specified. For instance, +alias for another symbol, which must have been previously declared with +the same type. Declaring an alias with a different type than the target +is undefined and may be diagnosed. For instance, @smallexample void __f () @{ /* @r{Do something.} */; @} @@ -3922,9 +3924,10 @@ results in warning on line 5. The @code{weak} attribute causes the declaration to be emitted as a weak symbol rather than a global. This is primarily useful in defining library functions that can be overridden in user code, though it can -also be used with non-function declarations. Weak symbols are supported -for ELF targets, and also for a.out targets when using the GNU assembler -and linker. +also be used with non-function declarations. The overriding symbol must +have the same type as the declaration of the weak symbol. Weak symbols +are supported for ELF targets, and also for a.out targets when using +the GNU assembler and linker. @item weakref @itemx weakref ("@var{target}") @@ -3932,7 +3935,8 @@ and linker. The @code{weakref} attribute marks a declaration as a weak reference. Without arguments, it should be accompanied by an @code{alias} attribute naming the target symbol. Optionally, the @var{target} may be given as -an argument to @code{weakref} itself. In either case, @code{weakref} +an argument to @code{weakref} itself. The the @var{target} must have +the same type as the declaration. In either case, @code{weakref} implicitly marks the declaration as @code{weak}. Without a @var{target}, given as an argument to @code{weakref} or to @code{alias}, @code{weakref} is equivalent to @code{weak}. @@ -3951,7 +3955,9 @@ definition to be given for the target symbol. If the target symbol is only referenced through weak references, then it becomes a @code{weak} undefined symbol. If it is directly referenced, however, then such strong references prevail, and a definition is required for the -symbol, not necessarily in the same translation unit. +symbol, not necessarily in the same translation unit. The definition +must have the same type as the alias, otherwise the behavior is +undefined. The effect is equivalent to moving all references to the alias to a separate translation unit, renaming the alias to the aliased symbol,