https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108626

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Strictly speaking, in this case I think it isn't invalid, puts is a standard
function and implementation could treat it as a builtin with known behavior
(that it doesn't care about pointer equality of what it prints).
But clang++ does that even for
static const char* const a = "bla";
static const char b[] = "bla";
extern void foo (const char *);

int main() {
  foo(a);
  foo(b);
}
Another TU could have
#include <stdlib.h>

void
foo (const char *p)
{
  static const char *q;
  if (!q)
    q = p;
  else if (q == p)
    abort ();
}

This will fail even with GCC -fmerge-all-constants, but in that case we
document that the option may cause non-conforming behavior.
C++ says https://eel.is/c++draft/lex.string#9 and my reading of it is that
different
string literals can be overlapping or partially overlapping etc., but am not
convinced
it is ok to make those overlap other const objects.
C 17 says:
"String literals, and compound literals with const-qualified types, need not
designate distinct objects."
and
"This allows implementations to share storage for string literals and constant
compound literals with the same or overlapping representations."
note, but that still doesn't look like allowing them to overlap non-string
literal non-constant compound literals objects.

Reply via email to