public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39985] New: Type qualifiers not actually ignored on function return type
@ 2009-04-30 23:45 anders at kaseorg dot com
2009-11-21 12:24 ` [Bug c/39985] " gcc at magfr dot user dot lysator dot liu dot se
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: anders at kaseorg dot com @ 2009-04-30 23:45 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1179 bytes --]
The warning printed with -Wignored-qualifiers (warning: type qualifiers
ignored on function return type) seems to be lying. The const on a functions
return type is not actually ignored, as can be demonstrated using typeof(). I
think that the warning should be right and the typeof() behavior is wrong, but
Im not actually sure.
int f(void);
const int g(void); /* warning: type qualifiers ignored on function return type
*/
typeof(f()) a;
a = 5;
typeof(g()) b;
b = 5; /* error: assignment of read-only variable b */
Another thing that seems similarly strange is that a statement expression can
return a const type, even though it is not an lvalue:
const int x = 5;
typeof( ({ x; }) ) y;
y = 5; /* error: assignment of read-only variable y */
--
Summary: Type qualifiers not actually ignored on function return
type
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: anders at kaseorg dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39985
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/39985] Type qualifiers not actually ignored on function return type
2009-04-30 23:45 [Bug c/39985] New: Type qualifiers not actually ignored on function return type anders at kaseorg dot com
@ 2009-11-21 12:24 ` gcc at magfr dot user dot lysator dot liu dot se
2009-11-22 20:24 ` jsm28 at gcc dot gnu dot org
2009-11-27 7:33 ` anders at kaseorg dot com
2 siblings, 0 replies; 6+ messages in thread
From: gcc at magfr dot user dot lysator dot liu dot se @ 2009-11-21 12:24 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 942 bytes --]
------- Comment #1 from gcc at magfr dot user dot lysator dot liu dot se 2009-11-21 12:24 -------
Created an attachment (id=19074)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19074&action=view)
Test case - g++ -Wignored-qualifiers test.C gives confusing results
In C++ it becomes even worse since the types are used more.
As it stands right now it becomes ridiculous:
$ g++ -Wignored-qualifiers test.C
test.C:12: warning: type qualifiers ignored on function return type
test.C:12: error: conflicting return type specified for virtual const int
D1::F()
test.C:5: error: overriding virtual int B1::F()
test.C:20: warning: type qualifiers ignored on function return type
test.C:27: error: conflicting return type specified for virtual int D2::F()
test.C:20: error: overriding virtual const int B2::F()
Are the type qualifiers ignored or are they not?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39985
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/39985] Type qualifiers not actually ignored on function return type
2009-04-30 23:45 [Bug c/39985] New: Type qualifiers not actually ignored on function return type anders at kaseorg dot com
2009-11-21 12:24 ` [Bug c/39985] " gcc at magfr dot user dot lysator dot liu dot se
@ 2009-11-22 20:24 ` jsm28 at gcc dot gnu dot org
2009-11-27 7:33 ` anders at kaseorg dot com
2 siblings, 0 replies; 6+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2009-11-22 20:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from jsm28 at gcc dot gnu dot org 2009-11-22 20:24 -------
If you wish to report a C++ bug, it needs to have component "c++" and be
a separate bug from any bug report for C front-end issues; comments
about possible C++ front-end issues in "c" bugs are irrelevant except insofar
as they illuminate questions of what the C front end should do.
For C, the qualifiers are ignored as far as standard terms are concerned.
Whether typeof applied to an rvalue in GNU C has a qualified types is
fundamentally confused at present; my inclination is that we should
eliminate the inconsistent attempts to give rvalues qualified types in
some cases, and say that if the operand of typeof is not an lvalue it
never has a qualified type.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39985
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/39985] Type qualifiers not actually ignored on function return type
2009-04-30 23:45 [Bug c/39985] New: Type qualifiers not actually ignored on function return type anders at kaseorg dot com
2009-11-21 12:24 ` [Bug c/39985] " gcc at magfr dot user dot lysator dot liu dot se
2009-11-22 20:24 ` jsm28 at gcc dot gnu dot org
@ 2009-11-27 7:33 ` anders at kaseorg dot com
2 siblings, 0 replies; 6+ messages in thread
From: anders at kaseorg dot com @ 2009-11-27 7:33 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1497 bytes --]
------- Comment #3 from anders at kaseorg dot com 2009-11-27 07:33 -------
> my inclination is that we should eliminate the inconsistent attempts to give
> rvalues qualified types in some cases, and say that if the operand of typeof
> is not an lvalue it never has a qualified type.
Should typeof ever return a qualified type? It is easy to add qualifiers to a
type if they are desired (const typeof(foo)), but seems difficult to remove
them.
For example, seemingly reasonable macros like
#define MAX(__x, __y) ({ \
typeof(__x) __ret = __x; \
if (__y > __ret) __ret = __y; \
__ret; \
})
currently fail when given a qualified argument:
const int c = 42;
MAX(c, 17); /* error: assignment of read-only variable __ret */
This bug report was motivated by my attempts to fix a macro like this, by
replacing typeof(__x) with something that strips qualifiers. These all fail to
strip qualifiers:
typeof( ({ __x; }) )
typeof( ((typeof(__x)(*)(void)) 0)() )
typeof( (typeof(__x)) (__x) )
This seems to work, but only for numeric and pointer types:
typeof( (typeof(__x)) 0 )
This succeeds at stripping qualifiers for numeric types, but for some reason it
promotes char and short to int, and it fails to strip qualifiers for
non-numeric types:
typeof( 1 ? (__x) : (__x) )
Much confusion would be avoided if typeof(__x) just stripped qualifiers to
begin with.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39985
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <bug-39985-4@http.gcc.gnu.org/bugzilla/>]
end of thread, other threads:[~2023-05-16 18:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-30 23:45 [Bug c/39985] New: Type qualifiers not actually ignored on function return type anders at kaseorg dot com
2009-11-21 12:24 ` [Bug c/39985] " gcc at magfr dot user dot lysator dot liu dot se
2009-11-22 20:24 ` jsm28 at gcc dot gnu dot org
2009-11-27 7:33 ` anders at kaseorg dot com
[not found] <bug-39985-4@http.gcc.gnu.org/bugzilla/>
2021-06-12 21:36 ` muecker at gwdg dot de
2023-05-16 18:55 ` mpolacek at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).