[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
G++'s statements as expressions feature
From: |
address@hidden |
Subject: |
G++'s statements as expressions feature |
Date: |
Fri, 29 Feb 2008 18:54:33 -0800 (PST) |
User-agent: |
G2/1.0 |
Consider the following code:
#include <iostream>
int main()
{
std::cout << ({(void)123; "apple";}) << '\n'; // *
std::cout << ({(void)123; (const char*)"apple";}) << '\n';
}
The line marked * gives the following compilation error:
cd d:/home/3-autogc-nosplit/
make 2008/tests/t-22-bug.run
* Compiling 2008/tests/t-22-bug.cc DEBUG
g++ -g -O0 -W -Wall -Wpointer-arith -Wformat -ffast-math -mwindows -c
2008/tests/t-22-bug.cc -o 2008/tests/t-22-bug.o
2008/tests/t-22-bug.cc: In function `int main()':
2008/tests/t-22-bug.cc:5: invalid use of non-lvalue array
make: *** [2008/tests/t-22-bug.o] Error 1
Compilation exited abnormally with code 2 at Sat Mar 01 15:47:53
Compilation took 1 second
My question is why does the compiler generate this error? The line
that follows the bugged one compiles just fine.
My reason for asking this question is that I am writing a new
programming language that combines the best of C++ and Lisp and I will
be needing to use G++'s statements as expressions feature (as used
above). To get around the above bug I will need to insert the cast
(const char*) to the front of every literal string. I would very
much like to avoid having to do this.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- G++'s statements as expressions feature,
address@hidden <=