Simon Baldwin - [PATCH][RFC] Warning for C++ malformed typedef [PR c++/23689] (original) (raw)

This is the mail archive of the gcc-patches@gcc.gnu.orgmailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Attached is a proposed small patch to address PR c++/23689. It adds a warning to g++ for what are either malformed typedef's or ordinary declarations with a useless prepended "typedef" qualifier.

The warning is unconditional; that is, it is printed no matter what warning controls are selected by command line options. This matches the behavior of gcc under similar circumstances, although the text of the warning message in g++ differs from gcc's -- this warning tries to be a little more explicit.

There is a new test in the testsuite for this warning. Two of the existing tests also generate the warning: in typedef2, the warning is not noted by dejagnu because of an error at the same line; ctor8, however, requires a small change to allow the test to continue to pass.

2007-02-01 Simon Baldwin simonb@google.com

PR c++/23689
* decl.c (check_tag_decl): Added new warning for typedef ignored
when it precedes an otherwise valid non-typedef declaration.

2007-02-01 Simon Baldwin simonb@google.com

PR c++/23689
* warn/ignored_typedef.C: New.
* init/ctor8.C: Added dg-warning to consume ignored typedef warning.

diff -Nrpc3 gcc-4.3-20070126_orig/gcc/cp/decl.c gcc-4.3-20070126/gcc/cp/decl.c *** gcc-4.3-20070126_orig/gcc/cp/decl.c Tue Jan 23 14:33:51 2007 --- gcc-4.3-20070126/gcc/cp/decl.c Wed Jan 31 11:07:05 2007 *************** check_tag_decl (cp_decl_specifier_seq *d *** 3694,3699 **** --- 3694,3701 ---- || declspecs->specs[(int)ds_thread]) error ("qualifiers can only be specified for objects " "and functions"); + else if (saw_typedef) + warning (0, "'typedef' was ignored in this declaration"); }
return declared_type; diff -Nrpc3 gcc-4.3-20070126_orig/gcc/testsuite/g++.dg/init/ctor8.C gcc-4.3-20070126/gcc/testsuite/g++.dg/init/ctor8.C *** gcc-4.3-20070126_orig/gcc/testsuite/g++.dg/init/ctor8.C Tue Oct 17 15:35:29 2006 --- gcc-4.3-20070126/gcc/testsuite/g++.dg/init/ctor8.C Thu Feb 1 14:11:32 2007 *************** *** 2,11 ****
typedef struct S { // { dg-error "reference" } int &r; ! };
S f () { return S (); // { dg-error "synthesized" } }

- --- 2,9 ----

typedef struct S { // { dg-error "reference" } int &r; ! }; // { dg-warning "" }

S f () { return S (); // { dg-error "synthesized" } } diff -Nrpc3 gcc-4.3-20070126_orig/gcc/testsuite/g++.dg/warn/ignored_typedef.C gcc-4.3-20070126/gcc/testsuite/g++.dg/warn/ignored_typedef.C *** gcc-4.3-20070126_orig/gcc/testsuite/g++.dg/warn/ignored_typedef.C Wed Dec 31 16:00:00 1969 --- gcc-4.3-20070126/gcc/testsuite/g++.dg/warn/ignored_typedef.C Thu Feb 1 14:36:46 2007


*** 0 **** --- 1,22 ----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]