* [C++ Patch] PR 26155 (improved patch)
@ 2012-06-01 12:16 Paolo Carlini
2012-06-01 15:10 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2012-06-01 12:16 UTC (permalink / raw)
To: gcc-patches, Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 427 bytes --]
Hi,
this is my last and best try ;) Seriously, compared to the last posted
version:
1- I added a rather large comment explaining what's going on wrt error
recovery.
2- Took the occasion to clean-up a bit the code about bool vs int for
flags (we had a mix).
3- Cleaned-up a bit the code itself (didn't notice that need_new is
initialized as true)
Tested x86_64-linux, as usual.
Thanks,
Paolo.
////////////////////////
[-- Attachment #2: CL_26155_5 --]
[-- Type: text/plain, Size: 302 bytes --]
/cp
2012-06-01 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/26155
* name-lookup.c (push_namespace): When error recovery is
impossible just error out in duplicate_decls.
/testsuite
2012-06-01 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/26155
* g++.dg/parse/namespace-alias-1.C: New.
[-- Attachment #3: patch_26155_5 --]
[-- Type: text/plain, Size: 2102 bytes --]
Index: testsuite/g++.dg/parse/namespace-alias-1.C
===================================================================
--- testsuite/g++.dg/parse/namespace-alias-1.C (revision 0)
+++ testsuite/g++.dg/parse/namespace-alias-1.C (revision 0)
@@ -0,0 +1,7 @@
+// PR c++/26155
+
+namespace N
+{
+ namespace M = N; // { dg-error "previous declaration" }
+ namespace M {} // { dg-error "declaration of namespace" }
+}
Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c (revision 188104)
+++ cp/name-lookup.c (working copy)
@@ -3518,8 +3518,8 @@ void
push_namespace (tree name)
{
tree d = NULL_TREE;
- int need_new = 1;
- int implicit_use = 0;
+ bool need_new = true;
+ bool implicit_use = false;
bool anon = !name;
bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
@@ -3535,8 +3535,8 @@ push_namespace (tree name)
d = IDENTIFIER_NAMESPACE_VALUE (name);
if (d)
/* Reopening anonymous namespace. */
- need_new = 0;
- implicit_use = 1;
+ need_new = false;
+ implicit_use = true;
}
else
{
@@ -3544,13 +3544,36 @@ push_namespace (tree name)
d = IDENTIFIER_NAMESPACE_VALUE (name);
if (d != NULL_TREE && TREE_CODE (d) == NAMESPACE_DECL)
{
- need_new = 0;
- if (DECL_NAMESPACE_ALIAS (d))
- {
- error ("namespace alias %qD not allowed here, assuming %qD",
- d, DECL_NAMESPACE_ALIAS (d));
- d = DECL_NAMESPACE_ALIAS (d);
+ tree dna = DECL_NAMESPACE_ALIAS (d);
+ if (dna)
+ {
+ /* We do some error recovery for, eg, the redeclaration
+ of M here:
+
+ namespace N {}
+ namespace M = N;
+ namespace M {}
+
+ However, in nasty cases like:
+
+ namespace N
+ {
+ namespace M = N;
+ namespace M {}
+ }
+
+ we just error out below, in duplicate_decls. */
+ if (NAMESPACE_LEVEL (dna)->level_chain
+ == current_binding_level)
+ {
+ error ("namespace alias %qD not allowed here, "
+ "assuming %qD", d, dna);
+ d = dna;
+ need_new = false;
+ }
}
+ else
+ need_new = false;
}
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ Patch] PR 26155 (improved patch)
2012-06-01 12:16 [C++ Patch] PR 26155 (improved patch) Paolo Carlini
@ 2012-06-01 15:10 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2012-06-01 15:10 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
OK.
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-06-01 15:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-01 12:16 [C++ Patch] PR 26155 (improved patch) Paolo Carlini
2012-06-01 15:10 ` 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).