* [C++ Patch] PR 50864 (parser bits)
@ 2011-11-08 0:49 Paolo Carlini
2011-11-08 1:10 ` Jason Merrill
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Carlini @ 2011-11-08 0:49 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 306 bytes --]
Hi,
this is what I figured out for the parser: I'm dealing also with '.', as
you recommended, and I tidied a bit the code wrt my first draft try,
consistently with the way we are handling another error condition a few
lines earlier.
Re-tested x86_64-linux.
Thanks,
Paolo.
//////////////////////////
[-- Attachment #2: CL_50864_new --]
[-- Type: text/plain, Size: 322 bytes --]
/cp
2011-11-08 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50864
* parser.c (cp_parser_postfix_dot_deref_expression): Reject invalid
uses of '->' and '.' as postfix-expression in namespace scope.
/testsuite
2011-11-08 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50864
* g++.dg/parse/template26.C: New.
[-- Attachment #3: patch_50864_new --]
[-- Type: text/plain, Size: 1718 bytes --]
Index: testsuite/g++.dg/parse/template26.C
===================================================================
--- testsuite/g++.dg/parse/template26.C (revision 0)
+++ testsuite/g++.dg/parse/template26.C (revision 0)
@@ -0,0 +1,18 @@
+// PR c++/50864
+
+namespace impl
+{
+ template <class T> T create();
+}
+
+template <class T, class U, __SIZE_TYPE__
+ = sizeof(impl::create<T>()->*impl::create<U>())>
+struct foo1;
+
+template <class T, class U, __SIZE_TYPE__
+ = sizeof(impl::create<T>()->impl::create<U>())> // { dg-error "not a class member" }
+struct foo2;
+
+template <class T, class U, __SIZE_TYPE__
+ = sizeof(impl::create<T>().impl::create<U>())> // { dg-error "not a class member" }
+struct foo3;
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 181133)
+++ cp/parser.c (working copy)
@@ -5969,10 +5969,19 @@ cp_parser_postfix_dot_deref_expression (cp_parser
{
if (name != error_mark_node && !BASELINK_P (name) && parser->scope)
{
- name = build_qualified_name (/*type=*/NULL_TREE,
- parser->scope,
- name,
- template_p);
+ if (TREE_CODE (parser->scope) == NAMESPACE_DECL
+ && (TREE_CODE (postfix_expression) == ARROW_EXPR
+ || TREE_CODE (postfix_expression) == CALL_EXPR))
+ {
+ error_at (token->location, "%<%D::%D%> is not a class member",
+ parser->scope, name);
+ postfix_expression = error_mark_node;
+ }
+ else
+ name = build_qualified_name (/*type=*/NULL_TREE,
+ parser->scope,
+ name,
+ template_p);
parser->scope = NULL_TREE;
parser->qualifying_scope = NULL_TREE;
parser->object_scope = NULL_TREE;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [C++ Patch] PR 50864 (parser bits)
2011-11-08 0:49 [C++ Patch] PR 50864 (parser bits) Paolo Carlini
@ 2011-11-08 1:10 ` Jason Merrill
2011-11-08 1:22 ` Paolo Carlini
0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2011-11-08 1:10 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
On 11/07/2011 07:31 PM, Paolo Carlini wrote:
> + if (TREE_CODE (parser->scope) == NAMESPACE_DECL
> + && (TREE_CODE (postfix_expression) == ARROW_EXPR
> + || TREE_CODE (postfix_expression) == CALL_EXPR))
Do we need to check the code of postfix_expression at all?
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [C++ Patch] PR 50864 (parser bits)
2011-11-08 1:10 ` Jason Merrill
@ 2011-11-08 1:22 ` Paolo Carlini
2011-11-08 1:42 ` Paolo Carlini
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Carlini @ 2011-11-08 1:22 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
On 11/08/2011 01:49 AM, Jason Merrill wrote:
> On 11/07/2011 07:31 PM, Paolo Carlini wrote:
>> + if (TREE_CODE (parser->scope) == NAMESPACE_DECL
>> + && (TREE_CODE (postfix_expression) == ARROW_EXPR
>> + || TREE_CODE (postfix_expression) == CALL_EXPR))
>
> Do we need to check the code of postfix_expression at all?
Ah! You implied that, in your previous message, but seemed too nice to
me ;) Let me regtest without...
Paolo.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [C++ Patch] PR 50864 (parser bits)
2011-11-08 1:22 ` Paolo Carlini
@ 2011-11-08 1:42 ` Paolo Carlini
2011-11-08 5:05 ` Jason Merrill
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Carlini @ 2011-11-08 1:42 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 355 bytes --]
On 11/08/2011 01:51 AM, Paolo Carlini wrote:
>> Do we need to check the code of postfix_expression at all?
> Ah! You implied that, in your previous message, but seemed too nice to
> me ;) Let me regtest without...
And this indeed passes testing. A rather old testcase got a slightly
more accurate error message.
Thanks,
Paolo.
//////////////////////
[-- Attachment #2: CL_50864_new_2 --]
[-- Type: text/plain, Size: 376 bytes --]
/cp
2011-11-08 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50864
* parser.c (cp_parser_postfix_dot_deref_expression): Reject invalid
uses of '->' and '.' as postfix-expression in namespace scope.
/testsuite
2011-11-08 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50864
* g++.dg/parse/template26.C: New.
* g++.dg/template/crash45.C: Adjust dg-error string.
[-- Attachment #3: patch_50864_new_2 --]
[-- Type: text/plain, Size: 1986 bytes --]
Index: testsuite/g++.dg/parse/template26.C
===================================================================
--- testsuite/g++.dg/parse/template26.C (revision 0)
+++ testsuite/g++.dg/parse/template26.C (revision 0)
@@ -0,0 +1,18 @@
+// PR c++/50864
+
+namespace impl
+{
+ template <class T> T create();
+}
+
+template <class T, class U, __SIZE_TYPE__
+ = sizeof(impl::create<T>()->*impl::create<U>())>
+struct foo1;
+
+template <class T, class U, __SIZE_TYPE__
+ = sizeof(impl::create<T>()->impl::create<U>())> // { dg-error "not a class member" }
+struct foo2;
+
+template <class T, class U, __SIZE_TYPE__
+ = sizeof(impl::create<T>().impl::create<U>())> // { dg-error "not a class member" }
+struct foo3;
Index: testsuite/g++.dg/template/crash45.C
===================================================================
--- testsuite/g++.dg/template/crash45.C (revision 181138)
+++ testsuite/g++.dg/template/crash45.C (working copy)
@@ -9,5 +9,5 @@ namespace N
void bar(A *p)
{
- p->N::foo<0>; // { dg-error "not a member" }
+ p->N::foo<0>; // { dg-error "not a class member" }
}
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 181138)
+++ cp/parser.c (working copy)
@@ -5969,10 +5969,17 @@ cp_parser_postfix_dot_deref_expression (cp_parser
{
if (name != error_mark_node && !BASELINK_P (name) && parser->scope)
{
- name = build_qualified_name (/*type=*/NULL_TREE,
- parser->scope,
- name,
- template_p);
+ if (TREE_CODE (parser->scope) == NAMESPACE_DECL)
+ {
+ error_at (token->location, "%<%D::%D%> is not a class member",
+ parser->scope, name);
+ postfix_expression = error_mark_node;
+ }
+ else
+ name = build_qualified_name (/*type=*/NULL_TREE,
+ parser->scope,
+ name,
+ template_p);
parser->scope = NULL_TREE;
parser->qualifying_scope = NULL_TREE;
parser->object_scope = NULL_TREE;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [C++ Patch] PR 50864 (parser bits)
2011-11-08 1:42 ` Paolo Carlini
@ 2011-11-08 5:05 ` Jason Merrill
0 siblings, 0 replies; 5+ messages in thread
From: Jason Merrill @ 2011-11-08 5:05 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
OK.
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-11-08 4:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-08 0:49 [C++ Patch] PR 50864 (parser bits) Paolo Carlini
2011-11-08 1:10 ` Jason Merrill
2011-11-08 1:22 ` Paolo Carlini
2011-11-08 1:42 ` Paolo Carlini
2011-11-08 5:05 ` 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).