Quantcast

MinGW Question on versions and Class Constructors

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

MinGW Question on versions and Class Constructors

Clayton Weaver
I'm using MInGW 4.8.1 which gives me issues with class constructors. For example, 

class Punct_stream{
public:
Punct_stream(istream& is) : source{is}, sensitive{true} {}
//...
private:
istream& source; // character source
bool sensitive; // is the stream case-sensitive?
};

The compiler fails with: 

error: invalid initialization of non-const reference of type 'std::istream& {aka std::basic_istream<char>&}' from an rvalue of type '<brace-enclosed initializer list>'

My main question is does this compile correctly in 4.9.3 and if so how do I go about moving from 4.8.1 to 4.9.3? 

-Clayton Weaver

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: MinGW Question on versions and Class Constructors

K. Frank
Hello Clayton!

On Tue, Mar 22, 2016 at 7:04 PM, Clayton Weaver <[hidden email]> wrote:

> I'm using MInGW 4.8.1 which gives me issues with class constructors. For
> example,
>
> class Punct_stream{
> public:
> Punct_stream(istream& is) : source{is}, sensitive{true} {}
> //...
> private:
> istream& source; // character source
> bool sensitive; // is the stream case-sensitive?
> };
>
> The compiler fails with:
>
> error: invalid initialization of non-const reference of type 'std::istream&
> {aka std::basic_istream<char>&}' from an rvalue of type '<brace-enclosed
> initializer list>'
>
> My main question is does this compile correctly in 4.9.3

Your code compiles without error for me using a mingw-w64 build of
gcc 4.9.2:

   g++ --version
   g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 4.9.2

(Note, mingw-w64 is a separate project, distinct from mingw, with its
own mailing list.  However, this seems likely to be a core gcc issue,
rather than something specific to mingw or mingw-w64, so maybe this
answer helps you.)

> and if so how do I go about moving from 4.8.1 to 4.9.3?

I haven't used mingw's 4.9.3, but it has been announced on this list as:

   "GCC-4.9.3 is now our current release"

I'm not certain about istream's constructors -- and I would expect the
later versions of gcc to be more correct than the earlier, so you code
is probably correct -- but if a class has an explicit "list-initializer"
constructor, then the constructor calls myclass{x} (curly braces) and
myclass(x) (parentheses) can behave differently, possibly leading to
this kind of error,  (Also, I don't know how this interacts with references,
as in your code.)

