From 94eeabbe1999a998aa8fb64a86e794c77755d0df Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Fri, 11 Jul 2008 18:12:37 +0000 Subject: [PATCH] re PR c++/13101 (incorrect warning on initialized extern const function pointer) 2008-07-11 Dodji Seketeli PR c++/13101 * decl.c (grokdeclarator): Warn about initializing variables of storage class 'extern' only after the type of the declarator has been properly computed. From-SVN: r137723 --- gcc/cp/ChangeLog | 12 +++++++-- gcc/cp/decl.c | 26 +++++++++---------- gcc/testsuite/ChangeLog | 7 +++++ .../g++.old-deja/g++.jason/crash11.C | 2 +- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c48fe96cb2f..7b73ee1e8a1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2008-07-11 Dodji Seketeli + + PR c++/13101 + * decl.c (grokdeclarator): Warn about initializing variables + of storage class 'extern' only after the type of the declarator + has been properly computed. + 2008-07-11 Dodji Seketeli PR c++/31754 @@ -13,7 +20,8 @@ cp_parser_type_specifier, cp_parser_simple_type_specifier, cp_parser_omp_for_loop, cp_parser_pragma): use location in error messages. -2008-06-30 Dodji Seketeli + +2008-07-11 Dodji Seketeli PR c++/31754 * pt.c, semantic.c: @@ -148,7 +156,7 @@ * pt.c: (tsubst_copy_and_build): Adjust. (unify): Handle { }. * name-lookup.c (arg_assoc_type): Handle init_list_type_node. - + 2008-07-01 Daniel Jacobowitz * typeck.c (comp_ptr_ttypes_real): Use vector_targets_convertible_p. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index fc76ebefb43..83d2c4ea5a7 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -8005,19 +8005,6 @@ grokdeclarator (const cp_declarator *declarator, storage_class = sc_none; } } - else if (storage_class == sc_extern && initialized - && !funcdef_flag) - { - if (toplevel_bindings_p ()) - { - /* It's common practice (and completely valid) to have a const - be initialized and declared extern. */ - if (!(type_quals & TYPE_QUAL_CONST)) - warning (0, "%qs initialized and declared %", name); - } - else - error ("%qs has both % and initializer", name); - } else if (storage_class == sc_extern && funcdef_flag && ! toplevel_bindings_p ()) error ("nested function %qs declared %", name); @@ -9236,6 +9223,19 @@ grokdeclarator (const cp_declarator *declarator, } } + if (storage_class == sc_extern && initialized && !funcdef_flag) + { + if (toplevel_bindings_p ()) + { + /* It's common practice (and completely valid) to have a const + be initialized and declared extern. */ + if (!(type_quals & TYPE_QUAL_CONST)) + warning (0, "%qs initialized and declared %", name); + } + else + error ("%qs has both % and initializer", name); + } + /* Record `register' declaration for warnings on & and in case doing stupid register allocation. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9833a0f828e..cf57c77a0c2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2008-07-11 Dodji Seketeli + + PR c++/13101 + * g++.dg/parse/func-ptr-decl.C: New test. + * gcc/testsuite/g++.old-deja/g++.jason/crash11.C: Update this to + catch a warning that is generated by virtue of fixing this bug. + 2008-07-11 Dodji Seketeli * g++.dg/other/semicolon.C: Tighten this test, making it column aware. diff --git a/gcc/testsuite/g++.old-deja/g++.jason/crash11.C b/gcc/testsuite/g++.old-deja/g++.jason/crash11.C index e88eb78d53e..5cc8e5f3d6b 100644 --- a/gcc/testsuite/g++.old-deja/g++.jason/crash11.C +++ b/gcc/testsuite/g++.old-deja/g++.jason/crash11.C @@ -6,4 +6,4 @@ struct A { }; const char foo[] = "bar"; const A a = { foo }; -extern const A* ap = &a; +extern const A* ap = &a; //{ dg-warning "warning: 'ap' initialized and declared 'extern'" }