Bug 68024 - Diagnose variadic functions defined without prototypes
Summary: Diagnose variadic functions defined without prototypes
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 6.0
Assignee: Marek Polacek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-19 23:43 UTC by Joseph S. Myers
Modified: 2015-10-21 17:31 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-10-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph S. Myers 2015-10-19 23:43:00 UTC
As a quality-of-implementation-issue, we should diagnose code such as:

void f (int, ...);
void f (a) int a; {}

which defines a variadic function without using "...".

The types are compatible as defined by ISO C (see C11 6.7.6.3#15), so no diagnostic is required.  However, this case is explicitly undefined behavior (C11 6.9.1#8: "If a function that accepts a variable number of arguments is defined without a parameter type list that ends with the ellipsis notation, the behavior is undefined."; likewise back to C90).  So it is valid to reject it (this is undefined behavior as a property of a program, not of a particular execution of a program), and certainly seems a good idea at least to give a diagnostic.

This showed up with such a (declaration, definition) pair in glibc only being diagnosed after converting the definition from K&R style to prototype-style.
Comment 1 Marek Polacek 2015-10-20 08:46:13 UTC
Confirmed.
Comment 2 Marek Polacek 2015-10-21 17:30:52 UTC
Author: mpolacek
Date: Wed Oct 21 17:30:20 2015
New Revision: 229131

URL: https://gcc.gnu.org/viewcvs?rev=229131&root=gcc&view=rev
Log:
	PR c/68024
	* c-decl.c (start_function): Warn about vararg functions without
	a prototype.

	* gcc.dg/pr68024.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr68024.c
Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Marek Polacek 2015-10-21 17:31:10 UTC
Fixed.