This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH][RFC] Warning for C++ malformed typedef [PR c++/23689]
- From: simonb at google dot com (Simon Baldwin)
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 1 Feb 2007 15:21:51 -0800 (PST)
- Subject: [PATCH][RFC] Warning for C++ malformed typedef [PR c++/23689]
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 ----
+ // PR c++/23689
+ // Test that malformed typedef's produce a compiler warning.
+
+ typedef char valid_0;
+ typedef int valid_1;
+ typedef long valid_2;
+ typedef float valid_3;
+ typedef double valid_4;
+ typedef unsigned valid_5;
+ typedef int *valid_6;
+ typedef struct valid_7 {} valid_8;
+ typedef struct {} valid_9;
+ typedef int temp_0; typedef temp_0 valid_10;
+ struct temp_1 {}; typedef temp_1 valid_11;
+ union temp_2 {}; typedef temp_2 valid_12;
+ typedef void (*valid_13) (int);
+
+ typedef struct invalid_0 {}; // { dg-warning "'typedef' was ignored" }
+ typedef class invalid_1 {}; // { dg-warning "'typedef' was ignored" }
+ typedef enum invalid_2 { INVALID_2 }; // { dg-warning "'typedef' was ignored" }
+ typedef enum { INVALID_3 }; // { dg-warning "'typedef' was ignored" }
+ typedef union invalid_4 {}; // { dg-warning "'typedef' was ignored" }