public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/31489] error says struct when it should say class
[not found] <bug-31489-4@http.gcc.gnu.org/bugzilla/>
@ 2011-09-27 10:15 ` paolo.carlini at oracle dot com
2011-09-27 21:57 ` paolo at gcc dot gnu.org
2011-09-27 22:06 ` paolo.carlini at oracle dot com
2 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-27 10:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31489
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
AssignedTo|unassigned at gcc dot |paolo.carlini at oracle dot
|gnu.org |com
--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-27 10:06:09 UTC ---
I just discovered that actually we *do* have machinery to do this, in general
terms (see CLASSTYPE_DECLARED_CLASS, used by eg, class_key_or_enum_as_string).
But cp_parser_elaborated_type_specifier doesn't use it, ie doesn't set
CLASSTYPE_DECLARED_CLASS (at variance with cp_parser_class_head). Thus
something like the following patchlet should do the trick. That said, Andrew
has a point of course, for its second example we would say struct or class,
whichever comes last in the redeclaration. All in all, seems an improvement to
me, if the below works pretty well I'm going to submit it.
/////////////
Index: parser.c
===================================================================
--- parser.c (revision 179242)
+++ parser.c (working copy)
@@ -13423,8 +13423,15 @@ cp_parser_elaborated_type_specifier (cp_parser* pa
}
if (tag_type != enum_type)
- cp_parser_check_class_key (tag_type, type);
+ {
+ /* Indicate whether this class was declared as a `class' or as a
+ `struct'. */
+ if (TREE_CODE (type) == RECORD_TYPE)
+ CLASSTYPE_DECLARED_CLASS (type) = (tag_type == class_type);
+ cp_parser_check_class_key (tag_type, type);
+ }
+
/* A "<" cannot follow an elaborated type specifier. If that
happens, the user was probably trying to form a template-id. */
cp_parser_check_for_invalid_template_id (parser, type, token->location);
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/31489] error says struct when it should say class
[not found] <bug-31489-4@http.gcc.gnu.org/bugzilla/>
2011-09-27 10:15 ` [Bug c++/31489] error says struct when it should say class paolo.carlini at oracle dot com
@ 2011-09-27 21:57 ` paolo at gcc dot gnu.org
2011-09-27 22:06 ` paolo.carlini at oracle dot com
2 siblings, 0 replies; 5+ messages in thread
From: paolo at gcc dot gnu.org @ 2011-09-27 21:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31489
--- Comment #4 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2011-09-27 21:52:23 UTC ---
Author: paolo
Date: Tue Sep 27 21:52:19 2011
New Revision: 179293
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179293
Log:
/cp
2011-09-27 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/31489
* parser.c (cp_parser_elaborated_type_specifier): For RECORD_TYPE,
set CLASSTYPE_DECLARED_CLASS.
/testsuite
2011-09-27 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/31489
* g++.dg/parse/error40.C: New.
* g++.dg/warn/incomplete1.C: Adjust.
Added:
trunk/gcc/testsuite/g++.dg/parse/error40.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/parser.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/g++.dg/warn/incomplete1.C
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/31489] error says struct when it should say class
[not found] <bug-31489-4@http.gcc.gnu.org/bugzilla/>
2011-09-27 10:15 ` [Bug c++/31489] error says struct when it should say class paolo.carlini at oracle dot com
2011-09-27 21:57 ` paolo at gcc dot gnu.org
@ 2011-09-27 22:06 ` paolo.carlini at oracle dot com
2 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-27 22:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31489
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
CC|gcc-bugs at gcc dot gnu.org |
Resolution| |FIXED
Target Milestone|--- |4.7.0
--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-27 21:54:26 UTC ---
Fixed for 4.7.0.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/31489] New: error says struct when it should say class
@ 2007-04-05 22:50 jg at jguk dot org
2007-04-05 23:09 ` [Bug c++/31489] " pinskia at gcc dot gnu dot org
2007-04-07 15:23 ` bangerth at dealii dot org
0 siblings, 2 replies; 5+ messages in thread
From: jg at jguk dot org @ 2007-04-05 22:50 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]
When a forward declared class is not found the error message describes it
incorrectly as a struct. See below for an example.
I'd like to submit a patch to correctly display class. Let me know if such a
patch would be considered.
$ g++ -Wall -ggdb -O0 -o t test6.cpp
test6.cpp: In function int main():
test6.cpp:8: error: invalid use of undefined type struct foobar
test6.cpp:4: error: forward declaration of struct foobar
File contains:
=====================================
// g++ -Wall -ggdb -O0 -o t test6.cpp
class foobar;
int main()
{
foobar * o = new foobar;
}
====================================
--
Summary: error says struct when it should say class
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jg at jguk dot org
GCC build triplet: i686-gnu-linux
GCC host triplet: i686-gnu-linux
GCC target triplet: i686-gnu-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31489
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-09-27 21:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-31489-4@http.gcc.gnu.org/bugzilla/>
2011-09-27 10:15 ` [Bug c++/31489] error says struct when it should say class paolo.carlini at oracle dot com
2011-09-27 21:57 ` paolo at gcc dot gnu.org
2011-09-27 22:06 ` paolo.carlini at oracle dot com
2007-04-05 22:50 [Bug c++/31489] New: " jg at jguk dot org
2007-04-05 23:09 ` [Bug c++/31489] " pinskia at gcc dot gnu dot org
2007-04-07 15:23 ` bangerth at dealii dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).