Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: I think references should have been const by default Date: Sat, 23 Oct 2021 15:07:16 -0700 Organization: None to speak of Lines: 42 Message-ID: <87mtmz2y5n.fsf@nosuchdomain.example.com> References: <871r4c3p7f.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="dc53845975de92cdf23a501c594f45fc"; logging-data="24867"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RxfY25muOftYQOFwzUY8v" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:O6btJBpsyKE7ACKLscF8PsxK1bQ= sha1:U3PJ4Foz1PehbN/7wVECfdTHiUY= Xref: csiph.com comp.lang.c++:82055 Bart writes: > On 23/10/2021 13:23, Ben Bacarisse wrote: >> David Brown writes: >> >>> I think it is odd, however, that you can have qualified types in the >>> generic association list, since they can't ever match anything >>> (AFAICS). >> I was curious so I tried this: >> #include >> struct S { const int i; } s; >> struct S f(void) { return s; } >> int main(void) >> { >> const char *t = >> _Generic(f().i, >> int: "int", >> const int: "const int"); >> puts(t); >> } >> f().i is not a lvalue and has a const-qualified type. gcc prints >> "int", >> but clang prints "const int". I think clang is right here. (So much >> for "they all copy gcc"!) > > You need to file a bug report to Clang's developers so that they can > fix that oversight! > > But, why do think Clang is wrong? The type has a top-level const qualifier. > > I don't get why this is only removed for an lvalue (where you'd think > that a const attribute is more critical). The removal of type qualifiers is part of lvalue conversion. No lvalue, no lvalue conversion. I can see that it would make sense for the expression `f().i` to have type int rather than const int, but the standard doesn't say so. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */