[patch, 3.4] Backport of fix for PR c++/22464
Volker Reichelt
reichelt@igpm.rwth-aachen.de
Sat Dec 3 23:15:00 GMT 2005
The following patch is a backport of a mainline patch to fix
PR c++/22464 (ice-on-invalid-code) on the 3.4 branch.
Bootstrapped and regtested on i686-pc-linux-gnu.
Ok for the 3.4 branch?
Regards,
Volker
2005-12-03 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
Backport:
2005-10-13 Mark Mitchell <mark@codesourcery.com>
PR c++/22464
* semantics.c (finish_id_expression): Issue errors about uses of
local variables in containing functions even in templates.
===================================================================
--- gcc/gcc/cp/semantics.c 2005/10/05 12:17:13 1.491
+++ gcc/gcc/cp/semantics.c 2005/10/13 08:38:39 1.492
@@ -2398,6 +2398,21 @@
was entirely defined. */
if (!scope && decl != error_mark_node)
maybe_note_name_used_in_class (id_expression, decl);
+
+ /* Disallow uses of local variables from containing functions. */
+ if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
+ {
+ tree context = decl_function_context (decl);
+ if (context != NULL_TREE && context != current_function_decl
+ && ! TREE_STATIC (decl))
+ {
+ error (TREE_CODE (decl) == VAR_DECL
+ ? "use of `auto' variable from containing function"
+ : "use of parameter from containing function");
+ cp_error_at (" `%#D' declared here", decl);
+ return error_mark_node;
+ }
+ }
}
/* If we didn't find anything, or what we found was a type,
@@ -2664,23 +2679,6 @@
}
else
{
- if (TREE_CODE (decl) == VAR_DECL
- || TREE_CODE (decl) == PARM_DECL
- || TREE_CODE (decl) == RESULT_DECL)
- {
- tree context = decl_function_context (decl);
-
- if (context != NULL_TREE && context != current_function_decl
- && ! TREE_STATIC (decl))
- {
- error ("use of %s from containing function",
- (TREE_CODE (decl) == VAR_DECL
- ? "`auto' variable" : "parameter"));
- cp_error_at (" `%#D' declared here", decl);
- return error_mark_node;
- }
- }
-
if (DECL_P (decl) && DECL_NONLOCAL (decl)
&& DECL_CLASS_SCOPE_P (decl)
&& DECL_CONTEXT (decl) != current_class_type)
===================================================================
2005-12-03 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
Backport:
2005-10-13 Mark Mitchell <mark@codesourcery.com>
PR c++/22464
* g++.dg/template/crash41.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/crash41.C 2005/10/13 08:36:37 1.1
+++ gcc/gcc/testsuite/g++.dg/template/crash41.C 2005/10/13 08:38:39 1.2
@@ -0,0 +1,15 @@
+// PR c++/22464
+
+template<typename T>
+void do_something(const T* A) { // { dg-error "declared" }
+ struct helper_t {
+ helper_t() {
+ A[0]; // { dg-error "use" }
+ }
+ } helper;
+}
+
+void sub1() {
+ double A[7];
+ do_something (A);
+}
===================================================================
More information about the Gcc-patches
mailing list