constexpr constructor: A bug in GCC 4.5.0

S

Saeed Amrollahi

Dear All
Hi

AFAIK, A constexpr constructor is a simple constructor that it must
initialize the data members in the
member-initializer part and those initializations must involve only
potential constant expressions, and its body is empty.

The following class is compiled without error under g++ 4.5.0
// point.c++
struct Point {
int x, y;
constexpr point(int xx, int yy) : x(xx), y(yy) {}
constexpr point() { x = y = 0; } // constexpr constructor with non-
empty body
};

I used the following command for compilation:
g++ -c -std=c++0x point.c++ -o point

Is it a bug in g++?

-- Saeed Amrollahi
 
M

Marc

Saeed said:
AFAIK, A constexpr constructor is a simple constructor that it must
initialize the data members in the
member-initializer part and those initializations must involve only
potential constant expressions, and its body is empty.

The following class is compiled without error under g++ 4.5.0
// point.c++
struct Point {
int x, y;
constexpr point(int xx, int yy) : x(xx), y(yy) {}
constexpr point() { x = y = 0; } // constexpr constructor with non-
empty body
};

Use the same capitalization for Point everywhere...
I used the following command for compilation:
g++ -c -std=c++0x point.c++ -o point

Is it a bug in g++?

g++-4.5 did not implement constexpr, just some super-crude version to
let some code compile. g++-4.6 does way better:
In constructor 'constexpr point::point()':
error: uninitialized member 'point::x' in 'constexpr' constructor
error: constexpr constructor does not have empty body
 
S

Saeed Amrollahi

Saeed Amrollahi  wrote:


Use the same capitalization for Point everywhere...
Oh Sorry.


g++-4.5 did not implement constexpr, just some super-crude version to
let some code compile. g++-4.6 does way better:
Yes I checked that and you are right.
In constructor 'constexpr point::point()':
error: uninitialized member 'point::x' in 'constexpr' constructor
error: constexpr constructor does not have empty body
AFAIK, GCC hasn't release the g++ 4.6.0 yet (http://gcc.gnu.org)
How can I access/download the g++ 4.6.0?

TIA,
-- Saeed Amrollahi
 
M

Marc

Saeed said:
AFAIK, GCC hasn't release the g++ 4.6.0 yet (http://gcc.gnu.org)
How can I access/download the g++ 4.6.0?

You are right that it isn't released yet, I was talking of the current
development version. http://gcc.gnu.org, top right corner, below
"Releases", "Snapshots". For debian users (possibly ubuntu as well),
there is also a gcc-snapshot package in the distribution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top