[cfe-dev] GNU extensions - different behaviour of g++ and clang for taking address of temporary array
Richard Smith via cfe-dev
cfe-dev at lists.llvm.org
Mon Feb 19 10:44:59 PST 2018
On 19 Feb 2018 10:31, "Aleksei Sidorin via cfe-dev" <cfe-dev at lists.llvm.org>
wrote:
Hi all,
Consider a test case:
#include <stdio.h>
typedef int a[];
void print(int *c) {
printf("%d\n", c[0]);
}
int main() {
print(a{2});
return 0;
}
`g++ -std=gnu++11 -fsyntax-only` fails to compile this code: "error: taking
address of temporary array". However, clang accepts it without any warnings
and there is no any ASan output for it. Could someone explain me if it a
GCC or Clang issue?
It's a GCC bug -- this code is valid. The array to pointer conversion is
used to convert the int[1] temporary to a pointer; a reference is not bound
to it.
(GCC's behaviour is not unreasonable, though, and perhaps we should warn on
such constructs. I would imagine the GCC diagnostic would be suppressed by
making c a pointer to const int?)
--
Best regards,
Aleksei Sidorin,
SRR, Samsung Electronics
_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180219/2167e447/attachment.html>
More information about the cfe-dev
mailing list