Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > constexpr constructor: A bug in GCC 4.5.0

Reply
Thread Tools

constexpr constructor: A bug in GCC 4.5.0

 
 
Saeed Amrollahi
Guest
Posts: n/a
 
      03-12-2011
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
 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      03-12-2011
Saeed Amrollahi wrote:

> 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:oint()':
error: uninitialized member 'point:' in 'constexpr' constructor
error: constexpr constructor does not have empty body
 
Reply With Quote
 
 
 
 
Saeed Amrollahi
Guest
Posts: n/a
 
      03-12-2011
On Mar 12, 5:23*pm, Marc <(E-Mail Removed)> wrote:
> Saeed Amrollahi *wrote:
> > 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 constructorwith non-
> > empty body
> > };

>
> Use the same capitalization for Point everywhere...
>

Oh Sorry.
> > 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:

Yes I checked that and you are right.
> In constructor 'constexpr point:oint()':
> error: uninitialized member 'point:' 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
 
Reply With Quote
 
Marc
Guest
Posts: n/a
 
      03-12-2011
Saeed Amrollahi wrote:

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: constexpr static member function Victor Bazarov C++ 1 03-02-2013 01:42 PM
Re: constexpr static member function Victor Bazarov C++ 0 03-01-2013 05:02 PM
constexpr references and constant expressions Inconnu C++ 1 11-16-2011 05:10 PM
initializer_list members not being constexpr anymore Rodolfo Lima C++ 0 06-28-2010 12:37 AM
What is the purpose of C++0X constexpr? jason.cipriani@gmail.com C++ 5 05-03-2008 09:31 AM



Advertisments