Web lists-archives.com

Re: [Mingw-users] MinGW Question on versions and Class Constructors




Hello Clayton!

On Tue, Mar 22, 2016 at 7:04 PM, Clayton Weaver <mingwuser@xxxxxxxxx> 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
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

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:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe