Bug#617321: gcc: c99-gcc with -ansi option should be handled as a conflict
Package: gcc
Version: 4:4.4.5-1
Severity: minor
Tags: patch
The c99-gcc wrapper script detects conflicting -std=* options and flags them as
errors before invoking gcc. The same logic should extend to the -ansi option,
which is identical to -std=c89; otherwise, the -ansi option overrides -std=c99
and turns the compilation into ISO C90 instead of ISO C99.
Example session compiling the attached program with current c99-gcc:
$ c99 --version
gcc (Debian 4.4.5-8) 4.4.5
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ c99 -Wall -D_XOPEN_SOURCE=600 democ99.c -lm
$ c99 -std=c89 -Wall -D_XOPEN_SOURCE=600 democ99.c -lm
c99 called with non ANSI/ISO C option -std=c89
$ c99 -ansi -Wall -D_XOPEN_SOURCE=600 democ99.c -lm
democ99.c:24: error: expected identifier or ‘(’ before ‘/’ token
democ99.c:27: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘static’
democ99.c: In function ‘main’:
democ99.c:36: error: ‘zarray’ undeclared (first use in this function)
democ99.c:36: error: (Each undeclared identifier is reported only once
democ99.c:36: error: for each function it appears in.)
democ99.c:38: error: ‘for’ loop initial declarations are only allowed in C99 mode
democ99.c:38: note: use option -std=c99 or -std=gnu99 to compile your code
democ99.c:40: error: redefinition of ‘i’
democ99.c:38: note: previous definition of ‘i’ was here
democ99.c:40: error: ‘for’ loop initial declarations are only allowed in C99 mode
democ99.c:40: warning: implicit declaration of function ‘zprint’
The included patch against the c99 script gives the desired behavior:
$ c99 -ansi -Wall -D_XOPEN_SOURCE=600 democ99.c -lm
c99 called with non ANSI/ISO C option -ansi
-- System Information:
Debian Release: 6.0
APT prefers proposed-updates
APT policy: (500, 'proposed-updates'), (500, 'stable'), (101, 'unstable')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.32-5-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages gcc depends on:
ii cpp 4:4.4.5-1 The GNU C preprocessor (cpp)
ii gcc-4.4 4.4.5-8 The GNU C compiler
Versions of packages gcc recommends:
ii libc6-dev [libc-dev] 2.11.2-10 Embedded GNU C Library: Developmen
Versions of packages gcc suggests:
pn autoconf <none> (no description available)
pn automake1.9 <none> (no description available)
ii bison 1:2.4.1.dfsg-3 A parser generator that is compati
ii flex 2.5.35-10 A fast lexical analyzer generator.
ii gcc-doc 5:3 documentation for the GNU compiler
ii gcc-multilib 4:4.4.5-1 The GNU C compiler (multilib files
ii gdb 7.0.1-2+b1 The GNU Debugger
pn libtool <none> (no description available)
ii make 3.81-8 An utility for Directing compilati
ii manpages-dev 3.27-1 Manual pages about using GNU/Linux
-- no debconf information
/* democ99.c - Demonstration program to separate C89 from C99
*
* Copyright (C) 2011 Mike Miller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <complex.h>
#include <stdbool.h>
// File-scoped complex value array to be initialized at run-time.
static long double complex *zarray;
inline static void zprint(long double complex z, FILE *restrict stream)
{
fprintf(stream, "(%Lf,%Lf)\n", creall(z), cimagl(z));
}
int main(int argc, char *argv[])
{
bool ok = true;
zarray = malloc(16 * sizeof(long double complex));
for (int i = 0; i < 16; i++) zarray[i] = cexpl(I * M_PI * i / 8);
for (int i = 0; i < 16; i++) zprint(zarray[i], stdout);
free(zarray);
exit(ok ? EXIT_SUCCESS : EXIT_FAILURE);
}
Index: c99
===================================================================
--- c99 (revision 5085)
+++ c99 (working copy)
@@ -14,7 +14,7 @@
-std=c9[9x]|-std=iso9899:199[9x])
extra_flag=
;;
- -std=*)
+ -std=*|-ansi)
echo >&2 "`basename $0` called with non ANSI/ISO C option $i"
exit 1
;;
Reply to: