* [C++ Patches] PR c++/66781 and c++/67847
@ 2015-10-21 14:40 Paolo Carlini
2015-10-21 19:24 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Paolo Carlini @ 2015-10-21 14:40 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 280 bytes --]
Hi,
I have two fixes for ICEs on invalid code. I'm not completely sure about
the wording of the error message for c++/67847, fwiw, clang issues
something rather similar. The other one should be more straightforward.
Tested x86_64-linux.
Thanks,
Paolo.
/////////////////////
[-- Attachment #2: CL_66781 --]
[-- Type: text/plain, Size: 286 bytes --]
/cp
2015-10-21 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/66781
* parser.c (cp_parser_enum_specifier): Upon error_at set
nested_name_specifier to error_mark_node.
/testsuite
2015-10-21 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/66781
* g++.dg/parse/enum13.C: New.
[-- Attachment #3: patch_66781 --]
[-- Type: text/plain, Size: 939 bytes --]
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 229082)
+++ cp/parser.c (working copy)
@@ -16655,8 +16655,11 @@ cp_parser_enum_specifier (cp_parser* parser)
else if (nested_name_specifier == error_mark_node)
/* We already issued an error. */;
else
- error_at (type_start_token->location,
- "%qD is not an enumerator-name", identifier);
+ {
+ error_at (type_start_token->location,
+ "%qD is not an enumerator-name", identifier);
+ nested_name_specifier = error_mark_node;
+ }
}
else
{
Index: testsuite/g++.dg/parse/enum13.C
===================================================================
--- testsuite/g++.dg/parse/enum13.C (revision 0)
+++ testsuite/g++.dg/parse/enum13.C (working copy)
@@ -0,0 +1,8 @@
+// PR c++/66781
+
+class foo
+{
+public:
+ enum foo::bar{}; // { dg-error "not an enumerator-name" }
+ foo::bar baz;
+};
[-- Attachment #4: CL_67847 --]
[-- Type: text/plain, Size: 278 bytes --]
/cp
2015-10-21 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/67847
* parser.c (cp_parser_enum_specifier): Reject TEMPLATE_TYPE_PARM as
nested_name_specifier.
/testsuite
2015-10-21 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/67847
* g++.dg/parse/enum12.C: New.
[-- Attachment #5: patch_67847 --]
[-- Type: text/plain, Size: 1119 bytes --]
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 229082)
+++ cp/parser.c (working copy)
@@ -16783,6 +16786,13 @@ cp_parser_enum_specifier (cp_parser* parser)
nested_name_specifier);
type = error_mark_node;
}
+ else if (TREE_CODE (nested_name_specifier) == TEMPLATE_TYPE_PARM)
+ {
+ error_at (type_start_token->location, "nested name specifier "
+ "for enum declaration cannot depend on a template "
+ "parameter, i.e., %qT", nested_name_specifier);
+ type = error_mark_node;
+ }
/* If that scope does not contain the scope in which the
class was originally declared, the program is invalid. */
else if (prev_scope && !is_ancestor (prev_scope,
Index: testsuite/g++.dg/parse/enum12.C
===================================================================
--- testsuite/g++.dg/parse/enum12.C (revision 0)
+++ testsuite/g++.dg/parse/enum12.C (working copy)
@@ -0,0 +1,7 @@
+// PR c++/67847
+
+template < typename T >
+class D
+{
+ enum T::Color {R, G, B} c; // { dg-error "template parameter" }
+};
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C++ Patches] PR c++/66781 and c++/67847
2015-10-21 14:40 [C++ Patches] PR c++/66781 and c++/67847 Paolo Carlini
@ 2015-10-21 19:24 ` Jason Merrill
2015-10-21 20:41 ` Paolo Carlini
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2015-10-21 19:24 UTC (permalink / raw)
To: Paolo Carlini, gcc-patches
On 10/21/2015 04:37 AM, Paolo Carlini wrote:
> + "%qD is not an enumerator-name", identifier);
This should be enum-name or "does not name an enumeration". We should
also print the nested-name-specifier.
> + error_at (type_start_token->location, "nested name specifier "
> + "for enum declaration cannot depend on a template "
> + "parameter, i.e., %qT", nested_name_specifier);
It can in, e.g.,
template <class T>
enum A<T>::E { ... };
We could hit this same ICE for anything that is not a class or
namespace, i.e. any of WILDCARD_TYPE_P. That's the problem here: the
nested-name-specifier on a definition needs to name a class or namespace.
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C++ Patches] PR c++/66781 and c++/67847
2015-10-21 19:24 ` Jason Merrill
@ 2015-10-21 20:41 ` Paolo Carlini
2015-10-21 21:04 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Paolo Carlini @ 2015-10-21 20:41 UTC (permalink / raw)
To: Jason Merrill, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1071 bytes --]
Hi,
and thanks a lot for your quick and helpful reply.
On 10/21/2015 09:19 PM, Jason Merrill wrote:
> On 10/21/2015 04:37 AM, Paolo Carlini wrote:
>> + "%qD is not an enumerator-name", identifier);
>
> This should be enum-name or "does not name an enumeration". We should
> also print the nested-name-specifier.
Agreed
>> + error_at (type_start_token->location, "nested name
>> specifier "
>> + "for enum declaration cannot depend on a template "
>> + "parameter, i.e., %qT", nested_name_specifier);
>
> It can in, e.g.,
>
> template <class T>
> enum A<T>::E { ... };
>
> We could hit this same ICE for anything that is not a class or
> namespace, i.e. any of WILDCARD_TYPE_P. That's the problem here: the
> nested-name-specifier on a definition needs to name a class or namespace.
In other terms exactly match (in reverse of course) the gcc_assert at
the beginning of is_ancestor which triggers in such cases, right?
I'm finishing testing the below, everything is fine so far.
Thanks,
Paolo.
/////////////////////
[-- Attachment #2: patch_66781_2 --]
[-- Type: text/plain, Size: 985 bytes --]
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 229123)
+++ cp/parser.c (working copy)
@@ -16655,8 +16655,12 @@ cp_parser_enum_specifier (cp_parser* parser)
else if (nested_name_specifier == error_mark_node)
/* We already issued an error. */;
else
- error_at (type_start_token->location,
- "%qD is not an enumerator-name", identifier);
+ {
+ error_at (type_start_token->location,
+ "%qD does not name an enumeration in %qT",
+ identifier, nested_name_specifier);
+ nested_name_specifier = error_mark_node;
+ }
}
else
{
Index: testsuite/g++.dg/parse/enum13.C
===================================================================
--- testsuite/g++.dg/parse/enum13.C (revision 0)
+++ testsuite/g++.dg/parse/enum13.C (working copy)
@@ -0,0 +1,8 @@
+// PR c++/66781
+
+class foo
+{
+public:
+ enum foo::bar{}; // { dg-error "does not name an enumeration" }
+ foo::bar baz;
+};
[-- Attachment #3: patch_67847_2 --]
[-- Type: text/plain, Size: 1154 bytes --]
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 229123)
+++ cp/parser.c (working copy)
@@ -16783,6 +16787,14 @@ cp_parser_enum_specifier (cp_parser* parser)
nested_name_specifier);
type = error_mark_node;
}
+ else if (TREE_CODE (nested_name_specifier) != NAMESPACE_DECL
+ && !CLASS_TYPE_P (nested_name_specifier))
+ {
+ error_at (type_start_token->location, "nested name specifier "
+ "%qT for enum declaration does not name a class "
+ "or namespace", nested_name_specifier);
+ type = error_mark_node;
+ }
/* If that scope does not contain the scope in which the
class was originally declared, the program is invalid. */
else if (prev_scope && !is_ancestor (prev_scope,
Index: testsuite/g++.dg/parse/enum12.C
===================================================================
--- testsuite/g++.dg/parse/enum12.C (revision 0)
+++ testsuite/g++.dg/parse/enum12.C (working copy)
@@ -0,0 +1,7 @@
+// PR c++/67847
+
+template < typename T >
+class D
+{
+ enum T::Color {R, G, B} c; // { dg-error "nested name specifier" }
+};
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C++ Patches] PR c++/66781 and c++/67847
2015-10-21 20:41 ` Paolo Carlini
@ 2015-10-21 21:04 ` Jason Merrill
0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2015-10-21 21:04 UTC (permalink / raw)
To: Paolo Carlini, gcc-patches
OK.
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-10-21 20:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-21 14:40 [C++ Patches] PR c++/66781 and c++/67847 Paolo Carlini
2015-10-21 19:24 ` Jason Merrill
2015-10-21 20:41 ` Paolo Carlini
2015-10-21 21:04 ` Jason Merrill
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).