efriedma added a comment.

I think you're looking at old documentation?  Here's what the current page 
(https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html) has to say:

  In C, a compound literal designates an unnamed object with static or 
automatic storage duration. In C++, a compound literal designates a temporary 
object that only lives until the end of its full-expression. As a result, 
well-defined C code that takes the address of a subobject of a compound literal 
can be undefined in C++, so G++ rejects the conversion of a temporary array to 
a pointer. For instance, if the array compound literal example above appeared 
inside a function, any subsequent use of foo in C++ would have undefined 
behavior because the lifetime of the array ends after the declaration of foo.
  
  As an optimization, G++ sometimes gives array compound literals longer 
lifetimes: when the array either appears outside a function or has a 
const-qualified type. If foo and its initializer had elements of type char 
*const rather than char *, or if foo were a global variable, the array would 
have static storage duration. But it is probably safest just to avoid the use 
of array compound literals in C++ code.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124038/new/

https://reviews.llvm.org/D124038

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to