[cfe-dev] GNU extensions - different behaviour of g++ and clang for taking address of temporary array
Aleksei Sidorin via cfe-dev
cfe-dev at lists.llvm.org
Tue Feb 20 00:40:34 PST 2018
Thank you for explanation Richard!
As I see, turning 'c' into 'const int *' doesn't suppress GCC
diagnostic. However, this is all information I need.
19.02.2018 21:44, Richard Smith пишет:
> On 19 Feb 2018 10:31, "Aleksei Sidorin via cfe-dev"
> <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>> wrote:
>
> Hi all,
>
> Consider a test case:
>
> #include<stdio.h>
>
> typedefinta[];
>
> voidprint(int*c) {
> printf("%d\n", c[0]);
> }
>
> intmain() {
> print(a{2});
> return0;
> }
>
> `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 <mailto:cfe-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
>
>
--
Best regards,
Aleksei Sidorin,
SRR, Samsung Electronics
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180220/7354b6b9/attachment.html>
More information about the cfe-dev
mailing list