From: Ian Lance Taylor Date: Fri, 19 Jun 2009 15:25:16 +0000 (+0000) Subject: c-decl.c (grokdeclarator): If -Wc++-compat, warn about a global variable with an... X-Git-Tag: releases/gcc-4.5.0~5106 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88eeff6f5a1347dc09de33c26a68648c4dea7f80;p=thirdparty%2Fgcc.git c-decl.c (grokdeclarator): If -Wc++-compat, warn about a global variable with an anonymous type. ./: * c-decl.c (grokdeclarator): If -Wc++-compat, warn about a global variable with an anonymous type. fortran/: * cpp.c (struct gfc_cpp_option_data): Give this struct, used for the global variable gfc_cpp_option, a name. testsuite/: * gcc.dg/Wcxx-compat-16.c: New testcase. From-SVN: r148708 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c327984c8fbb..37a3629ff6de 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2009-06-19 Ian Lance Taylor + + * c-decl.c (grokdeclarator): If -Wc++-compat, warn about a global + variable with an anonymous type. + 2009-06-19 Uros Bizjak * see.c: Remove for real. diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 4e48bac7f548..57cbd2835889 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -5875,6 +5875,19 @@ grokdeclarator (const struct c_declarator *declarator, name of a variable. Thus, if it's known before this, die horribly. */ gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl)); + if (warn_cxx_compat + && TREE_CODE (decl) == VAR_DECL + && TREE_PUBLIC (decl) + && TREE_STATIC (decl) + && (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE + || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE + || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE) + && TYPE_NAME (TREE_TYPE (decl)) == NULL_TREE) + warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat, + ("non-local variable %qD with anonymous type is " + "questionable in C++"), + decl); + return decl; } } diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d3d140bd50bb..136a0e564cc2 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2009-06-19 Ian Lance Taylor + + * cpp.c (struct gfc_cpp_option_data): Give this struct, used for + the global variable gfc_cpp_option, a name. + 2009-06-19 Janus Weil PR fortran/40450 diff --git a/gcc/fortran/cpp.c b/gcc/fortran/cpp.c index 9187bed7efea..ec8bb59504c9 100644 --- a/gcc/fortran/cpp.c +++ b/gcc/fortran/cpp.c @@ -66,7 +66,7 @@ typedef struct gfc_cpp_macro_queue } gfc_cpp_macro_queue; static gfc_cpp_macro_queue *cpp_define_queue, *cpp_undefine_queue; -struct +struct gfc_cpp_option_data { /* Argument of -cpp, implied by SPEC; if NULL, preprocessing disabled. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 918d19819f5a..b68dc7e059bf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2009-06-19 Ian Lance Taylor + + * gcc.dg/Wcxx-compat-16.c: New testcase. + 2009-06-19 Uros Bizjak * gcc.dg/builtins-34.c: Add significand cases. diff --git a/gcc/testsuite/gcc.dg/Wcxx-compat-16.c b/gcc/testsuite/gcc.dg/Wcxx-compat-16.c new file mode 100644 index 000000000000..51b503bf607e --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wcxx-compat-16.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-Wc++-compat" } */ + +struct { int f1; } g1; /* { dg-warning "C\[+\]\[+\]" } */ +static struct { int f2; } g2; +struct s { int f3; } g3; +union { int f4; } g4; /* { dg-warning "C\[+\]\[+\]" } */ +static union { int f5; } g5; +union u { int f6; } g6; +enum { A } g7; /* { dg-warning "C\[+\]\[+\]" } */ +static enum { B } g8; +enum E { C } g9;