diff options
-rw-r--r-- | gcc/c-decl.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wc++-compat.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wno-c++-compat.c | 9 |
4 files changed, 31 insertions, 2 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 003b813..a86cfdc 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 %<extern%>", 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 %<extern%>", name); + } else error ("%qs has both %<extern%> and initializer", name); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bfc1d95..f33e833 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2005-11-23 Gabriel Dos Reis <gdr@integrable-solutions.net> + + PR c/21668 + * gcc.dg/Wc++-compat.c: New. + * gcc.dg/Wno-c++-compat.c: New. + 2005-11-23 Alan Modra <amodra@bigpond.net.au> * 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 0000000..aa435be --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wc++-compat.c @@ -0,0 +1,9 @@ +/* Copyright (C) 2005 Free Software Foundation. + + by Gabriel Dos Reis <gdr@integrable-solutions.net> */ + +/* { 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 0000000..b1f3cf2 --- /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 <gdr@integrable-solutions.net> */ + +/* { dg-do compile } */ +/* { dg-options "-Wno-c++-compat" } */ + +extern const int foo = 42; /* { dg-error "initialized and declared" } */ + |