This can be annoying (I've tripped over it a couple of times.), as it breaks
the new "uniform initialization" syntax, which, because of this, isn't
fully uniform.

> -Clayton Weaver


Good luck.


K. Frank

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: MinGW Question on versions and Class Constructors

Keith Marshall
In reply to this post by Clayton Weaver
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 22/03/16 23:04, Clayton Weaver wrote:

> I'm using MInGW 4.8.1 which gives me issues with class
> constructors. For example,
>
> class Punct_stream{ public: Punct_stream(istream& is) : source{is},
> sensitive{true} {} //... private: istream& source; // character
> source bool sensitive; // is the stream case-sensitive? };
>
> The compiler fails with:
>
> error: invalid initialization of non-const reference of type
> 'std::istream& {aka std::basic_istream<char>&}' from an rvalue of
> type '<brace-enclosed initializer list>'

FWIW, I see exactly the same when I compile with the native GCC-4.8.2,
on my LinuxMint Debian system, so this isn't MinGW specific; (I also
see the same with mingw32-g++ v4.8.2, on the same host).

> My main question is does this compile correctly in 4.9.3

Again on the LinuxMint host, the mingw32-g++ v4.9.3 cross-compiler,
which I used to build the GCC-4.9.3 now offered by MinGW.org, compiles
it correctly with -std=gnu++11, but not with -std=c++11; the GCC-5.3.0
cross-compiler, on which I am now working, compiles it correctly with
either option.

> and if so how do I go about moving from 4.8.1 to 4.9.3?

With mingw-get:

  mingw-get update
  mingw-get upgrade

(or the equivalent operations from the mingw-get GUI).  Right now,
this will upgrade GCC to v4.9.3; in a few days, I hope to have a
release of GCC-5.3.0 ready to go.

- --
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (GNU/Linux)

iQIcBAEBAgAGBQJW8p83AAoJEMCtNsY0flo/2DEP+gMs+oQzph4mel4k0qEfJsmO
VNo0LuNdE7/alzRhnIxvuJZMQdB0gPvuwBuBAVzkBECRBbjLUXtNSPCnH/heSGOX
wuBuvG9ZFEoRaTrXMXd9k3DRLBgA79WkouHjDeVdZVjwGKRwcXF+s9LNmR5OYkmM
G2S53e98WLpEyPBWZGPu/2vQIZcReNRTSWqljqdFE8HyuGlMNXXRDEnNfKZ2vaL6
mqPawZASuhOiMW4yvd25MHoAM0YFipPA4FvutVhrG+ZGutl51t8O0vdpkfazQtZN
edXT2VyGWfo1oe1xt8DTf1V8+q8pFoznBCAF7eNwieZIvPkCSwCh1uWBo/QxUumo
wWWpeC69eqSMXWY7LNMiaKbveBlwfGfT9Lg4+RYkghsHHIJEtwmQc5CM61SCLntX
P8QIkyDMTaOlJzi9e+CxP36MiScfKxAMlH8NV7It7DtDU488jRUDs7JFfdT9aaJw
0IcfapI3OIZ0uYlYNd/4beUZgWsMenueri9EGiDCJRxrVRbABIzYzbgfb2YAZSQ8
3n3pguwvhh/nfi/oaVPKbV5Y8Czg1flee7mbrd1GTOEHo5Kgf16kmi7TNlo3f0TJ
gM9ThfE+i5u+jtkd4Sx7XjpIUmf/WzLT8SG7Io63eaySsuAEe6NOzgoMuTwLxiYL
UYxeRhVmD8TA+iseGo5O
=ix+b
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: MinGW Question on versions and Class Constructors

K. Frank
Hi Keith!

On Wed, Mar 23, 2016 at 9:50 AM, Keith Marshall
<[hidden email]> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 22/03/16 23:04, Clayton Weaver wrote:
>> I'm using MInGW 4.8.1 which gives me issues with class
>> constructors. For example,
>>
>> class Punct_stream{ public: Punct_stream(istream& is) : source{is},
>> sensitive{true} {} //... private: istream& source; // character
>> source bool sensitive; // is the stream case-sensitive? };
>>
>> The compiler fails with:
>>
>> error: invalid initialization of non-const reference of type
>> 'std::istream& {aka std::basic_istream<char>&}' from an rvalue of
>> type '<brace-enclosed initializer list>'
>
> FWIW, I see exactly the same when I compile with the native GCC-4.8.2,
> on my LinuxMint Debian system, so this isn't MinGW specific; (I also
> see the same with mingw32-g++ v4.8.2, on the same host).
>
>> My main question is does this compile correctly in 4.9.3
>
> Again on the LinuxMint host, the mingw32-g++ v4.9.3 cross-compiler,
> which I used to build the GCC-4.9.3 now offered by MinGW.org, compiles
> it correctly with -std=gnu++11, but not with -std=c++11; the GCC-5.3.0
> cross-compiler, on which I am now working, compiles it correctly with
> either option.

I should have mentioned that with my 4.9.2 mingw-w64 test, I compiled
successfully with "-std=c++11" (as well as with -std=gnu++11, -std=c++14,
and -std=gnu++14).  (As expected, without the -std flag, the compile failed,
because initializer lists are new to c++11.)

It's a little odd that Keith's 4.9.3 needed "-std=gnu++11" to compile Clayton's
code, but my 4.9.2 worked with "-std=c++11".  But, no matter ...

> ...
> Regards,
> Keith.


Best.


K. Frank

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: MinGW Question on versions and Class Constructors

Clayton Weaver
Thanks. That fixed it. I was hoping it was just a matter of upgrading to a newer version and not a work around for now.

-Clayton Weaver

On Wed, Mar 23, 2016 at 11:42 AM, K. Frank <[hidden email]> wrote:
Hi Keith!

On Wed, Mar 23, 2016 at 9:50 AM, Keith Marshall
<[hidden email]> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 22/03/16 23:04, Clayton Weaver wrote:
>> I'm using MInGW 4.8.1 which gives me issues with class
>> constructors. For example,
>>
>> class Punct_stream{ public: Punct_stream(istream& is) : source{is},
>> sensitive{true} {} //... private: istream& source; // character
>> source bool sensitive; // is the stream case-sensitive? };
>>
>> The compiler fails with:
>>
>> error: invalid initialization of non-const reference of type
>> 'std::istream& {aka std::basic_istream<char>&}' from an rvalue of
>> type '<brace-enclosed initializer list>'
>
> FWIW, I see exactly the same when I compile with the native GCC-4.8.2,
> on my LinuxMint Debian system, so this isn't MinGW specific; (I also
> see the same with mingw32-g++ v4.8.2, on the same host).
>
>> My main question is does this compile correctly in 4.9.3
>
> Again on the LinuxMint host, the mingw32-g++ v4.9.3 cross-compiler,
> which I used to build the GCC-4.9.3 now offered by MinGW.org, compiles
> it correctly with -std=gnu++11, but not with -std=c++11; the GCC-5.3.0
> cross-compiler, on which I am now working, compiles it correctly with
> either option.

I should have mentioned that with my 4.9.2 mingw-w64 test, I compiled
successfully with "-std=c++11" (as well as with -std=gnu++11, -std=c++14,
and -std=gnu++14).  (As expected, without the -std flag, the compile failed,
because initializer lists are new to c++11.)

It's a little odd that Keith's 4.9.3 needed "-std=gnu++11" to compile Clayton's
code, but my 4.9.2 worked with "-std=c++11".  But, no matter ...

> ...
> Regards,
> Keith.


Best.


K. Frank

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Loading...