From: Anubhav on 26 Apr 2010 23:01 Hi, I would like to know what should be the behavior of the compiler for the code shown const int fn(){return 0;} Comeau/Gcc give warning whereas C++ standard does not appear to mention anything specific. However looking at the grammar, it appears to me that such a declaration is syntactically legal. Regards, Dabs. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Bo Persson on 27 Apr 2010 07:24 Anubhav wrote: > Hi, > > I would like to know what should be the behavior of the compiler for > the code shown > > const int fn(){return 0;} > > > Comeau/Gcc give warning whereas C++ standard does not appear to > mention anything specific. However looking at the grammar, it > appears to me that such a declaration is syntactically legal. > They warn you that the qualifier is meaningless, because it doesn't make any difference. It is perfectly legal though. Bo Persson -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Daniel Krügler on 27 Apr 2010 07:22 On 27 Apr., 16:01, Anubhav <rkld...(a)gmail.com> wrote: > Hi, > > I would like to know what should be the behavior of the compiler for > the code shown > > const int fn(){return 0;} > > Comeau/Gcc give warning whereas C++ standard does not appear to > mention anything specific. However looking at the grammar, it appears > to me that such a declaration is syntactically legal. This is syntactically legal, but useless, because rvalues of non-class types are never const-qualified, see [basic.lval]/9: "Class rvalues can have cv-qualified types; non-class rvalues always have cv-unqualified types.[..]" HTH & Greetings from Bremen, Daniel Kr�gler -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Francis Glassborow on 27 Apr 2010 16:01 Anubhav wrote: > Hi, > > I would like to know what should be the behavior of the compiler for > the code shown > > const int fn(){return 0;} > > > Comeau/Gcc give warning whereas C++ standard does not appear to > mention anything specific. However looking at the grammar, it appears > to me that such a declaration is syntactically legal. > You do not say what the warning is but I guess it was warning about the return by const int. I think they are trying to be helpful by drawing your attention to the fact that the const qualifier serves no purpose. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: friend function and storage specifier Next: [ANN] CodeSynthesis XSD 3.3.0 released |