diff options
Diffstat (limited to 'gcc/cp/typeck.c')
-rw-r--r-- | gcc/cp/typeck.c | 74 |
1 files changed, 28 insertions, 46 deletions
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index ad297106a6e..fcf52dc9db4 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -511,9 +511,10 @@ composite_pointer_type (tree t1, tree t2, tree arg1, tree arg2, tree attributes; tree result_type; - if (pedantic && TYPE_PTRFN_P (t2) && (complain & tf_error)) - pedwarn ("ISO C++ forbids %s between pointer of type %<void *%> " - "and pointer-to-function", location); + if (TYPE_PTRFN_P (t2) && (complain & tf_error)) + pedwarn (OPT_pedantic, "ISO C++ forbids %s " + "between pointer of type %<void *%> and pointer-to-function", + location); result_type = cp_build_qualified_type (void_type_node, (cp_type_quals (TREE_TYPE (t1)) @@ -1278,8 +1279,9 @@ cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain) type = non_reference (type); if (TREE_CODE (type) == METHOD_TYPE) { - if (complain && (pedantic || warn_pointer_arith)) - pedwarn ("invalid application of %qs to a member function", + if (complain) + pedwarn (pedantic ? OPT_pedantic : OPT_Wpointer_arith, + "invalid application of %qs to a member function", operator_name_info[(int) op].name); value = size_one_node; } @@ -1645,7 +1647,7 @@ decay_conversion (tree exp) return exp; } -/* Perform prepatory conversions, as part of the "usual arithmetic +/* Perform preparatory conversions, as part of the "usual arithmetic conversions". In particular, as per [expr]: Whenever an lvalue expression appears as an operand of an @@ -1696,18 +1698,6 @@ perform_integral_promotions (tree expr) return expr; } -/* Take the address of an inline function without setting TREE_ADDRESSABLE - or TREE_USED. */ - -tree -inline_conversion (tree exp) -{ - if (TREE_CODE (exp) == FUNCTION_DECL) - exp = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (exp)), exp); - - return exp; -} - /* Returns nonzero iff exp is a STRING_CST or the result of applying decay_conversion to one. */ @@ -2596,8 +2586,8 @@ build_array_ref (tree array, tree idx) return error_mark_node; } - if (pedantic && !lvalue_p (array)) - pedwarn ("ISO C++ forbids subscripting non-lvalue array"); + if (!lvalue_p (array)) + pedwarn (OPT_pedantic, "ISO C++ forbids subscripting non-lvalue array"); /* Note in C++ it is valid to subscript a `register' array, since it is valid to take the address of something with that @@ -2822,17 +2812,11 @@ cp_build_function_call (tree function, tree params, tsubst_flags_t complain) fndecl = function; /* Convert anything with function type to a pointer-to-function. */ - if (pedantic && DECL_MAIN_P (function) && (complain & tf_error)) - pedwarn ("ISO C++ forbids calling %<::main%> from within program"); - - /* Differs from default_conversion by not setting TREE_ADDRESSABLE - (because calling an inline function does not mean the function - needs to be separately compiled). */ + if (DECL_MAIN_P (function) && (complain & tf_error)) + pedwarn (OPT_pedantic, + "ISO C++ forbids calling %<::main%> from within program"); - if (DECL_INLINE (function)) - function = inline_conversion (function); - else - function = build_addr_func (function); + function = build_addr_func (function); } else { @@ -3299,7 +3283,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, TREE_TYPE (type1))) return pointer_diff (op0, op1, common_type (type0, type1)); /* In all other cases except pointer - int, the usual arithmetic - rules aply. */ + rules apply. */ else if (!(code0 == POINTER_TYPE && code1 == INTEGER_TYPE)) { common = 1; @@ -3821,7 +3805,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, For them, this optimization is safe only if both args are zero-extended or both are sign-extended. Otherwise, we might change the result. - Eg, (short)-1 | (unsigned short)-1 is (int)-1 + E.g., (short)-1 | (unsigned short)-1 is (int)-1 but calculated in (unsigned short) it would be (unsigned short)-1. */ if (shorten && none_complex) @@ -4101,15 +4085,12 @@ pointer_diff (tree op0, tree op1, tree ptrtype) if (!complete_type_or_else (target_type, NULL_TREE)) return error_mark_node; - if (pedantic || warn_pointer_arith) - { - if (TREE_CODE (target_type) == VOID_TYPE) - permerror ("ISO C++ forbids using pointer of type %<void *%> in subtraction"); - if (TREE_CODE (target_type) == FUNCTION_TYPE) - permerror ("ISO C++ forbids using pointer to a function in subtraction"); - if (TREE_CODE (target_type) == METHOD_TYPE) - permerror ("ISO C++ forbids using pointer to a method in subtraction"); - } + if (TREE_CODE (target_type) == VOID_TYPE) + permerror ("ISO C++ forbids using pointer of type %<void *%> in subtraction"); + if (TREE_CODE (target_type) == FUNCTION_TYPE) + permerror ("ISO C++ forbids using pointer to a function in subtraction"); + if (TREE_CODE (target_type) == METHOD_TYPE) + permerror ("ISO C++ forbids using pointer to a method in subtraction"); /* First do the subtraction as integers; then drop through to build the divide operator. */ @@ -4559,7 +4540,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert, arg = build1 (CONVERT_EXPR, type, arg); return arg; } - else if (pedantic && DECL_MAIN_P (arg)) + else if (DECL_MAIN_P (arg)) { /* ARM $3.4 */ if (complain & tf_error) @@ -4655,7 +4636,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert, /* Even if we're not being pedantic, we cannot allow this extension when we're instantiating in a SFINAE context. */ - if (! lvalue_p (arg) && (pedantic || complain == tf_none)) + if (! lvalue_p (arg) && complain == tf_none) { if (complain & tf_error) permerror ("ISO C++ forbids taking the address of a cast to a non-lvalue expression"); @@ -5443,7 +5424,8 @@ convert_member_func_to_ptr (tree type, tree expr) || TREE_CODE (intype) == METHOD_TYPE); if (pedantic || warn_pmf2ptr) - pedwarn ("converting from %qT to %qT", intype, type); + pedwarn (pedantic ? OPT_pedantic : OPT_Wpmf_conversions, + "converting from %qT to %qT", intype, type); if (TREE_CODE (intype) == METHOD_TYPE) expr = build_addr_func (expr); @@ -6980,7 +6962,6 @@ check_return_expr (tree retval, bool *no_warning) else permerror ("return-statement with a value, in function " "returning 'void'"); - current_function_returns_null = 1; /* There's really no value to return, after all. */ @@ -7347,7 +7328,8 @@ cp_apply_type_quals_to_decl (int type_quals, tree decl) if (pedantic) { tree bad_type = build_qualified_type (type, type_quals); - pedwarn ("ignoring %qV qualifiers added to function type %qT", + pedwarn (OPT_pedantic, + "ignoring %qV qualifiers added to function type %qT", bad_type, type); } |