From: Gabriel Dos Reis Date: Wed, 23 Nov 2005 07:07:33 +0000 (+0000) Subject: re PR c/21668 (gratuitous warning about "extern const" with initializer) X-Git-Tag: releases/gcc-4.2.0~5794 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b8b47f42511415601638a9efde76b54c39729c32;p=thirdparty%2Fgcc.git re PR c/21668 (gratuitous warning about "extern const" with initializer) PR c/21668 * c-decl.c (grokdeclarator): Don't warn for 'extern const' when compiling at the intersection of C and C++. testsuite/ PR c/21668 * gcc.dg/Wc++-compat.c: New. * gcc.dg/Wno-c++-compat.c: New. From-SVN: r107401 --- diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 003b813fc7d5..a86cfdc01b64 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -4014,8 +4014,13 @@ grokdeclarator (const struct c_declarator *declarator, && !funcdef_flag) { /* 'extern' with initialization is invalid if not at file scope. */ - if (current_scope == file_scope) - warning (0, "%qs initialized and declared %", name); + if (current_scope == file_scope) + { + /* It is fine to have 'extern const' when compiling at C + and C++ intersection. */ + if (!(warn_cxx_compat && constp)) + warning (0, "%qs initialized and declared %", name); + } else error ("%qs has both % and initializer", name); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bfc1d95c446b..f33e8337f9fe 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2005-11-23 Gabriel Dos Reis + + PR c/21668 + * gcc.dg/Wc++-compat.c: New. + * gcc.dg/Wno-c++-compat.c: New. + 2005-11-23 Alan Modra * gcc.target/powerpc/altivec-consts.c (vspltisb): Use int val. diff --git a/gcc/testsuite/gcc.dg/Wc++-compat.c b/gcc/testsuite/gcc.dg/Wc++-compat.c new file mode 100644 index 000000000000..aa435be9f3e1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wc++-compat.c @@ -0,0 +1,9 @@ +/* Copyright (C) 2005 Free Software Foundation. + + by Gabriel Dos Reis */ + +/* { dg-do compile } */ +/* { dg-options "-Wc++-compat" } */ + +extern const int foo = 42; + diff --git a/gcc/testsuite/gcc.dg/Wno-c++-compat.c b/gcc/testsuite/gcc.dg/Wno-c++-compat.c new file mode 100644 index 000000000000..b1f3cf26f579 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wno-c++-compat.c @@ -0,0 +1,9 @@ +/* Copyright (C) 2005 Free Software Foundation. + + by Gabriel Dos Reis */ + +/* { dg-do compile } */ +/* { dg-options "-Wno-c++-compat" } */ + +extern const int foo = 42; /* { dg-error "initialized and declared" } */ +