[cfe-dev] Compound literals in C++: why rvalue?
Enea Zaffanella
zaffanella at cs.unipr.it
Wed Jan 11 07:14:57 PST 2012
We recently saw from clang sources that compound literals are classified
as lvalues in C, but not in C++ (when used as extensions).
Is this intentional and, if so, can someone provide a pointer to the
relevant documentation? (As far as we can tell, they are classified as
lvalues for both C/C++ in recent versions of gcc).
While passing, here is a testcase (using r147790) showing that a crash
is obtained when specifying -W[no-]address-of-temporary:
$ cat bug.cc
int (*pa)[1] = &(int[]) { 1 };
$ clang++ -c bug.cc
bug.cc:1:16: error: taking the address of a temporary object of type
'int [1]'
[-Waddress-of-temporary]
int (*pa)[1] = &(int[]) { 1 };
^~~~~~~~~~~~~~
1 error generated.
$ clang++ -Waddress-of-temporary -c bug.cc
bug.cc:1:16: warning: taking the address of a temporary object of type
'int [1]'
[-Waddress-of-temporary]
int (*pa)[1] = &(int[]) { 1 };
^~~~~~~~~~~~~~
clang: <path>/tools/clang/lib/AST/ExprConstant.cpp:2479: bool
EvaluateLValue(const clang::Expr*, <unnamed>::LValue&,
<unnamed>::EvalInfo&): Assertion `(E->isGLValue() ||
E->getType()->isFunctionType() || E->getType()->isVoidType() ||
isa<CXXTemporaryObjectExpr>(E)) && "can't evaluate expression as an
lvalue"' failed.
[...]
Enea.
More information about the cfe-dev
mailing list