public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99317] New: Missed warning
@ 2021-03-01 14:25 pj at hugeone dot co.uk
2021-03-01 17:20 ` [Bug c/99317] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: pj at hugeone dot co.uk @ 2021-03-01 14:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99317
Bug ID: 99317
Summary: Missed warning
Product: gcc
Version: 10.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: pj at hugeone dot co.uk
Target Milestone: ---
The code:
int *foo(void *v, void *w, int x) {
float * f = v;
int * i = w;
return (x ? f : i);
}
int *foo1(void *v, void *w, int x) {
float * f = v;
int * i = w;
return (1 ? f : (void *)i);
}
int *bar(void *v, void *w, int x) {
float * f = v;
int * i = w;
return (x ? f : (void *)i);
}
Function foo correctly emits the warning:
source>: In function 'foo':
<source>:7:19: warning: pointer type mismatch in conditional expression
7 | return (x ? f : i);
| ^
Casting removes that warming even in the trivial foo1 example.
https://godbolt.org/z/ozsPPY
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/99317] Missed warning
2021-03-01 14:25 [Bug c/99317] New: Missed warning pj at hugeone dot co.uk
@ 2021-03-01 17:20 ` pinskia at gcc dot gnu.org
2021-03-02 2:01 ` pj at hugeone dot co.uk
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-03-01 17:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99317
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I dont think this is exactly a bug. The warning is a pedantic warning and with
void*, things are implicitly converted by standard c rules.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/99317] Missed warning
2021-03-01 14:25 [Bug c/99317] New: Missed warning pj at hugeone dot co.uk
2021-03-01 17:20 ` [Bug c/99317] " pinskia at gcc dot gnu.org
@ 2021-03-02 2:01 ` pj at hugeone dot co.uk
2021-03-02 2:28 ` pinskia at gcc dot gnu.org
2021-03-02 16:38 ` msebor at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pj at hugeone dot co.uk @ 2021-03-02 2:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99317
--- Comment #2 from Piotr <pj at hugeone dot co.uk> ---
@(In reply to Andrew Pinski from comment #1)
> I dont think this is exactly a bug. The warning is a pedantic warning and
> with void*, things are implicitly converted by standard c rules.
With not `void *` it is exactly the same. https://godbolt.org/z/zM8Eqs
No -pedantic option too.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/99317] Missed warning
2021-03-01 14:25 [Bug c/99317] New: Missed warning pj at hugeone dot co.uk
2021-03-01 17:20 ` [Bug c/99317] " pinskia at gcc dot gnu.org
2021-03-02 2:01 ` pj at hugeone dot co.uk
@ 2021-03-02 2:28 ` pinskia at gcc dot gnu.org
2021-03-02 16:38 ` msebor at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-03-02 2:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99317
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Right.
basically what I am saying is:
x ? void* : char*
implies an implict conversion of the second operand to void*.
Without the cast, there is no implict conversion in standard C, that is what
the warning is about.
With -pendatic-errors, the warning turns into an error.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/99317] Missed warning
2021-03-01 14:25 [Bug c/99317] New: Missed warning pj at hugeone dot co.uk
` (2 preceding siblings ...)
2021-03-02 2:28 ` pinskia at gcc dot gnu.org
@ 2021-03-02 16:38 ` msebor at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-03-02 16:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99317
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |msebor at gcc dot gnu.org
Resolution|--- |WONTFIX
Status|UNCONFIRMED |RESOLVED
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=44209
--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
To expand on Andrew's comment: The C rules specify the type of the result of
operator ?: when either of the second and third operands is a pointer to void,
but they do no specify the result type when the operands are pointers to
incompatible types (like int* and float*). The warning points out the latter.
The C++ rules, OTOH, are more restrictive and make the ?: expression valid only
when the types of the arguments can be implicitly converted to one another.
Since in C++ a pointer to void isn't implicitly convertible to a pointer to an
object type all the expressions in the test case are invalid.
In C mode, the -Wc++-compat option helps detect C/C++ incompatibilities and
detects this problem (below). So with that, since the problem is diagnosed
under the right option, I think this report can be resolved as WONTFIX. (That
the warning in comment #0 is issued unconditionally and not under the control
of a specific option, is a separate problem tracked in in bug 44209.)
$ gcc -S -Wall -Wc++-compat pr99317.c
pr99317.c: In function ‘foo’:
pr99317.c:3:17: warning: request for implicit conversion from ‘void *’ to
‘float *’ not permitted in C++ [-Wc++-compat]
3 | float * f = v;
| ^
pr99317.c:4:15: warning: request for implicit conversion from ‘void *’ to ‘int
*’ not permitted in C++ [-Wc++-compat]
4 | int * i = w;
| ^
pr99317.c:5:19: warning: pointer type mismatch in conditional expression
5 | return (x ? f : i);
| ^
pr99317.c:5:19: warning: request for implicit conversion from ‘void *’ to ‘int
*’ not permitted in C++ [-Wc++-compat]
5 | return (x ? f : i);
| ~~~~~~~^~~~
pr99317.c: In function ‘foo1’:
pr99317.c:10:17: warning: request for implicit conversion from ‘void *’ to
‘float *’ not permitted in C++ [-Wc++-compat]
10 | float * f = v;
| ^
pr99317.c:11:15: warning: request for implicit conversion from ‘void *’ to ‘int
*’ not permitted in C++ [-Wc++-compat]
11 | int * i = w;
| ^
pr99317.c:12:19: warning: request for implicit conversion from ‘void *’ to ‘int
*’ not permitted in C++ [-Wc++-compat]
12 | return (1 ? f : (void *)i);
| ~~~~~~~^~~~~~~~~~~~
pr99317.c: In function ‘bar’:
pr99317.c:16:17: warning: request for implicit conversion from ‘void *’ to
‘float *’ not permitted in C++ [-Wc++-compat]
16 | float * f = v;
| ^
pr99317.c:17:15: warning: request for implicit conversion from ‘void *’ to ‘int
*’ not permitted in C++ [-Wc++-compat]
17 | int * i = w;
| ^
pr99317.c:18:19: warning: request for implicit conversion from ‘void *’ to ‘int
*’ not permitted in C++ [-Wc++-compat]
18 | return (x ? f : (void *)i);
| ~~~~~~~^~~~~~~~~~~~
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-03-02 16:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01 14:25 [Bug c/99317] New: Missed warning pj at hugeone dot co.uk
2021-03-01 17:20 ` [Bug c/99317] " pinskia at gcc dot gnu.org
2021-03-02 2:01 ` pj at hugeone dot co.uk
2021-03-02 2:28 ` pinskia at gcc dot gnu.org
2021-03-02 16:38 ` msebor 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).