[clang] [Clang][Sema] Reject array prvalue operands (PR #140702)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue May 20 07:12:20 PDT 2025
AaronBallman wrote:
> > Is this going to break behavior in C?
>
> Array **prvalues** is C++11+ exclusive thing. Compound literals are lvalues in C
Ah, good point, I wasn't remembering that C and C++ are different in how they handle compound literals. And you can return a pointer to an array in C, but that's still an lvalue.
> Anyway, here is a check:
>
> ```shell
> $ build/bin/clang -fsyntax-only test.c
> test.c:2:3: warning: expression result unused [-Wunused-value]
> 2 | *((int []){ 1, 2, 3});
> | ^~~~~~~~~~~~~~~~~~~~~
> test.c:3:24: warning: expression result unused [-Wunused-value]
> 3 | ((int []){ 1, 2, 3}) + 0;
> | ~~~~~~~~~~~~~~~~~~~~ ^ ~
> 2 warnings generated.
> ```
Thank you!
https://github.com/llvm/llvm-project/pull/140702
More information about the cfe-commits
mailing list