From a753acd480b940e6abb7e531fe6270422a09fadf Mon Sep 17 00:00:00 2001 From: paolo Date: Sat, 16 Mar 2013 10:02:11 +0000 Subject: /cp 2013-03-16 Paolo Carlini PR c++/56582 * semantics.c (cxx_eval_array_reference): Check for negative index. /testsuite 2013-03-16 Paolo Carlini PR c++/56582 * g++.dg/cpp0x/constexpr-array5.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@196701 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/semantics.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gcc/cp/semantics.c') diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index e909b984681..3c76bad5a3d 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -7007,6 +7007,13 @@ cxx_eval_array_reference (const constexpr_call *call, tree t, *non_constant_p = true; return t; } + else if (tree_int_cst_lt (index, integer_zero_node)) + { + if (!allow_non_constant) + error ("negative array subscript"); + *non_constant_p = true; + return t; + } i = tree_low_cst (index, 0); if (TREE_CODE (ary) == CONSTRUCTOR) return (*CONSTRUCTOR_ELTS (ary))[i].value; -- cgit v1.2.1 From 7c99bd48472bfd42c38beaddb780c38f0e63e57f Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 17 Mar 2013 02:34:45 +0000 Subject: PR c++/55240 * parser.c (parsing_nsdmi): New. * semantics.c (outer_automatic_var_p): Check it. (finish_id_expression): Likewise. * cp-tree.h: Declare it. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@196727 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/semantics.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'gcc/cp/semantics.c') diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 3c76bad5a3d..efe09bb14b2 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2884,7 +2884,8 @@ outer_var_p (tree decl) { return ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) && DECL_FUNCTION_SCOPE_P (decl) - && DECL_CONTEXT (decl) != current_function_decl); + && (DECL_CONTEXT (decl) != current_function_decl + || parsing_nsdmi ())); } /* As above, but also checks that DECL is automatic. */ @@ -3041,12 +3042,14 @@ finish_id_expression (tree id_expression, return integral_constant_value (decl); } + if (parsing_nsdmi ()) + containing_function = NULL_TREE; /* If we are in a lambda function, we can move out until we hit 1. the context, 2. a non-lambda function, or 3. a non-default capturing lambda function. */ - while (context != containing_function - && LAMBDA_FUNCTION_P (containing_function)) + else while (context != containing_function + && LAMBDA_FUNCTION_P (containing_function)) { lambda_expr = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (containing_function)); -- cgit v1.2.1 From 69ed07ff6653de4fd0543fbd05493c65d11cdeed Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 17 Mar 2013 02:37:21 +0000 Subject: PR c++/56481 * semantics.c (potential_constant_expression_1): Use of 'this' in a non-constexpr function makes the expression not potentially constant. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@196737 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/semantics.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gcc/cp/semantics.c') diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index efe09bb14b2..20fe2433777 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -8497,6 +8497,13 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags) STRIP_NOPS (x); if (is_this_parameter (x)) { + if (DECL_CONTEXT (x) + && !DECL_DECLARED_CONSTEXPR_P (DECL_CONTEXT (x))) + { + if (flags & tf_error) + error ("use of % in a constant expression"); + return false; + } if (want_rval && DECL_CONTEXT (x) && DECL_CONSTRUCTOR_P (DECL_CONTEXT (x))) { -- cgit v1.2.1 From 7175d53da0f6f81d46e89cbb0cccbb20be488a80 Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 17 Mar 2013 02:38:01 +0000 Subject: PR c++/55357 * semantics.c (maybe_add_lambda_conv_op): Clear DECL_NAME of copied parms to avoid duplicate -Wshadow warnings. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@196739 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/semantics.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'gcc/cp/semantics.c') diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 20fe2433777..e46b4bfae9c 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9678,7 +9678,11 @@ maybe_add_lambda_conv_op (tree type) DECL_STATIC_FUNCTION_P (fn) = 1; DECL_ARGUMENTS (fn) = copy_list (DECL_CHAIN (DECL_ARGUMENTS (callop))); for (arg = DECL_ARGUMENTS (fn); arg; arg = DECL_CHAIN (arg)) - DECL_CONTEXT (arg) = fn; + { + /* Avoid duplicate -Wshadow warnings. */ + DECL_NAME (arg) = NULL_TREE; + DECL_CONTEXT (arg) = fn; + } if (nested) DECL_INTERFACE_KNOWN (fn) = 1; -- cgit v1.2.1 From 9dd19b79a49ba8b497c0e9f44bb178a8d5bc4807 Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 17 Mar 2013 02:38:50 +0000 Subject: PR c++/54764 PR c++/55972 * name-lookup.h (tag_scope): Add ts_lambda. * semantics.c (begin_lambda_type): Use it. * decl.c (xref_tag_1): Set CLASSTYPE_LAMBDA_EXPR. * pt.c (check_default_tmpl_args): Ignore lambdas. (push_template_decl_real): Handle lambdas. * tree.c (no_linkage_check): Adjust lambda check. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@196742 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/semantics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/cp/semantics.c') diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index e46b4bfae9c..9a2b7285dc9 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -8984,7 +8984,7 @@ begin_lambda_type (tree lambda) /* Create the new RECORD_TYPE for this lambda. */ type = xref_tag (/*tag_code=*/record_type, name, - /*scope=*/ts_within_enclosing_non_class, + /*scope=*/ts_lambda, /*template_header_p=*/false); } -- cgit v1.2.1 From f153f0531fbf0c8a5454ba6662b8819a6831bea6 Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 17 Mar 2013 02:41:22 +0000 Subject: PR c++/54277 * cp-tree.h (WILDCARD_TYPE_P): Split out from... (MAYBE_CLASS_TYPE_P): ...here. * semantics.c (lambda_capture_field_type): Only build a magic decltype for wildcard types. (lambda_proxy_type): Likewise. (finish_non_static_data_member): Get the quals from the object. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@196747 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/semantics.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'gcc/cp/semantics.c') diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 9a2b7285dc9..5143e4bd582 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1574,9 +1574,7 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) else { /* Set the cv qualifiers. */ - int quals = (current_class_ref - ? cp_type_quals (TREE_TYPE (current_class_ref)) - : TYPE_UNQUALIFIED); + int quals = cp_type_quals (TREE_TYPE (object)); if (DECL_MUTABLE_P (decl)) quals &= ~TYPE_QUAL_CONST; @@ -9056,7 +9054,7 @@ tree lambda_capture_field_type (tree expr) { tree type; - if (type_dependent_expression_p (expr)) + if (!TREE_TYPE (expr) || WILDCARD_TYPE_P (TREE_TYPE (expr))) { type = cxx_make_type (DECLTYPE_TYPE); DECLTYPE_TYPE_EXPR (type) = expr; @@ -9265,7 +9263,7 @@ lambda_proxy_type (tree ref) if (REFERENCE_REF_P (ref)) ref = TREE_OPERAND (ref, 0); type = TREE_TYPE (ref); - if (!dependent_type_p (type)) + if (type && !WILDCARD_TYPE_P (type)) return type; type = cxx_make_type (DECLTYPE_TYPE); DECLTYPE_TYPE_EXPR (type) = ref; -- cgit v1.2.1 From 88af6243ca81dc222d58bfce586dc1e13b65c7c4 Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 21 Mar 2013 03:25:35 +0000 Subject: PR c++/54532 * expr.c (cplus_expand_constant): Do nothing if the class is incomplete. * semantics.c (reduced_constant_expression_p): Allow PTRMEM_CST. * typeck2.c (store_init_value): Use reduced_constant_expression_p. * decl.c (maybe_register_incomplete_var): Handle PTRMEM_CST. (complete_vars): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@196852 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/semantics.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gcc/cp/semantics.c') diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 5143e4bd582..3691d862049 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6838,6 +6838,9 @@ cxx_eval_call_expression (const constexpr_call *old_call, tree t, bool reduced_constant_expression_p (tree t) { + if (TREE_CODE (t) == PTRMEM_CST) + /* Even if we can't lower this yet, it's constant. */ + return true; /* FIXME are we calling this too much? */ return initializer_constant_valid_p (t, TREE_TYPE (t)) != NULL_TREE; } -- cgit v1.2.1 From 694683bbcd14ccda5b40367fe2ad0f75d030db6e Mon Sep 17 00:00:00 2001 From: gdr Date: Fri, 22 Mar 2013 03:55:51 +0000 Subject: * cp-tree.h (identifier_p): New. * call.c: Throughout, call identifier_p insstead of direct comparaison of TREE_CODE against IDENTIFIER_NODE. * decl.c: Likewisse. * decl2.c: Likewise. * init.c: Likewise. * mangle.c: Likewise. * name-lookup.c: Likewise. * parser.c: Likewise. * pt.c: Likewise. * search.c: Likewise. * semantics.c: Likewise. * tree.c: Likewise. * typeck.c: Likewise. * typeck2.c: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@196897 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/semantics.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'gcc/cp/semantics.c') diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 3691d862049..e3aeb817a52 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -536,7 +536,7 @@ simplify_loop_decl_cond (tree *cond_p, tree body) tree finish_goto_stmt (tree destination) { - if (TREE_CODE (destination) == IDENTIFIER_NODE) + if (identifier_p (destination)) destination = lookup_label (destination); /* We warn about unused labels with -Wunused. That means we have to @@ -1999,7 +1999,7 @@ perform_koenig_lookup (tree fn, vec *args, bool include_std, } /* Find the name of the overloaded function. */ - if (TREE_CODE (fn) == IDENTIFIER_NODE) + if (identifier_p (fn)) identifier = fn; else if (is_overloaded_fn (fn)) { @@ -2966,7 +2966,7 @@ finish_id_expression (tree id_expression, if (scope && (!TYPE_P (scope) || (!dependent_type_p (scope) - && !(TREE_CODE (id_expression) == IDENTIFIER_NODE + && !(identifier_p (id_expression) && IDENTIFIER_TYPENAME_P (id_expression) && dependent_type_p (TREE_TYPE (id_expression)))))) { @@ -2995,8 +2995,7 @@ finish_id_expression (tree id_expression, the current class so that we can check later to see if the meaning would have been different after the class was entirely defined. */ - if (!scope && decl != error_mark_node - && TREE_CODE (id_expression) == IDENTIFIER_NODE) + if (!scope && decl != error_mark_node && identifier_p (id_expression)) maybe_note_name_used_in_class (id_expression, decl); /* Disallow uses of local variables from containing functions, except @@ -3169,8 +3168,7 @@ finish_id_expression (tree id_expression, /* A template-id where the name of the template was not resolved is definitely dependent. */ else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR - && (TREE_CODE (TREE_OPERAND (decl, 0)) - == IDENTIFIER_NODE)) + && (identifier_p (TREE_OPERAND (decl, 0)))) dependent_p = true; /* For anything except an overloaded function, just check its type. */ @@ -5301,7 +5299,7 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, [expr.ref]), decltype(e) is defined as the type of the entity named by e. If there is no such entity, or e names a set of overloaded functions, the program is ill-formed. */ - if (TREE_CODE (expr) == IDENTIFIER_NODE) + if (identifier_p (expr)) expr = lookup_name (expr); if (TREE_CODE (expr) == INDIRECT_REF) -- cgit v1.2.1