Bug 44586 - gcc does not warn about casting non-variadic types to variadic types
Summary: gcc does not warn about casting non-variadic types to variadic types
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2010-06-18 19:48 UTC by Khem Raj
Modified: 2021-09-13 00:08 UTC (History)
3 users (show)

See Also:
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
Build: x86_64-linux-gnu
Known to work:
Known to fail: 4.5.0
Last reconfirmed: 2010-06-20 22:25:41


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Khem Raj 2010-06-18 19:48:12 UTC
the folowing testcase does a casting which results in undefined behaviour but gcc does not warn about it.

ypedef int (*bar_t)(int x, int y, ...);

int foo(int x, int y) {
        return x+y;
}

void f(int x, int y) {
       bar_t bar;

       /* Cast foo to variadic type... undefined behaviour */
       bar = (bar_t) foo;
       (*bar)(x,y);
}
Comment 1 Manuel López-Ibáñez 2010-06-20 21:41:34 UTC
Joseph, what do you think? Any suggestions where this may be catched? wording? option?

I have wished for some time to create a -Wundefined option anyway.
Comment 2 joseph@codesourcery.com 2010-06-20 22:17:35 UTC
Subject: Re:  gcc does not warn about casting non-variadic types
 to variadic types

It's not the conversion that's undefined, but the call.  You could have an 
option to warn for all function pointer conversions to incompatible 
function pointer types (but they have reasonable uses as there isn't a 
generic function pointer type like void *) - or you could have the 
optimizers detect calls to incompatibly cast types and warn then like the 
front ends does when the cast appears directly in the call.

Comment 3 Manuel López-Ibáñez 2010-06-20 22:25:41 UTC
OK. So I would say confirmed, but still I am not sure how I would implement this. So patches welcome.